編譯環境:VS2017
主文件為:
1 #include "stdafx.h" 2 #include "WindowsProject5.h" 3 #include "Resource.h" 4 #define NULL 0 5 6 7 //回調函數 8 BOOL CALLBACK MainProc( 9 HWND hwndDlg, 10 UINT uMsg, 11 WPARAM wParam, 12 LPARAM lParam) 13 { 14 //以下三行為調試語句,可去除 15 char s[256]; 16 wsprintf((LPWSTR)s,L"uMsg=%d,wParam=%d,lParam=%d\n", uMsg, wParam, (int)lParam); 17 OutputDebugStringW((LPWSTR)s); 18 19 //對於菜單、加速鍵來說,點擊后發送WM_COMMAND消息 20 if (WM_COMMAND == uMsg) 21 { 22 //如果點擊取消按鈕,關閉對話框 23 if (LOWORD(wParam) == IDCANCEL) 24 { 25 EndDialog(hwndDlg, IDCANCEL); 26 return TRUE; 27 }; 28 //如果點擊計算按鈕,進行加法計算,得出結果 29 if (LOWORD(wParam) == IDOK) 30 { 31 int nLeft = GetDlgItemInt(hwndDlg, IDC_LEFT, NULL, TRUE); 32 int nRight = GetDlgItemInt(hwndDlg, IDC_RIGHT, NULL, TRUE); 33 int nResult = nLeft + nRight; 34 SetDlgItemInt(hwndDlg,IDC_RESULT,nResult,TRUE); 35 } 36 } 37 return FALSE; 38 } 39 40 //win主函數 41 int APIENTRY wWinMain(_In_ HINSTANCE hInstance, 42 _In_opt_ HINSTANCE hPrevInstance, 43 _In_ LPWSTR lpCmdLine, 44 _In_ int nCmdShow) 45 { 46 47 DialogBox(hInstance,(LPWSTR)IDD_DIALOG1,0,(DLGPROC)MainProc); 48 return 0; 49 }
資源文件:
1 #define IDI_ICON2 131 2 #define IDD_DIALOG1 133 3 #define IDC_RESULT 1004 4 #define IDC_RIGHT 1005 5 #define IDC_LEFT 1006 6 #define IDC_STATIC -1
對話框截圖:
運行結果: