Thread: Window not actually showing.

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968

    Window not actually showing.

    Okay, I just walked myself through a tut and I got the code down line by line. Actually wrote it out, and I'm pretty sure I understand everything that is going on at this point, but the thing is the window never actually shows!

    Code:
    #include <windows.h>
    
    const char ClassName[] = "myWindowClass";
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(msg)
    	{
    	case WM_CLOSE:
    		DestroyWindow(hWnd);
    		break;
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		break;
    	default:
    		return DefWindowProc(hWnd, msg, wParam, lParam);
    	}
    	return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    				   char* lpCmdLine, int nCmdShow)
    {
    	WNDCLASSEX wc;
    	HWND hWnd;
    	MSG Msg;
    
    	// Register the class!
    
    	wc.cbSize = sizeof(WNDCLASSEX);
    	wc.style = 0;
    	wc.lpfnWndProc = WndProc;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hInstance = hInstance;
    	wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
    	wc.hCursor = LoadCursor(hInstance, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = ClassName;
    	wc.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
    
    	if(!RegisterClassEx(&wc))
    	{
    		MessageBox(NULL, "Window Registration Failed!", "Error!",
    			MB_ICONEXCLAMATION | MB_OK);
    		return 0;
    	}
    
    	// Create the window!
    
    	hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, ClassName, "Window Title",
    		WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,240,120,
    		NULL, NULL, hInstance, NULL);
    	if(hWnd = NULL)
    	{
    		MessageBox(NULL, "Window Creation Failed!", "Error!",
    			MB_ICONEXCLAMATION | MB_OK);
    	}
    
    	ShowWindow(hWnd, nCmdShow);
    	UpdateWindow(hWnd);
    
    	// Start the message loop
    
    	while(GetMessage(&Msg, hWnd, 0, 0) > 0)
    	{
    		TranslateMessage(&Msg);
    		DispatchMessage(&Msg);
    	}
    	return Msg.wParam;
    
    }
    Am I doing something wrong?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    Code:
    if(hWnd = NULL)
    	{
    		MessageBox(NULL, "Window Creation Failed!", "Error!",
    	        MB_ICONEXCLAMATION | MB_OK);
    	}
    The above should be if( hWnd == NULL )

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I guess that explains why it isn't showing. Turn up your warnings!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    haha, thank you!
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM