🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Why won't the window display?

Started by
3 comments, last by Wild9eR 24 years, 6 months ago
Nevermind I figured it out, no msg system or event handler...
Job description : Duct Tape
Advertisement
The biggest reason is because you have no message loop. The program creates the window and then quits. You need to pass messages from WinMain() to the WinProc() through the message loop. this is usually(except for games ) a while loop like:

while(GetMessage()){    TranslateMessage();    DispatchMessage();}

That's just some quicky psuedocode so check the documentation.

Also, why did you comment out ShowWindow() and UpdateWindow()?

And, you should at least call DefWindowProc() in the WinProc procedure. This handles messages you don't.

And you can probably leave out main_window_handle and just use your hwnd var wherever you use it.

Good Luck

-the logistical one-http://members.bellatlantic.net/~olsongt
I hate it when that happens while I'm typing.


Oh well. Ignore the previous post

-the logistical one-http://members.bellatlantic.net/~olsongt
Hi, below is some source code in c++.
All I am doing is createing a basic window class, registering it and trying to display it. I get no complie errors, but when I run the .exe nothing happens...Why not, what am I missing?

-----------------------------------
//includes and defines
#define WIN32_LEAN_AND_MEAN
#include
#include


//windproc function
LRESULT CALLBACK WindowProc(HWND hwnd, //the window
UINT msg, //the message itself
WPARAM wParam,
LPARAM lParam)
{
return 0;
}

//winmain entry point
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpCmdLine,
int nShowCmd)
{

//declaration of window class
WNDCLASS wndclass;
HWND hwnd;
wndclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WindowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hinstance; //from winmain
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "WINCLASS1";

//register wndclass
if (RegisterClass(&wndclass)==0)
{
//error
}


//create windows
HWND main_window_handle = NULL;
main_window_handle = CreateWindow("WINCLASS1",
"Blind Try",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100, 100,
320, 200,
NULL,
NULL,
hinstance,
NULL);

hwnd = main_window_handle;

//show window
//ShowWindow(main_window_handle, SW_SHOW);
//UpdateWindow(main_window_handle);
return 0;

}

---------------------------------------

Job description : Duct Tape
The BIGGEST problem IS the message loop, but still the window will not display if you dont process the WM_PAINT message. Look it up in Petzold. (or MSDN / LaMothe).

-Erik L. Elmore

-Erik L. Elmore

This topic is closed to new replies.

Advertisement