Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Detecting mouse movement outside the active winodw

This topic is 5281 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible for a window to recive mouse move messages when the mouse pointer is outside the client area? I know about WM_NCMOUSEMOVE, but that doesnt solve the problem of detecting movement when the cursor is totally out of the area of the window. SetCapture only seems to work if the left mouse button is down, but this isnt good enough for what I''m after. It needs to detect it regardless of the mouse state Thanks Spree

Share this post

Link to post
Share on other sites
Hmm, I know that setting a win32 hook would allow you to receive system wide messages, and I''m inclined to believe this might be the only viable way to get this info. Perhaps someone else has another idea that might be quicker/easier.

look here about hooks: clicker

Share this post

Link to post
Share on other sites
I know this can be done with a windows hook. The hook has to be placed in a separate DLL when dealing with messages out of the client window, but here is how it works.

You set up a Mouse hook procedure (sort of like a windows procedure, but for mouse hookes instead), inside of a dll module, and export it from the dll.

The prototype for the mouse hook procedure is as follows:

LRESULT CALLBACK MouseHookProc(int Code, WPARAM wParam, LPARAM lParam);

Code is the kind of message sent.
wParam is the mouse identifier message, (mouse window message) eg WM_LBUTTONDOWN, etc.
and lParam is the memory address to a MOUSEHOOKSTRUCT structure.
The MOUSEHOOKSTRUCTURE contains information about the window that received the message, the coordinates, etc.

After you have set up the DLL module, you need to set up a windows hook, and hook it to the system, to receive the mouse messages. This is done in your app, as follows:


HookDll = LoadLibrary("HookDll.dll");
HookProc = (HOOKPROC)GetProcAddress(HookDll, "MouseHookProc");
Hook = SetWindowsHookEx(WH_MOUSE, HookProc, HookDll, NULL);

NOTE: Make sure you make a .def (definitions) file for you dll module and export the mouse hook procedure.

and also, youll want to do some error checking.

Hope this helped, if you want any more information, or need more help, reply here, or email me at chatterbox@xtra.co.nz.

Share this post

Link to post
Share on other sites
Thanks for that, i''ll look into it tonight. Hopefully should be able to get it working soon.

Thanks for your advice

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!