??Windows编程中怎样把鼠标隐藏在窗口内部区域??
我知道 ShowCursor 是隐藏鼠标的函数,但我用了之后,鼠标在窗口中全部隐藏了,窗口的外部区域也是。
我在之前还加了GetClientRect 取得窗口内部矩形。。也不行。
我只是想把鼠标仅仅 在窗口内部处于隐藏状态。。
怎么做啊,请指教啊、、!
下面是短小的源码:
#include <windows.h>//函数声明BOOL InitWindow( HINSTANCE hInstance, int nCmdShow );LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );//变量说明HWND hWnd; //窗口句柄//************************************************************//函数:WinMain( )//功能:Windows程序入口函数。创建主窗口,处理消息循环//************************************************************int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ if ( !InitWindow( hInstance, nCmdShow ) ) return FALSE; //创建主窗口 //如果创建不成功则返回FALSE并同时退出程序 MSG msg; //进入消息循环: for(;;) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if ( msg.message==WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam;}//************************************************************//函数:InitWindow( )//功能:创建窗口//************************************************************static BOOL InitWindow( HINSTANCE hInstance, int nCmdShow ){ //定义窗口风格: WNDCLASS wc; wc.style = NULL; wc.lpfnWndProc = (WNDPROC)WinProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = NULL; wc.hbrBackground = CreateSolidBrush(0x0); //暗红色的背景 wc.lpszMenuName = NULL; wc.lpszClassName = "My_Test"; RegisterClass(&wc);//注册窗口 //按所给参数创造窗口 hWnd = CreateWindow("My_Test", "I'll be the one!", WS_OVERLAPPEDWINDOW,//WS_POPUP|WS_MAXIMIZE, CW_USEDEFAULT,//0, CW_USEDEFAULT,//0, CW_USEDEFAULT,//GetSystemMetrics( SM_CXSCREEN ), //此函数返回屏幕宽度 CW_USEDEFAULT,//GetSystemMetrics( SM_CYSCREEN ), //此函数返回屏幕高度 NULL,NULL,hInstance,NULL); if( !hWnd ) return FALSE; ShowWindow(hWnd,nCmdShow);//显示窗口 UpdateWindow(hWnd);//刷新窗口 MoveWindow(hWnd,150,100,400,500,true); RECT rect; GetClientRect(hWnd,&rect); //.................... //GetWindowRect(hWnd,&rect); ShowCursor(FALSE); //.................... return TRUE;}//************************************************************//函数:WinProc( )//功能:处理窗口消息//************************************************************LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ){ switch( message ) { //调用缺省消息处理过程 return DefWindowProc(hWnd, message, wParam, lParam); }LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ){ int xPos; int yPos; switch( message ) { case WM_QUIT: ExitProcess(0); break; case WM_CLOSE: SendMessage(hWnd, WM_QUIT, NULL, NULL); break; case WM_MOUSEMOVE: xPos = LOWORD(lParam); // horizontal position of cursor yPos = HIWORD(lParam); // vertical position of cursor if(yPos >= (rect.top) && yPos <= rect.bottom) ShowCursor(FALSE); break; default: break; } //调用缺省消息处理过程 return DefWindowProc(hWnd, message, wParam, lParam); }