Write a simple Windows Desktop Calculator program

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.