#include <windows.h>
#include <stdlib.h>
#include <string.h>
BOOL Init WindowsClass(HINSTANCE hInstance);
BOOL Init Windows(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG Message;
if(!InitWindowsClass(hInstnce ,nCmdShow))
return FALSE;
if(! InieWindows(hInstance,nCmdShow))
return FALSE;
while(GetMessage(&Message,0,0,0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UNIT iMessage,UNIT wParam,LONG lParam)
{
WORD x,y;
HCURSOR hCursor;
switch(iMessage)
{
case WM_MOUSEMOVE:
x=LOWORD(lParam);
y=HIWORD(iParam);
if(x>=50&&x<=400&&y>=50&&y<=300)
{
if(x>=50&&x<=100&&y>=50&&y<=100)
{
hCursor=LoadCursor(NULL,IDC_CROSS);
SetCursor(hCursor);
}
if(x>=100&&x<=150&&y>=50&&y<=100)
{
hCursor=LoadCursor(NULL,IDC_SIZEALL);
SetCursor(hCursor);
}
if(x>=150&&x<=200&&y>=50&&y<=100)
{
hCursor=LoadCursor(NULL,IDC_HELP);
SetCursor(hCursor);
}
if(x>=50&&x<=100&&y>=100&&y<=150)
{
hCursor=LoadCursor(NULL,IDC_SIZENESW);
SetCursor(hCursor);
}
if(x>=100&&x<=250&&y>=100&&y<=150)
{
hCursor=LoadCursor(NULL,IDC_SIZENS);
SetCursor(hCursor);
}
if(x>=250&&x<=400&&y>=100&&y<=150)
{
hCursor=LoadCursor(NULL,IDC_SIZENWSE);
SetCursor(hCursor);
}
if(x>=50&&x<=100&&y>=150&&y<=300)
{
hCursor=LoadCursor(NULL,IDC_SIZEWE);
SetCursor(hCursor);
}
if(x>=100&&x<=250&&y>=100&&y<=300)
{
hCursor=LoadCursor(NULL,IDC_UPARROW);
SetCursor(hCursor);
}
if(x>=250&&x<=400&&y>=150&&y<=300)
{
hCursor=LoadCursor(NULL,IDC_WAIT);
SetCursor(hCursor);
}
}
else
{
hCursor=LoadCursor(NULL,IDC_ARROW);
SetCursor(hCursor);
}
return 0;
case WM_DESTROY:
PoseQuitMessage(0);
return 0;
default:
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
}
BOOL InitWindowsClass(HINSTANCE hInstance)
{
WNDCLASS Wndclass;
WndClass.cbClsExtra=0;
WndClass.hbrBackground=(HBRUSH)(GetStockObject(WHILE_BRUSH));
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=loadCursor(NULL,"END");
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName="WinMouse";
Wndclass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAM|CS_VREDRAW;
return RegisterClass(&WndClass);
}
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
hWnd=CreateWindow("WinMouse",
"鼠标及光标形状设置示例",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULE,0,
NULL,
NULL,
hInstance,
NULL);
if(!hWnd)
return FALSE;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}