Ready to scream
Okay, i''m doing a basic win32 application to exercise my knowledge and understanding of menus
here is the problem code ( I think )
if (!(hWnd = CreateWindowEx(NULL, NULL,
"Menu Example", WS_OVERLAPPEDWINDOW, 0, 0, 400, 400, NULL, LoadMenu(hInstance, "MainMenu"), hInstance, NULL) ) )
return (0);
from what i can gather, hWnd is not being created okay, what could cause this?
I have a sneaking suspicion as i''m writing this that I did something funky in the other part of the program, but to be safe i figured i''d ask :p
The second parameter of CreateWindowEx is supposed to be the name of a window class you registered with RegisterClass, not NULL.
Play free Java games at: www.infinitepixels.com
Maybe it is okay to have it NULL but I always pass CreateWindowEx a pointer to a window class for the second parameter.
Here is code to set it up straight from Windows Game Prog. Gurus:
WNDCLASSEX winclass;
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS / CS_OWNDC / CS_HREDRAW /
CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(hinstance, IDI_APPLICATION);
winclass.hCursor = LoadCursor(hinstance, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject
(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = "WINCLASS1";
winclass.hIconSm = LoadIcon(hinstance, IDI_APPLICATION);
then just replace NULL with "WINCLASS1" as the second parameter. Then if the code doesn''t work, your problem lies elsewhere.
Were you getting an error, or did the program just quit?
bcj
Here is code to set it up straight from Windows Game Prog. Gurus:
WNDCLASSEX winclass;
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS / CS_OWNDC / CS_HREDRAW /
CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(hinstance, IDI_APPLICATION);
winclass.hCursor = LoadCursor(hinstance, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject
(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = "WINCLASS1";
winclass.hIconSm = LoadIcon(hinstance, IDI_APPLICATION);
then just replace NULL with "WINCLASS1" as the second parameter. Then if the code doesn''t work, your problem lies elsewhere.
Were you getting an error, or did the program just quit?
bcj
Whoops, that''s right. You have to register the class first. So after the big snippet of code and before your call to CreateWindowEx() make this call:
RegisterClassEx(&winclass)
bcj
RegisterClassEx(&winclass)
bcj
Dang, in the code above; when setting winclass.style, those are supposed to be pipes, not slashes.
bcj
bcj
aye, i did register the class. but i figured that wasn''t the problem.
I changed the second param to "winclass" and that didn''t help, either.
so apparently the error lies elsewhere :/
I changed the second param to "winclass" and that didn''t help, either.
so apparently the error lies elsewhere :/
Ok, I''m not sure if you know this so I''ll post this in case you don''t, the second parameter (the way I do it and it always works, bcj''s might work also) is a string equal to the lpszClassName field of your WNDCLASS :
WNDCLASS wc;
wc.lpszClassName = "My Program";
...
RegisterClass(&wc);
HWND hWnd = CreateWindowEx(WS_EX_DLGMODALFRAME,
"My Program", // This matches lpszClassName
...
WNDCLASS wc;
wc.lpszClassName = "My Program";
...
RegisterClass(&wc);
HWND hWnd = CreateWindowEx(WS_EX_DLGMODALFRAME,
"My Program", // This matches lpszClassName
...
Chris
how interesting, i tried both of your method''s and it didn''t work. I''ve come to the conclusion i made a major error somewhere else down the line, sorry for the trouble guys
You may also want to OR the WS_VISIBLE flag with the WS_OVERLAPPPEDWINDOW. Not having the WS_VISIBLE flag wont cause CreateWindowEx to fail, but you never said if you were getting by that portion of code or not. So if you are getting by, maybe the missing WS_VISIBLE flag is why you don''t see the window.
Play free Java games at: www.infinitepixels.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement