【源文件:wnd.c】 #include <tchar.h> #include <Windows.h> #include "resource.h"
INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { HICON hIcon, hIconSm; HMENU hMenu; int wmId; switch (uMsg) { case WM_COMMAND: wmId = LOWORD(wParam); switch (wmId) { case IDOK: MessageBox(hDlg, TEXT("Hello World!"), TEXT("Hello"), MB_OK); break; case IDCANCEL: EndDialog(hDlg, wmId); break; case IDM_OPEN: MessageBox(hDlg, TEXT("Cannot open!"), TEXT("Error"), MB_ICONERROR); break; } break; case WM_INITDIALOG: hIcon = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(MYICON), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), (UINT)NULL); hIconSm = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(MYICON), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), (UINT)NULL); SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon); SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm); hMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(MYMENU)); SetMenu(hDlg, hMenu); break; } return FALSE; }
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { DialogBox(hInstance, MAKEINTRESOURCE(MYDIALOG), NULL, DlgProc); return 0; }
|