Subject:
WNDPROC problem
From:
"Dmitry Baryshev" ####@####.####
Date:
28 May 2008 12:11:08 -0000
Message-Id: <39840bc80805280511w21412983v97155792e550647b@mail.gmail.com>
Hi. I found a problem with SetWindowLong(..., GWL_WNDPROC, ...) using
Microwindows-0.91. If I install new WNDPROC on some widget with type T
("LISTBOX", for example), it will be installed on all widgets of type
T.
Source code:
#include <windows.h>
#include <cstdio>
LRESULT CALLBACK wproc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK lwproc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
WNDPROC oldproc;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static const char szAppName[] = "Display";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
MwRegisterButtonControl(NULL);
MwRegisterEditControl(NULL);
MwRegisterListboxControl(NULL);
MwRegisterProgressBarControl(NULL);
MwRegisterStaticControl(NULL);
wndclass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = (WNDPROC)wproc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = 0;
wndclass.hIcon = 0;
wndclass.hCursor = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
RegisterClass(&wndclass);
hwnd = CreateWindowEx(0L,
szAppName,
"Display test",
WS_VISIBLE | WS_OVERLAPPED | WS_POPUP,
0, 0,
320, 200,
0, 0, 0, 0);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
HWND h1 = CreateWindowEx(0L, "LISTBOX", "Listbox1",
WS_BORDER | WS_CHILD | WS_VISIBLE,
0, 0, 80, 172,
hwnd,
0, 0, 0);
SendMessage(h1, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Type1");
SendMessage(h1, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Type2");
SendMessage(h1, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Type3");
SendMessage(h1, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Type4");
HWND h2 = CreateWindowEx(0L, "LISTBOX", "Listbox2",
WS_BORDER | WS_CHILD | WS_VISIBLE,
82, 0, 80, 172,
hwnd,
0, 0, 0);
SendMessage(h2, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Type5");
SendMessage(h2, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Type6");
SendMessage(h2, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Type7");
SendMessage(h2, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Type8");
HWND h3 = CreateWindowEx(0L, "LISTBOX", "Listbox3",
WS_BORDER | WS_CHILD | WS_VISIBLE,
164, 0, 80, 172,
hwnd,
0, 0, 0);
SendMessage(h3, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Type9");
SendMessage(h3, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Type10");
SendMessage(h3, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Type11");
SendMessage(h3, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Type12");
printf("WINDOWS:\n\t%d\n\t%d\n\t%d\n", (int)h1, (int)h2, (int)h3);
oldproc = (WNDPROC)SetWindowLong(h1, GWL_WNDPROC, (LONG)lwproc);
while(GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK lwproc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
printf("HWND %d\n", (int)hwnd);
// call old wndproc
oldproc(hwnd, iMsg, wParam, lParam);
}
LRESULT CALLBACK wproc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch(iMsg)
{
case WM_DESTROY:
KillTimer(hwnd, 1);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
return 0;
}
# g++ -o mtest mtest.cpp -Imw/include -lmwin
# ./mtest > log 2>&1
# cat log
WINDOWS:
134527024
134527672
134528608
HWND 134528608
HWND 134528608
HWND 134528608
HWND 134527672
HWND 134527672
HWND 134527672
HWND 134527024
HWND 134527024
HWND 134527024
HWND 134528608
HWND 134528608
HWND 134528608
...
Description: I installed new event handler on widget h1, but this
event handler also grabs events from h2 and h3. How can I fix it?
Thanks in advance.
--