(二)表徵圖和游標
#include<windows.h><br />#include"Resource.h"</p><p>TCHARszName[] = TEXT("Icon and Cursor Example");<br />HICONhIconBig, hIconSmall;<br />HCURSOR hCur1, hCur2;<br />HMENUhMenu;<br />HINSTANCEhInst;</p><p>LRESULT CALLBACK ProcWinMain(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)<br />{<br />switch(uMsg)<br />{<br />case WM_CREATE:<br />hIconBig = LoadIcon(hInst, MAKEINTRESOURCE(IDI_BIG));<br />hIconSmall = LoadIcon(hInst, MAKEINTRESOURCE(IDI_SMALL));<br />hCur1 = LoadCursorFromFile(TEXT("1.ANI"));<br />hCur2 = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR));</p><p>SendMessage(hWnd, WM_COMMAND, IDM_BIG, 0);<br />SendMessage(hWnd, WM_COMMAND, IDM_CUR1, 0);<br />return 0;</p><p>case WM_COMMAND:<br />switch(LOWORD(wParam))<br />{<br />case IDM_EXIT:<br />DestroyWindow(hWnd);<br />PostQuitMessage(0);<br />return 0;</p><p> case IDM_BIG:<br />CheckMenuRadioItem(hMenu, IDM_BIG, IDM_SMALL, IDM_BIG, MF_BYCOMMAND);<br />SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIconBig);<br />return 0;</p><p>case IDM_SMALL:<br />CheckMenuRadioItem(hMenu, IDM_BIG, IDM_SMALL, IDM_SMALL, MF_BYCOMMAND);<br />SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIconSmall);<br />return 0;</p><p>case IDM_CUR1:<br />CheckMenuRadioItem(hMenu, IDM_CUR1, IDM_CUR2, IDM_CUR1, MF_BYCOMMAND);<br />SetClassLong(hWnd, GCL_HCURSOR, (LONG)hCur1);<br />return 0;</p><p>case IDM_CUR2:<br />CheckMenuRadioItem(hMenu, IDM_CUR1, IDM_CUR2, IDM_CUR2, MF_BYCOMMAND);<br />SetClassLong(hWnd, GCL_HCURSOR, (LONG)hCur2);<br />return 0;<br />}<br />break;</p><p>case WM_CLOSE:<br />DestroyWindow(hWnd);<br />PostQuitMessage(0);<br />return 0;<br />}<br />return DefWindowProc(hWnd, uMsg, wParam, lParam);<br />}</p><p>int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)<br />{<br />WNDCLASSEXstWndCls;<br />MSGstMsg;<br />HWNDhMainWnd;</p><p>hInst = hInstance;<br />hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDM_MAIN));<br />RtlZeroMemory(&stWndCls, sizeof(stWndCls));<br />stWndCls.cbWndExtra = 0;<br />stWndCls.cbClsExtra = 0;<br />stWndCls.hInstance = hInst;<br />stWndCls.cbSize = sizeof(WNDCLASSEX);<br />stWndCls.style = CS_HREDRAW | CS_VREDRAW;<br />stWndCls.lpfnWndProc = ProcWinMain;<br />stWndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);<br />stWndCls.lpszClassName = szName;<br />stWndCls.lpszMenuName = NULL;</p><p>RegisterClassEx(&stWndCls);<br />hMainWnd = CreateWindowEx(WS_EX_CLIENTEDGE, szName, szName,<br />WS_OVERLAPPEDWINDOW, 500, 200, 300, 185, NULL, hMenu, hInstance, NULL);</p><p>ShowWindow(hMainWnd, SW_SHOWNORMAL);<br />UpdateWindow(hMainWnd);</p><p>while(GetMessage(&stMsg, NULL, 0, 0))<br />{<br />TranslateMessage(&stMsg);<br />DispatchMessage(&stMsg);<br />}<br />return stMsg.wParam;<br />}