Thread: the window dosent get showed....

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    319

    the window dosent get showed....

    Code:
    it compiles fine , it just dosent get displayed does anyone know why?
    #include <windows.h>
    
    //Function prototypes...
    
    LRESULT WINAPI WndProc(HWND Hwnd, UINT msg, WPARAM wParam , LPARAM lParam);
    void RegisterWindowClass(HINSTANCE hInstance);
    void CreateAppWindow(HINSTANCE hINstance);
    WPARAM StartMessageLoop();
    
    //Global
    HWND g_hWnd;
    
    INT WINAPI WinMain(HINSTANCE hInstance , HINSTANCE , LPSTR , INT)
    {
    	RegisterWindowClass(hInstance);
    	CreateAppWindow(hInstance);
    	ShowWindow(g_hWnd, SW_MAXIMIZE);
    	UpdateWindow(g_hWnd);
    	INT result = StartMessageLoop();
    	return result;
    } 
    
    //WndProc
    
    LRESULT WINAPI WndProc(HWND hWnd, UINT msg , WPARAM wParam , LPARAM lParam)
    {
    	switch(msg) 
    	{
    	case WM_CREATE:
    		return 0;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    	case WM_PAINT:
    		ValidateRect(g_hWnd , NULL);
    		return 0;
    	}
    	return DefWindowProc(g_hWnd , msg , wParam , lParam);
    }
    
    void RegisterWindowClass(HINSTANCE hInstance)
    {
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra =0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = (HCURSOR)LoadCursor(NULL , IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "WinApp";
    wc.hIconSm = NULL;
    
    RegisterClassEx(&wc);
    }
    
    
    void CreateAppWindow(HINSTANCE hInstance)
    {
    g_hWnd =  CreateWindowEx(
    					NULL,
    					"WinApp",
    					"Basic Windows Application",
    					WS_OVERLAPPEDWINDOW,
    					100,
    					100,
    					648,
    					514,
    					GetDesktopWindow(),
    					NULL,
    					hInstance,
    					NULL);
    }
    
    WPARAM StartMessageLoop()
    {
    	MSG msg;
    	while(1)
    	{
    		if(PeekMessage(&msg , NULL , 0 , 0 , PM_REMOVE))
    		{
    			if(msg.message == WM_QUIT)
    			break;
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    
    		}
    		else
    		{
    			//use for idle
    		}
    	}
    	return msg.wParam;
    }

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    LRESULT WINAPI WndProc(HWND hWnd, UINT msg , WPARAM wParam , LPARAM lParam)
    {
    	switch(msg) 
    	{
    	case WM_CREATE:
    		return 0;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    	case WM_PAINT:
    		ValidateRect(g_hWnd , NULL);
    		return 0;
    	}
    	return DefWindowProc(g_hWnd , msg , wParam , lParam);
    }
    Use hWnd instead of g_hWnd.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    thanks alot , fixed now

Popular pages Recent additions subscribe to a feed

Similar Threads

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