我正在使用类构建我的第一个 c++ 项目(试图获得更多经验),现在我被卡住了。我需要确定从我的计算器应用程序中按下了哪个按钮。我设置项目的方式是:
Windows.cpp
// Windows.cpp
#include <Windows.h>
#include <wchar.h>
#include "Resource.h"
#include "Application.h"
int WINAPI wWinMain(...)
{
// after register class and create/show/update window ( winMain() )
Application App(hwnd);
App.Go();
// Main message loop, etc.
MSG msg;
ZeroMemory(&msg,sizeof(msg));
while(msg.message != WM_QUIT)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
应用程序.h
#pragma once
#include "Calculator.h"
class Application
{
public:
Application(HWND hwnd);
~Application();
void Go();
private:
void Run();
private:
Calculator calc;
};
应用程序.cpp:
// Application.cpp
#include "Application.h"
Application::Application(HWND hwnd)
: calc(hwnd)
{}
Application::~Application()
{}
void Application::Go()
{
calc.Initiate(); // This function shows all my button controls for my calculator
Run();
}
void Application::Run()
{
// This is where i want to determine which button was pressed(if any)
if(buttonONEwasPRESSED) { /* do stuff */ } // etc
}
我考虑向 Calculator 类添加一个函数来确定是否按下了按钮,但我不确定如何访问 wm_command,或者是否有其他方式。然后我可以调用 calc.IsButtonPressed()。