Click to See Complete Forum and Search --> : some questions
Paca
Mar 5th, 2001, 06:44 AM
Ok, I made and now have an API spy so I can get all the info I need for calling up windows, giving commands, etc., but I need to know some things, I'll put my questions in order so they are easier to answer.
1. How can I have my program watch for a window in another program pop up?
2. How can I tell my program to click a button on the other program once the window has popped up?
3. How can I make my program watch for specific browser (E.I., Netscape, whatever) popups, then close them once they pop up?
4. How can I make my program minimize into the systems tray and not into the taskbar?
2)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const BM_CLICK = &HF5
Private Sub Command1_Click()
Dim hWnd_Btn As Long
hWnd_Btn = FindWindowEx(FindWindowEx(0, 0, "ParentWindowClass", "ParentWindowName" _
), 0, "Button", "ButtonCaption")
SendMessage hWnd_Btn, BM_CLICK, 0, 0
End Sub
This will check for IE. Add to a Form with a Timer.
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Const WM_CLOSE = &H10
Private Sub Form_Load()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim hApp As Long
hApp = FindWindowEx(0, 0, "IEFrame", vbNullString)
If hApp <> 0 Then
SendMessage hApp, WM_CLOSE, 0, 0
DestroyWindow hApp
End If
End Sub
Paca
Mar 6th, 2001, 03:14 AM
Your answer to question 3 didn't work, I tried it the way you showed the code here, creating a form and timer to specifications, but it still wouldn't work. I couldn't use the answer to question 2 because the button I want to push doesn't show a Parent Window Name or a Button Caption (its a picture instead of a caption), is there any other way I can do this?
Now the complication sets in, I really want to learn how to preform these though so I can make a handy add on tool for a program I use.
Thanks for all and any help.
Sorry about that. For closing IE, change this line: Timer1.Enabled = True to this line: Timer1.Interval = 10.
For #2) how many other buttons are on the Window. If so, do they use Pictutes too? Or do they use a caption property.
Paca
Mar 6th, 2001, 04:35 PM
Originally posted by Megatron
For #2) how many other buttons are on the Window. If so, do they use Pictutes too? Or do they use a caption property.
They all have pictures and no captions, but, they have ToolTipText that describes the button if that helps.
Paca
Mar 6th, 2001, 04:41 PM
Originally posted by Megatron
Sorry about that. For closing IE, change this line: Timer1.Enabled = True to this line: Timer1.Interval = 10.
It still doesn't work for me.
For IE Windows, try this:
Private Declare Function FindWindowEx _
Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As _
Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal _
lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength _
Lib "user32" Alias "GetWindowTextLengthA" (ByVal _
hwnd As Long) As Long
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle _
As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetWindowThreadProcessId _
Lib "user32" (ByVal hwnd As Long, lpdwProcessId As _
Long) As Long
Private Declare Function GetExitCodeProcess _
Lib "kernel32" (ByVal hProcess As Long, lpExitCode As _
Long) As Long
Private Declare Function TerminateProcess _
Lib "kernel32" (ByVal hProcess As Long, ByVal _
uExitCode As Long) As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Sub Timer1_Timer()
Dim lngIE As Long
Dim strBuffer As String
Dim lngLength As Long
Dim intCount As Integer
Dim lHwnd As Long
Dim lProcess As Long
Dim lExitCode As Long
Dim p As Integer
Do
lngIE = FindWindowEx(0, lngIE, "IEFrame", vbNullString)
lngLength = GetWindowTextLength(lngIE)
strBuffer = Space(lngLength)
Call GetWindowText(lngIE, strBuffer, Len(strBuffer))
If Len(Trim(strBuffer)) > 0 Then
intCount = intCount + 1
End If
Loop Until lngIE = 0
If intCount > 1 Then
For p = 1 To (intCount - 1)
'Get the Window Handle
lHwnd = FindWindow("IEFrame", vbNullString)
'Get the ProcessID
Call GetWindowThreadProcessId(lHwnd, lProcess)
'Get the Process Handle
lProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, lProcess)
'Get the Exitcode
Call GetExitCodeProcess(lProcess, lExitCode)
'Terminate the Process
Call TerminateProcess(lProcess, lExitCode)
Next p
End If
End Sub
Paca
Mar 7th, 2001, 01:52 PM
Thanks Matthew Gates, that worked. Thats one down, now, how about my other questions? ;]
This method is much shorter. It's the same as my other code, except I used PostMessage.
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CLOSE = &H10
Private Sub Form_Load()
Timer1.Interval = 1
End Sub
Private Sub Timer1_Timer()
Dim hApp As Long
hApp = FindWindowEx(0, 0, "IEFrame", vbNullString)
If hApp <> 0 Then
PostMessage hApp, WM_CLOSE, 0, 0
DestroyWindow hApp
End If
End Sub
Q4:
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_LBUTTONUP = &H202
Private Const WM_RBUTTONUP = &H205
Private Const WM_MOUSEMOVE = &H200
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uId As Long
uFlags As Long
ucallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Private VBGTray As NOTIFYICONDATA
Private Sub GoSystemTray()
VBGTray.cbSize = Len(VBGTray)
VBGTray.hwnd = Me.hwnd
VBGTray.uId = vbNull
VBGTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
VBGTray.ucallbackMessage = WM_MOUSEMOVE
VBGTray.hIcon = Me.Icon
'tool tip text
VBGTray.szTip = Me.Caption & vbNullChar
Call Shell_NotifyIcon(NIM_ADD, VBGTray)
App.TaskVisible = False 'remove application from taskbar
Me.Hide
End Sub
Private Sub Form_MouseMove(button As Integer, Shift As Integer, X As Single, Y As Single)
Static lngMsg As Long
Static blnFlag As Boolean
Dim result As Long
lngMsg = X / Screen.TwipsPerPixelX
If blnFlag = False Then
blnFlag = True
Select Case lngMsg
'right-click
Case WM_RBUTTONUP
result = SetForegroundWindow(Me.hwnd)
PopupMenu MyPopUpMenu
Case WM_LBUTTONUP
result = SetForegroundWindow(Me.hwnd)
PopupMenu MyPopUpMenu
End Select
blnFlag = False
End If
End Sub
Private Sub Form_Resize()
If Me.WindowState = 1 Then
Call GoSystemTray
ElseIf Me.WindowState = 0 Then
VBGTray.cbSize = Len(VBGTray)
VBGTray.hwnd = Me.hwnd
VBGTray.uId = vbNull
Call Shell_NotifyIcon(NIM_DELETE, VBGTray)
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
VBGTray.cbSize = Len(VBGTray)
VBGTray.hwnd = Me.hwnd
VBGTray.uId = vbNull
Call Shell_NotifyIcon(NIM_DELETE, VBGTray)
Unload Me
Set Form1 = Nothing
End
End Sub
Paca
Mar 7th, 2001, 04:40 PM
Now I can't maximize the form though, it just stays in the system tray minimized, even if I add a mazimize command.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.