我有一个基本的包装类,用于使用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