Sign in to follow this  
DrunkenBrit

ShowCursor() - Windows

Recommended Posts

Yo, Does anyone know how to hide the mouse cursor when it is in the client window but reveal it again when it is over the title bar etc, google hasn't been much help other than find ShowCursor() which is what I already know... Cheers.

Share this post


Link to post
Share on other sites
First I would try setting the cursor of the window itself, which I believe is only applied when the cursor is in the client area. I am pretty sure you can do this with other cursors, I am just not sure if you can hide it completely using this method. Look at the creation of the window for the place to insert your cursor.

If that doesn't work, you will probably have to look into hit testing, and manually hide the cursor when in you client area, and showing the cursor when in your title area. Hit testing is a Window message, and one of the parameter is an identifier telling you where on the window the cursor is located, for example the lower resize area, the title bar, the caption buttons, the client area, etc. Take a look at WM_HITTEST and NCHITTEST for more information.

Share this post


Link to post
Share on other sites
Thanks for your replies guys, Evil Steve, I've tried your method, it works but when the cursor goes out of the window it appears, which is what I wanted, but then I need a way to hide it when it goes into the client area again...

Mike.Popoloski i'm looking into your solution now.

Share this post


Link to post
Share on other sites
Quote:
Original post by DrunkenBrit
Thanks for your replies guys, Evil Steve, I've tried your method, it works but when the cursor goes out of the window it appears, which is what I wanted, but then I need a way to hide it when it goes into the client area again...
I was talking gibberish when I posted [smile]
Set your cursor handle to NULL in the window class, and call SetCursor(NULL); when you get a WM_SETCURSOR message.

You shouldn't need to worry about showing the cursor when it's over the window frame, Windows does that itself I think...

Share this post


Link to post
Share on other sites
Haha thanks guys :) Steve, I tried you method but no luck, the cursor doesn't reappear when it's over the title bar etc

Here's my code just incase i'm doing a school boy error or something :) -



// Create the window

HWND CreateMyWindow(LPSTR strWindowName, int width, int height, DWORD dwstyle, bool bFullScreen, HINSTANCE hInstance)
{
HWND hWnd;
WNDCLASS wndclass;

memset(&wndclass, 0, sizeof(WNDCLASS));
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WinProc;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wndclass.hCursor = NULL; //LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wndclass.lpszClassName = "Asteroids 2.5D";

SetCursor(NULL);

RegisterClass(&wndclass);

if(bFullScreen && !dwstyle)
{
dwstyle = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
ChangeToFullScreen();
ShowCursor(FALSE);
}
else if(!dwstyle)
dwstyle = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;

g_hInstance = hInstance;

RECT rWindow;
rWindow.left = 0;
rWindow.right = width;
rWindow.top = 0;
rWindow.bottom = height;

AdjustWindowRect( &rWindow, dwstyle, false);

hWnd = CreateWindow("Asteroids 2.5D", strWindowName, dwstyle, 0, 0,
rWindow.right - rWindow.left, rWindow.bottom - rWindow.top,
NULL, NULL, hInstance, NULL);

if(!hWnd) return NULL;

ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);

SetFocus(hWnd);

return hWnd;
}

// Call back

LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LONG lRet = 0;
PAINTSTRUCT ps;

switch (uMsg)
{

case WM_SETCURSOR:
SetCursor(NULL);
break;

case WM_MOUSEMOVE:
break;

case WM_SIZE:
if(!g_bFullScreen)
{
GetClientRect(hWnd, &g_rRect);
SizeOpenGLScreen( g_rRect.right, g_rRect.bottom, 45.0, 1.0, 150.0 );
}
break;

case WM_PAINT:
BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;

case WM_KEYDOWN:
if(wParam == VK_ESCAPE) DeInit();

if(wParam == VK_SPACE)
{

}
break;

case WM_DESTROY:
DeInit();
break;

default:
lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
break;
}

return lRet;
}



Cheers!

P.S. I tried to use code tags but didn't work :S

Share this post


Link to post
Share on other sites
You can use use [ source ] [ /source ] tags for pasting blocks of code.

Ah, I thought Windows would always show the cursor when it's over your window frame, apparently not - sorry.

You can get around that by doing it yourself though:

case WM_SETCURSOR:
{
// Get client coordinates of cursor
POINT pt;
GetCursorPos(&pt);
ScreenToClient(hWnd, &pt);

// Get client rect
RECT rc;
GetClientRect(hWnd, &rc);
rc.right -= rc.left;
rc.bottom -= rc.top;

// See if cursor is in client area
if(pt.x < 0 || pt.x > rc.right || pt.y < 0 || pt.y > rc.bottom)
SetCursor(LoadCursor(NULL, IDC_ARROW));
else
SetCursor(NULL);

// Docs say to return true if msg is handled
lRet = TRUE;
}
break;



That's untested though, appologies in advance if it doesn't work again [smile]

Share this post


Link to post
Share on other sites
Och aye mate! :) lol Nah doesn't work, I havn't messed around with it properly, just copied and pasted but should be able to get it working :) Think im going to try and get my object to face where the mouse cursor is now so this all might become obsolete! :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this