標籤:== cancel bool pcm pie ret windows 技術 resource
編譯環境: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 1312 #define IDD_DIALOG1 1333 #define IDC_RESULT 10044 #define IDC_RIGHT 10055 #define IDC_LEFT 10066 #define IDC_STATIC -1
對話方塊:
運行結果:
編寫簡單的windows案頭計算機程式