仿微软写了一个win32 计算器小程序

3 篇文章 0 订阅

只实现了外观,功能 还没有实现,有时间再把它补全

main.cpp文件如下:

 

#include <Windows.h>
#include "resource.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	HWND hWnd;
	WNDCLASS wndclass;
	MSG msg;
	static TCHAR szAppName[]= TEXT("我的世界");
	wndclass.style = CS_HREDRAW | CS_VREDRAW;
	wndclass.lpfnWndProc = WndProc;
	wndclass.cbClsExtra = 0;
	wndclass.cbWndExtra = DLGWINDOWEXTRA;
	wndclass.hInstance = hInstance;
	wndclass.hIcon = LoadIcon(NULL, IDC_ARROW);
	wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndclass.lpszClassName = szAppName;
	wndclass.lpszMenuName = NULL;
	wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
	if (!RegisterClass(&wndclass))
	{
		MessageBox(NULL, TEXT("窗口无法显示"), szAppName, MB_ICONERROR);
		return 0;
	}
	hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), 0, NULL);
	ShowWindow(hWnd, iCmdShow);
	while (GetMessage(&msg, hWnd, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	//static BOOL bNewNumber = TRUE;
	//static int iOperator = '=';
	//static UINT iNumber, iFirstNum;
	//HWND hButton;
	//HDC hdc;
	//HFONT hFont;
	//设置字体
	//LOGFONT lf;
	
	//TEXTMETRIC tm;
//	SaveDC(hdc);
	switch (message)
	{
	case WM_SETFONT:
		//hdc = GetDC(hwnd);
		//GetTextMetrics(hdc, &tm);
		//lf.lfHeight = 35;
		//hFont = CreateFontIndirect(&lf);
		//SelectObject(hdc, hFont);
		//ReleaseDC(hwnd, hdc);
		break;
	case WM_INITDIALOG:

		break;
	case WM_KEYDOWN:
		break;
	case WM_CHAR:
		break;
	case WM_COMMAND:
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		break;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);
}

 

 

resource.rc 文件如下:

 

//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ 生成的包含文件。
// 供 Resource.rc 使用
//
#define IDD_DIALOG1                     101
#define IDC_EDIT_RESULT                 1001
#define IDC_BUTTON_PERCENT              1002
#define IDC_BUTTON2                     1003
#define IDC_NUMBER_7                    1004
#define IDC_NUMBER_4                    1005
#define IDC_NUMBER_1                    1006
#define IDC_BUTTON_PLUSMINUS            1007
#define IDC_BUTTON_ROOT                 1008
#define IDC_BUTTON8                     1009
#define IDC_NUMBER_8                    1010
#define IDC_NUMBER_5                    1011
#define IDC_NUMBER_2                    1012
#define IDC_NUMBER_0                    1013
#define IDC_BUTTON_RECIPROCAL           1014
#define IDC_BUTTON_DIV                  1015
#define IDC_BUTTON_MUL                  1016
#define IDC_BUTTON_MINUS                1017
#define IDC_BUTTON_PLUS                 1018
#define IDC_BUTTON18                    1019
#define IDC_BUTTON_EQUAL                1019
#define IDC_BUTTON_SQUARE               1020
#define IDC_BUTTON20                    1021
#define IDC_NUMBER_9                    1022
#define IDC_NUMBER_6                    1023
#define IDC_NUMBER_3                    1024
#define IDC_BUTTON24                    1025

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        103
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1003
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif


实现界面如图所示:

 

---------------------重新写了一个,大家可以移步到此

https://blog.csdn.net/celly20/article/details/89005992


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值