Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wait for Mouse Click on External App?

Status
Not open for further replies.

Rock6431

Programmer
Mar 23, 2002
56
US
Need info on how to make my app wait for external click on an external application's caption bar...

TIA
Mike
 
you can use FindWindow to get the external window's handle, then WindowFromPt to know when the user is hovering over this window, and GetAsyncKeyState to know when the mouse has been clicked. but since you only want to trigger this event when they have clicked on the caption bar you would need to use GetWindowPlacement and subtract the Top Left coordinate of the window from the Y coordinate of the mouse to tell if the mouse was in the caption bar region. I think there may be an easier way but researching it may take more time than just doing this, which really is not much work at all if you know the APIs, if you need a reference...
 
Hardkor,

Thanks. I found what I was looking for after reading your reply and it lead me to the proper process. I thought that I'd share the result. I simply waited for the next mouseclick and then pulled the windows coordinates at that point. Checked the class and caption to confirm that it was the application that I wanted the user to identify. Then I continued on from there...

Thanks Again...

Mike


For anyone else that needed to know how to wait I've left the following code here for your help. I did not include all the necessary API declarations. Only the one for determining the Mouse Click while waiting.

----------------------

Declare Function GetAsyncKeyState Lib "User32" (ByVal Key As Integer) As Integer


Function Button_Click
' Call GetAsyncKeyState in the Debug line below to clear the KeyState of the mouse click for this Function
' Check for both mouse events in case Left Handed User.

Debug.Print "LastKey= " & GetAsyncKeyState(1)
Do
DoEvents
If GetAsyncKeyState(1) <> 0 Then '(1) = Left Mouse Click
Debug.Print &quot;Mouse Left Clicked&quot;
Exit Do
End If
If GetAsyncKeyState(2) <> 0 Then '(2) = Right Mouse Click
Debug.Print &quot;Mouse Right Clicked&quot;
Exit Do
End If
Loop

mfx = MouseX()
mfy = MouseY()
' Get Window Handle
frwnd = WindowFromPoint(mfx, mfy)
' Now bring that Window to TOP...

ttr = IsWindowVisible(frwnd) ' 1=true

If ttr = 1 Then
ttr = IsIconic(frwnd)
Else
Debug.Print (&quot;Invalid Window&quot;)
Exit Function
End If


If ttr = 0 Then ' Not an Icon
ttr = BringWindowToTop(frwnd) '0 = False 1=True
Else
Debug.Print(&quot;Icon&quot;)
ShowWindow frwnd, SW_RESTORE
ttr = BringWindowToTop(frwnd) '0 = False 1=True
End If

' Check to make sure window is a CORRECT Window
Call CheckClass(frwnd)
If mc.checkclass = False then exit function
Dim WinTitleBuf1 As String * 255
Dim WinTitle1 As String

ttr = GetWindowText(frwnd, WinTitleBuf1, 255)
WinTitle1 = StripNulls(WinTitleBuf1)
Debug.Print Mid(WinTitle1, 3, 6)

If Mid(WinTitle1, 3, 6) = &quot;CAPTION&quot; Or Mid(WinTitle1, 3, 6) = &quot;CAPTION&quot; Then
RHWND = frwnd
Debug.Print (&quot;Found Correct Window: &quot; & frwnd)
Exit Function
Else
'Debug.Print &quot;No&quot; ' NO this is not the proper window
MsgBox (&quot;Please Select the Proper Window&quot;)
RHWND = 0
Exit Function
End If

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top