编写简单的windows桌面计算器程序
2021-04-09 16:27
标签:== cancel bool pcm pie ret windows 技术 resource 编译环境:VS2017 主文件为: 资源文件: 对话框截图: 运行结果: 编写简单的windows桌面计算器程序 标签:== cancel bool pcm pie ret windows 技术 resource 原文地址:https://www.cnblogs.com/junjunjun123/p/9059716.html 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
文章标题:编写简单的windows桌面计算器程序
文章链接:http://soscw.com/index.php/essay/73396.html