I have done a couple of different ways to get the position of the mouse above the form to know when its hovering something.
when i create a project i usually like to skip the need of a commandbutton or textbox or whatever, i usually use GDI to create everything. that means i need to know everything, where the mouse is, if the mousebutton is pressed, released, if outside the form or inside a picturebox/frame/component.
the latest code im using to do that is with hooking, CallWindowProc, some code:
Code:
Public Function WindowProcForm(ByVal lWnd As Long, ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
HookMsg lMsg, Val(lParam And 65535), Val(lParam / 65536), 1, wParam
WindowProcForm = CallWindowProc(ProcForm, lWnd, lMsg, wParam, lParam)
End Function
im calling another function/sub because there could be multiple hooking.
all the hooks calls the same function/sub, here how it looks:
Code:
Sub HookMsg(ByVal Msg As Long, ByVal x As Long, ByVal y As Long, ByVal dc As Long, Optional w As Long)
that will give me the Msg, x & y coordination, dc is used if multiple hooking and w if theres a need of the wParam.
everything works great. but theres one thing that i can't get using hooking so im forced to use a timer. i don't like that.
here code of the timer:
Code:
Call GetCursorPos(MousePoint)
ObjHwnd = WindowFromPoint(MousePoint.x, MousePoint.y)
If ObjHwnd <> FieldHwnd Then HookMsg 133, MousePoint.x, MousePoint.y, 1 + FormNumber
that will trigger when the mouse goes outside the hooked area.
im calling the same HookMsg here with the "Msg=133", the 1 + FormNumber is because im using 2 forms with different hwnd.
so my question is, do you know a way to do this without using a timer?
my other "ways" are using a timer, so i know how to do that but i like the idea of a hook method.