Nope it doesnt seem to receive WM_LBUTTONDOWN and WM_RBUTTONDOWN events and probably others. I create the window like this:
Code:
CreateWindowEx(0,
"STATIC",
"Test",
WS_CHILD | WS_VSCROLL | WS_HSCROLL,
10,
10,
500,
400,
getHandle(),
NULL,
GetModuleHandle(NULL),
NULL)
and sub class it like this:
Code:
SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)this);
SetWindowLong(handle, GWL_WNDPROC, (LONG)winProc);
and the sub classed window procedure looks like this:
Code:
LRESULT CALLBACK CControlClass::winProc(HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
{
CControlClass* control = (CControlClass*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
if (control)
{
TEvent event;
CMessageHandler* msgHandle = NULL;
memset(&event, 0, sizeof(event));
switch (message)
{
...
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
if(control->onMouseClickHandle.isSet())
{
event.onMouseClick.button = wParam;
event.onMouseClick.mouseX = LOWORD(lParam);
event.onMouseClick.mouseY = HIWORD(lParam);
msgHandle = &control->onMouseClickHandle;
}
break;
...
}
if (msgHandle)
{
if (msgHandle->call(event))
return 0;
}
return CallWindowProc(control->defaultProc, hWnd, message, wParam, lParam);
}
return 1;
}
And the event handling looks like this:
Code:
#define MessageHandler(a, b) CMessageHandler((int (CControlClass::*)(const TEvent&))(a), b)
class CMyWindow:
public CControlClass
{
CControlClass canvas;
public:
CMyWindow(HWND hWnd): CControlClass(hWnd)
{
//Create a canvas
canvas.create(CreateWindowEx(
0,
"STATIC",
"Test",
WS_CHILD | WS_VSCROLL | WS_HSCROLL,
10,
10,
500,
400,
getHandle(),
NULL,
GetModuleHandle(NULL),
NULL));
canvas.onMouseClickHandle = MessageHandler(&CMyWindow::canvas_onMouseClick, this);
canvas.show(SW_SHOWNORMAL);
this->onCloseHandle = MessageHandler(&CMyWindow::onClose, this);
this->onDestroyHandle = MessageHandler(&CMyWindow::onDestroy, this);
this->show(SW_SHOWNORMAL);
}
int canvas_onMouseClick(const TEvent& event)
{
printf("canvas Mouse clicked\n");
return 0;
}
int onClose(const TEvent& event)
{
destroy();
printf("Destroyed\n");
return 0;
}
int onDestroy(const TEvent& event)
{
PostQuitMessage(0);
return 0;
}
};
If i change the control to "EDIT" the mouse click event works (but looks and behaves like an edit box). If i set it to STATIC it will not work.