-
stuffed up window proc.
hi,
I have a win32 program that creates 3 windows.
The first window is the parent for the second, and the first one is never displayed and does not need to recieve messages. (the first window is only to stop the second one appearing on the task bar)
I then create a third window that is a child of the second one.
Both the second and the third have their own window class and window procedure.
My problem is that the third window's window procedure never gets called, it all goes to the second window's window procedure as if i had clicked on the second window.
why is this happending??
thanks,
Robert.
-
Need to see the code for the creation of the windows winclass.
Especially
WndClass.lpfnWndProc = (WNDPROC) MainCallback;
Are they the right ones? (I think they will both be for window #2)
-
well.. thats the thing i first checked and they are different. What i dont get is that when i click on the third window, it goes to the second window and reports the HWND of the SECOND!
code is below...
Code:
// setup and register window class
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProcI;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, (char*)IDI_MAIN);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = black; //(HBRUSH)(COLOR_BTNFACE + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = INDCLS;
RegisterClass(&wc);
// create indicator window
HWND hwnd = CreateWindow(INDCLS, TITLE, WS_POPUP, 0, 0,
400, 24, hParent, NULL, hInstance, NULL);
thats the 3rd window
and this is the first and second ones...
Code:
// setup and register window class
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProcM;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, (char*)IDI_MAIN);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = black; //(HBRUSH)(COLOR_BTNFACE + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = NAME;
RegisterClass(&wc);
// create host window
HWND hmain = CreateWindow(NAME, TITLE, WS_POPUP, 10, 10,
400, 300, NULL, NULL, hInstance, NULL);
// create main window
HWND hwnd = CreateWindow(NAME, TITLE, WS_POPUP, 10, 10,
400, 300, hmain, NULL, hInstance, NULL);
any help would be great.
-
There was no code so I started with the first thing I would have looked at.
Looks like you have created a child (even though you do not use the WS_CHILD | WS_OVERLAPPED | WS_POPUP ) by specifing the hmain for the HWND PARENT, then failed to have different ID# for the windows.
Code:
#define IDW_SECOND 10001
#define IDW_THIRD 10002
HWND hwnd = CreateWindow(NAME, TITLE, WS_POPUP, 10, 10,400, 300, hmain, (HMENU)IDW_SECOND, hInstance, NULL);
HWND hwnd = CreateWindow(INDCLS, TITLE, WS_POPUP, 10, 10,400, 24, hparent, (HMENU)IDW_THIRD, hInstance, NULL);
-
i dont get it... how is setting an invalid menu handle to the window changing the id? I tried your code but it just fails to create the window.
pls explain.
-
hmmm... are you releasing capture after the click? this could be causing one window to send messages back to the other one...?
-out-
PsychoBrat
-
There is one other error (in my code as well as I cut and pasted) but I thought it was a typo.
You use HWND hwnd for both main and indicator windows which would explain the problem.
from MSDN help
CreateWindow(
//blah
//blah
hWndParent
//blah
Although this parameter must specify a valid handle if the dwStyle parameter includes the WS_CHILD style, it is optional if dwStyle includes the WS_POPUP style.
hMenu
//blah
For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.
but you don't want to use childs because of the size restrictions (has to be in client area of parent)