Compilation Environment: VS2017
The main file is:
1#include"stdafx.h"2#include"WindowsProject5.h"3#include"Resource.h"4 #defineNULL 05 6 7 //callback function8 BOOL CALLBACK Mainproc (9 HWND Hwnddlg,Ten UINT umsg, One WPARAM WPARAM, A LPARAM LPARAM) - { - //The following three behavior debug statements can be used to remove the Chars[ the]; -wsprintf ((LPWSTR) s,l"umsg=%d,wparam=%d,lparam=%d\n", umsg, WParam, (int) lParam); - OutputDebugStringW ((LPWSTR) s); - + //for menu, accelerator key, click Send WM_COMMAND message - if(Wm_command = =umsg) + { A //If you click the Cancel button, close the dialog box at if(LoWord (wParam) = =IDCANCEL) - { - EndDialog (Hwnddlg, IDCANCEL); - returnTRUE; - }; - //If you click the Calculate button, the addition is calculated and the result is obtained. in if(LoWord (wParam) = =IDOK) - { to intNleft =Getdlgitemint (Hwnddlg, Idc_left, NULL, TRUE); + intNright =Getdlgitemint (Hwnddlg, Idc_right, NULL, TRUE); - intNresult = Nleft +Nright; the Setdlgitemint (hwnddlg,idc_result,nresult,true); * } $ }Panax Notoginseng returnFALSE; - } the + //win main function A intapientry wWinMain (_in_ hinstance hinstance, the _in_opt_ hinstance hPrevInstance, + _in_ lpwstr lpCmdLine, -_in_intncmdshow) $ { $ -DialogBox (HInstance, (LPWSTR) Idd_dialog1,0, (Dlgproc) mainproc); - return 0; the}
Resource file:
1 #define Idi_icon2 1312#define idd_dialog1 1333#define idc_result 1004 4 #define Idc_right 10055#define idc_left 10066#define idc_static -1
dialog box:
Operation Result:
Write a simple Windows Desktop Calculator program