1. 加载光标 注意 加载光标不能发送WM_SETCURSOR 光标的位置不断变化 只在一瞬间有效
case WM_CHAR:
{
HICON hCursor = = LoadCursor(NULL,IDC_ARROW); //加载标准光标
SetClassLong(hWnd,GCL_HCURSOR,(LPARAM)hCursor);
HCURSOR hCursor = LoadCursor(hInst,MAKEINTRESOURCE(IDC_CURSOR1)); //加载自定义光标
SetClassLong(hWnd,GCL_HCURSOR,(LPARAM)hCursor);
HCURSOR hCursor2 = LoadCursorFromFile("Cursor.cur"); //从文件加载静态光标
SetClassLong(g_hWnd,GCL_HCURSOR,(LPARAM)hCursor2);
HCURSOR hCursor3 = LoadCursorFromFile("Working.ani"); //从文件加载动态光标
SetClassLong(hWnd,GCL_HCURSOR,(LPARAM)hCursor3);
}
break;
2.加载图标
HICON hIconN=(HICON)LoadImage(NULL,L"directx.ico",IMAGE_ICON,0,0,LR_LOADFROMFILE);
SetClassLong(DXUTGetHWND(),GCL_HICON,(LPARAM)hIconN);
动态设置图标时注意
在类的声明时把 hIconSm 设置为 NULL 如果一开始就加载图标 当只有32x32 的图标时,就无法实现动态变化图标
// wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
wcex.hIconSm = NULL;
// HICON hIconN = LoadIcon(NULL,IDI_HAND);
HICON hIconN = LoadIcon(hInst,MAKEINTRESOURCE(IDI_ICON2));
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
case IDI_ICON_C:
SetClassLong(g_hWnd,GCL_HICON,(LPARAM)hIconN); //设置图标
break;
}
3. SetClassLong 函数可以修改窗口类的背景色 光标 图标 hInstance 菜单 风格 窗口过程地址
DWORD SetClassLong(
HWND hWnd, // handle to window
int nIndex, // index of value to change
LONG dwNewLong // new value
);
nIndex:
GCL_HBRBACKGROUND
GCL_HCURSOR
GCL_HICON
GCL_HICONSM
GCL_HMODULE
GCL_MENUNAME
GCL_STYLE
GCL_WNDPROC
SendMessage(hWnd,WM_SETICON,ICON_BIG,hIcon);
消息的wParam参数可以是ICON_BIG或ICON_SMALL,用来指定图标的分辨率为
32×32还是16×16。