我有一个基本的包装类,用于使用 WinAPI 在 C++ 中创建的按钮。我尝试处理消息,但似乎并非所有内容都能到达我的WndProc
class MyButton {
public:
MyButton(HINSTANCE, HWND);
private:
HWND _hWnd;
static LRESULT CALLBACK _WndProc(HWND, UINT, WPARAM, LPARAM, UINT_PTR, DWORD_PTR);
};
MyButton::MyButton(HINSTANCE hInst, HWND hParent)
{
this->_hWnd = CreateWindow(
TEXT("BUTTON"),
TEXT("CLICK ME"),
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
10, 10,
100, 25,
hParent,
NULL,
hInst,
this
);
SetWindowSubclass(this->_hWnd, this->_WndProc, 1, (DWORD_PTR)this);
}
LRESULT CALLBACK MyButton::_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSub, DWORD_PTR dwRef)
{
// MessageBox(NULL, L"TEST1", L"TEST1", MB_OK | MB_ICONINFORMATION);
MyButton *pThis = (MyButton*)dwRef;
switch (uMsg)
{
case WM_COMMAND:
MessageBox(NULL, L"TEST2", L"TEST2", MB_OK | MB_ICONINFORMATION);
break;
}
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
该函数被调用(显示了“TEST1”)但是当我单击按钮时,我看不到“TEST2”。我也试过了WM_CREATE
,它也不起作用。我不知道传递给什么消息_WndProc