#include <windows.h>
#include "resource.h"
HMENU hmenu;LRESULT CALLBACK WinProc (HWND,UINT,WPARAM,LPARAM);
int Quit (HWND hwnd);int WINAPI WinMain (HINSTANCE hInstance,HINSTANCE hPrevInstance,
 LPSTR lpCmdLine,int nShowCmd)
{
WNDCLASSEX wndclass;
HWND hwnd;
MSG msg;
static TCHAR clsname[] = TEXT("lizhi");
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = HBRUSH(COLOR_WINDOW + 1);
wndclass.hCursor = LoadCursor (hInstance,MAKEINTRESOURCE(IDC_1));
wndclass.hIcon = LoadIcon (hInstance,MAKEINTRESOURCE (IDI_BIG));
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WinProc;
wndclass.lpszClassName = clsname;
wndclass.lpszMenuName = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.cbSize = sizeof (WNDCLASSEX);
wndclass.hIconSm = LoadIcon (hInstance,MAKEINTRESOURCE (IDI_SMALL)); if(!RegisterClassEx (&wndclass))
{
MessageBox (NULL,TEXT ("NT!"),clsname,MB_ICONERROR);
return 0;
}
hmenu = LoadMenu (hInstance,MAKEINTRESOURCE (IDM_MAIN)); hwnd = CreateWindowEx (WS_EX_CLIENTEDGE,clsname,clsname,
WS_OVERLAPPEDWINDOW,100,100,400,300,
NULL,hmenu,hInstance,NULL); ShowWindow (hwnd,SW_SHOWNORMAL);
UpdateWindow (hwnd); while (GetMessage (&msg,NULL,0,0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam ;
}LRESULT CALLBACK WinProc (HWND hwnd,UINT msg,
  WPARAM wParam,LPARAM lParam )
{
//static HMENU hmenu;
static HCURSOR hcur1,hcur2;
static HICON hiconbig,hiconsmall;
HINSTANCE hinstance; switch (msg)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_BIG:
SendMessage (hwnd,WM_SETICON,ICON_BIG,(long)hiconbig);
CheckMenuRadioItem (hmenu,IDM_SMALL,IDM_BIG,IDM_BIG,MF_BYCOMMAND);
break;
case IDM_SMALL:
SendMessage (hwnd,WM_SETICON,ICON_SMALL,(long)hiconsmall);
CheckMenuRadioItem (hmenu,IDM_SMALL,IDM_BIG,IDM_SMALL,MF_BYCOMMAND);
break;
case IDM_CUR1:
SetClassLong (hwnd,GCL_HCURSOR,(long)hcur1);
CheckMenuRadioItem (hmenu,IDM_CUR1,IDM_CUR2,IDM_CUR1,MF_BYCOMMAND);
break;
case IDM_CUR2:
SetClassLong (hwnd,GCL_HCURSOR,(long)hcur2);
CheckMenuRadioItem (hmenu,IDM_CUR1,IDM_CUR2,IDM_CUR2,MF_BYCOMMAND);
break;
case IDM_EXIT:
Quit(hwnd);
break;
}
return 0;
case WM_CREATE:
hinstance = (HINSTANCE)GetWindowLong (hwnd,GWL_HINSTANCE);
hcur1 = LoadCursor (hinstance,MAKEINTRESOURCE (IDC_1));
hcur2 = LoadCursor (hinstance,MAKEINTRESOURCE (IDC_2)); hiconsmall = LoadIcon (hinstance,MAKEINTRESOURCE (IDI_SMALL));
hiconbig = LoadIcon (hinstance,MAKEINTRESOURCE (IDI_BIG)); //SetClassLong (hwnd,GCL_HCURSOR,(long)hcur1);
//CheckMenuRadioItem (hmenu,IDM_CUR1,IDM_CUR1,IDM_CUR2,MF_BYCOMMAND); SendMessage (hwnd,WM_COMMAND,IDM_BIG,NULL);
SendMessage (hwnd,WM_COMMAND,IDM_CUR1,NULL);
//CheckMenuRadioItem (hmenu,IDM_BIG,IDM_SMALL,IDM_BIG,MF_BYCOMMAND); return 0;
case WM_CLOSE:
Quit(hwnd);
return 0;
} return DefWindowProc (hwnd,msg,wParam,lParam);
}int Quit (HWND hwnd)
{
DestroyWindow (hwnd);
PostQuitMessage(0);
return 0;
}
它可以从大图标改为小图标,但是为什么之后就不能改变了???

解决方案 »

  1.   

    hiconsmall = LoadIcon (hinstance,MAKEINTRESOURCE (IDI_SMALL));
    hiconbig = LoadIcon (hinstance,MAKEINTRESOURCE (IDI_BIG));
     这2个数据在哪里用到了?
      

  2.   

    改变图标的时候啊
    case IDM_BIG:
    SendMessage (hwnd,WM_SETICON,ICON_BIG,(long)hiconbig);
    CheckMenuRadioItem (hmenu,IDM_SMALL,IDM_BIG,IDM_BIG,MF_BYCOMMAND);
    break;
    case IDM_SMALL:
    SendMessage (hwnd,WM_SETICON,ICON_SMALL,(long)hiconsmall);
    CheckMenuRadioItem (hmenu,IDM_SMALL,IDM_BIG,IDM_SMALL,MF_BYCOMMAND);
    break;