Public Function MouseInWindow(ByVal p_Hwnd As Long) As Boolean Dim lt_Pt As POINTAPI Dim l_MouseWindow As Long GetCursorPos lt_Pt l_MouseWindow = WindowFromPoint(lt_Pt.x, lt_Pt.y) Do While (l_MouseWindow <> p_Hwnd) And (l_MouseWindow <> 0) ' Run up the chain of parent windows looking for a match l_MouseWindow = GetAncestor(l_MouseWindow, GA_PARENT) Loop MouseInWindow = (l_MouseWindow = p_Hwnd) End Function
This function checks if the mouse is anywhere in the form (p_Hwnd is the form's handle) except for the control which has been clicked. Clicking again on the same control from which the event has been at first fired makes l_MouseWindow = p_Hwnd, which does not meet the "l_MouseWindow <> p_Hwnd" condition, and the loop is not entered. How to correct this?
E.g. Click on a control, say, a combo box. The list is dropped down. Click anywhere on the form except on that same control. The loop is entered and MouseInWindow eventually becomes True, and, according to the caller, the combo box is retracted and made not visible. Now, drop down the combo and click again on the drop down arrow in an attempt to retract the list; it does not work because "l_MouseWindow = p_Hwnd", which causes the function not to go to l_MouseWindow = GetAncestor(l_MouseWindow, GA_PARENT) and eventually makes MouseInWindow False.
This post has been edited by AN1554: 22 December 2011 - 02:49 PM

New Topic/Question
Reply



MultiQuote



|