void cApp::CreateMainWindow(int ShowCode)
{
const char ClassName[] = "MyGame";
WNDCLASSEX WndCX =
{ sizeof(WNDCLASSEX),CS_CLASSDC, (WNDPROC)MessagePump,0,0,hInstance,NULL,NULL,(HBRUSH)(COLOR_BACKGROUND),NULL, "MyGame",NULL};
if (!RegisterClassEx(&WndCX))
{
char error[256];
sprintf(error, "Error1 %u", GetLastError());
MessageBox(NULL, error, "Error!",MB_ICONEXCLAMATION | MB_OK);
TerminateProgram();
}
MainWnd=CreateWindow("MyGame", "Velochy", WS_POPUP | WS_EX_TOPMOST, CW_USEDEFAULT, CW_USEDEFAULT, 300, 200, NULL, NULL, hInstance, NULL );
if (MainWnd==NULL)
{
char error[256];
sprintf(error, "Error2 %u", GetLastError());
MessageBox(NULL, error, "Error!",MB_ICONEXCLAMATION | MB_OK);
TerminateProgram();
}
ShowWindow(MainWnd, ShowCode);
UpdateWindow(MainWnd);
return;
}
🔒 Locked
CreateWindow problems
Advertisement
Original Post
This is my Window procedure which keeps giving me an Error 2: 1400 message box AKA it cannot create the MainWnd.. anyone got any ideas as to what might be causing it?
It might be because you are trying to do in in a class. I know this can cause all sorts of problems. I copied your code and it compiled and ran fine for me. The only difference is that I did not put the code inside a class.
Make it work.
Make it fast.
"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book
Make it work.
Make it fast.
"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book
nope, didnt really work
could anyone take the time to actully try this function in their program.. perhaps the error is somewhere else.. altho it seems highly unlikely.
ANy other ideas anyone?
Update:
okay, ill try to take it out of a class and see what happends, thanx for compiling
[edited by - Velochy on October 10, 2002 8:38:09 AM]
could anyone take the time to actully try this function in their program.. perhaps the error is somewhere else.. altho it seems highly unlikely.
ANy other ideas anyone?
Update:
okay, ill try to take it out of a class and see what happends, thanx for compiling
[edited by - Velochy on October 10, 2002 8:38:09 AM]
and nope, takin it out of a class did jack for the code
perhaps it is something that has to be done before the window creation that i didnt include in the program.. this is the first function called.. the hInstance and ShowCode are both valid(given by windows and passed on directly) but if something needs to be done before these things described in CreateMainWindow, i would really like to know about them
perhaps it is something that has to be done before the window creation that i didnt include in the program.. this is the first function called.. the hInstance and ShowCode are both valid(given by windows and passed on directly) but if something needs to be done before these things described in CreateMainWindow, i would really like to know about them
Having the code in a class member function is fine.
What does your WM_NCCREATE/WM_CREATE processing code look like? Are you returing from your handler during the processing of these msgs with your own return, or with the returned value from DefWindowProc?
If you''re returing with your own value, then you need to make sure they''re the right ones to indicate that the creation process should continue. I think it''s 1 for WM_NCREATE and 0 for WM_CREATE. But it''s best just to let DefWindowProc return the appropriate value.
What does your WM_NCCREATE/WM_CREATE processing code look like? Are you returing from your handler during the processing of these msgs with your own return, or with the returned value from DefWindowProc?
If you''re returing with your own value, then you need to make sure they''re the right ones to indicate that the creation process should continue. I think it''s 1 for WM_NCREATE and 0 for WM_CREATE. But it''s best just to let DefWindowProc return the appropriate value.
Have you looked to see if the window was created? (ie in win2k and xp press alt-ctl-del and go to the processes. You can also use Spy++ ) Is your program listed? If so, then change your ShowCode to something like SW_SHOW. Good luck!
Brad
Brad
Casting COLOR_BACKGROUND to HBRUSH is correct, but you need to do (HBRUSH)(COLOR_BACKGROUND+1), I think. That will set the background color to COLOR_BACKGROUND. You can do that instead of creating a brush. Read the docs to make sure what I''ve said is correct.
Try this for window flags: WS_VISIBLE|WS_OVERLAPPEDWINDOW. If that works, then you''re probably passing an invalid combination of window flags, which seems to be my most common source of window creation failure.
Try this for window flags: WS_VISIBLE|WS_OVERLAPPEDWINDOW. If that works, then you''re probably passing an invalid combination of window flags, which seems to be my most common source of window creation failure.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement