User Drawn Mouse?
Hi, Trying to draw my own mouse on a window.
I have hidden the system mouse ( with ShowCursor(false) ), and I’m using a GL_LINE_STRIP to draw my own mouse this is all fine
But I’m not sure how to reactivate the mouse when its on the boarder, or title bar. I’m getting window messages for the drawing area only. In other words I know when the mouse is in the drawing area, but when I move over the windows title bar of course I have no mouse, and no way of knowing when to show the mouse again?
Any ideas please.
Well there is a windows function called ScreenToClient, which when passed the desktop mouse coordinates converts them to the local window coordinates if it lies inside. Now im not sure whether the client coords cover the entire window, but it might be worth a look.
ace
ace
If the mouse has moved, check if it's in the client rectangle and reactivate it if it isn't. There is a function called GetClientRect or somethign similar that will put the client window coords into a RECT struct, then you just test the cursor against those.
You only have to refresh the RECT if the window itself actually moves.
[Edited by - Vampyre_Dark on September 12, 2005 9:53:39 AM]
You only have to refresh the RECT if the window itself actually moves.
[Edited by - Vampyre_Dark on September 12, 2005 9:53:39 AM]
You could also use GetSystemMetrics to detect if the cursor is actually on the title/menu bar.
that is
from GetSystemMetrics you get the menu height, then test if the cursor lies in the menu.
that is
from GetSystemMetrics you get the menu height, then test if the cursor lies in the menu.
Thanks for all your comments, I have a method working now so I thought I would post details of it here for the benefit of others. And in the hope some one can spot errors for me.
The WM_MOUSEMOVE message is only sent in the context of the current client window area, for the non-client area the WM_NCMOUSEMOVE message is sent.
Then I used ShowCursor(true) to turn it on when I received a WM_NCMOUSEMOVE and off again for normal mouse move messages.
It seems (or else I just don’t understand) that windows is very picky about how many times ShowCursor() is called. So I've included a check to ensure it only ever gets called once to turn it on and once to turn it off. By picky I mean, it may turn off and stay off or on.
I've included this snippet of code below. Note that SYS_Mouse is my custom cursor struct, and tracks if the mouse was LastMovedInClient window, and a visibility setting, the custom mouse gets rendered with each frame in my game loop.
The WM_MOUSEMOVE message is only sent in the context of the current client window area, for the non-client area the WM_NCMOUSEMOVE message is sent.
Then I used ShowCursor(true) to turn it on when I received a WM_NCMOUSEMOVE and off again for normal mouse move messages.
It seems (or else I just don’t understand) that windows is very picky about how many times ShowCursor() is called. So I've included a check to ensure it only ever gets called once to turn it on and once to turn it off. By picky I mean, it may turn off and stay off or on.
I've included this snippet of code below. Note that SYS_Mouse is my custom cursor struct, and tracks if the mouse was LastMovedInClient window, and a visibility setting, the custom mouse gets rendered with each frame in my game loop.
case WM_NCMOUSEMOVE: if(SYS_Mouse.LastMovedInClient==true) { ShowCursor(true); SYS_Mouse.Visible = false; } SYS_Mouse.LastMovedInClient = false; break;case WM_MOUSEMOVE: if(SYS_Mouse.LastMovedInClient==false) { ShowCursor(false); SYS_Mouse.Visible = true; } SYS_Mouse.LastMovedInClient = true; // other mouse stuff. break;
why draw your own pointer? why not just specify a dib for the pointer in a resource file and let windows do it for you? you can load up your own cursor form a dib(bmp like) file and save yourself the trouple of drawing it. can't remember how exactly but I know it's extremly simple like one or two function call. every component of your window will get a message when the mouse is in focus, this is how the "double arrow cursor" is applied when you mouse over a border, upon mouse aquisiton this window(the border) sets the cursor to the double arrow and when it looses focus it sets it back, this is how all components do it. I cant remember specifics tho, but it's extremely simple, if your handling drawing functions or something, then you're going more into it then you need to.
Tim
Tim
Thanks timw, my rational for drawing the mouse my self was this.
-In order to promote cross platform compatibility I wanted to avoid using as many windows specific resource shortcuts as possible.
-I can create 3D cursors, and have at my disposal all the effects / features of the render pipe line I’m wanting to build into my engine.
-A mouse cursor as an engine object generally fits better into my object model then adding another unrelated Interface_Windows_Dib_Cursor class.
As it is I only have two platform specific classes, the windows creation and messaging class and resource interface class (files / winsock / ect). I’d like to keep it that way.
-In order to promote cross platform compatibility I wanted to avoid using as many windows specific resource shortcuts as possible.
-I can create 3D cursors, and have at my disposal all the effects / features of the render pipe line I’m wanting to build into my engine.
-A mouse cursor as an engine object generally fits better into my object model then adding another unrelated Interface_Windows_Dib_Cursor class.
As it is I only have two platform specific classes, the windows creation and messaging class and resource interface class (files / winsock / ect). I’d like to keep it that way.
Quote:Original post by bobason456
It seems (or else I just don’t understand) that windows is very picky about how many times ShowCursor() is called. So I've included a check to ensure it only ever gets called once to turn it on and once to turn it off. By picky I mean, it may turn off and stay off or on.
That's because ShowCursor increments/decrements a counter. If you call ShowCursor(false) twice, you must call ShowCursor(true) twice also.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement