having problems making the window a diferent background colour

This is a discussion on having problems making the window a diferent background colour within the Windows Programming forums, part of the Platform Specific Boards category; why dosent this make g_hWnd2 black background ,, Code: #include <windows.h> #include "WM_CHARH.h" //#include "CreateWindowTwo.h" //#include "WndProcH.h" //Global Varibles HWND ...

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

    having problems making the window a diferent background colour

    why dosent this make g_hWnd2 black background ,,

    Code:
    #include <windows.h>
    #include "WM_CHARH.h"
    //#include "CreateWindowTwo.h"
    //#include "WndProcH.h"
    //Global Varibles
    HWND g_hWnd;
    HWND g_hWnd2;
    char *WinApp = "WinApp";
    char *WinApp2 = "WinApp2";
    WNDCLASSEX wc;
    WNDCLASSEX wc2;
    //Function Prototypes
    LRESULT WINAPI WndProc(HWND,UINT,WPARAM,LPARAM); //main windows function
    void RegisterWindowClass(HINSTANCE hInstance);
    void RegisterWindowClass2(HINSTANCE hInstance);
    void CreateAppWindow(HINSTANCE hInstance);
    void CreateAppWindow2(HINSTANCE hInstance);
    WPARAM StartMessageLoop();
    
    //Global Varibles
    //HWND g_hWnd;
    
    
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    
    	RegisterWindowClass(hInstance);
    	CreateAppWindow(hInstance);
    	RegisterWindowClass2(hInstance);
    	CreateAppWindow2(hInstance);
    	//ShowWindow(g_hWnd , SW_SHOWDEFAULT);
    	ShowWindow(g_hWnd , SW_NORMAL);
    	UpdateWindow(g_hWnd);
    	INT result = StartMessageLoop();
    	return result;
    }
    
    
    LRESULT CALLBACK WndProc(HWND hWnd  ,UINT msg , WPARAM wParam , LPARAM lParam)
    {
    	
    	switch(msg)
    	{
    	case WM_CREATE:
    		return 0;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		break;
    
    	case WM_PAINT:
    		ValidateRect(g_hWnd, NULL);
    		return 0;
     
    	case WM_COMMAND:
            break;
    
    	case WM_KEYDOWN: break;
              
    
        case WM_CHAR: 
    		 WM_CHARH(wParam , g_hWnd , g_hWnd2); break;
    
    			
    
    	 
    	
    	
    	}
    
    	return DefWindowProc(hWnd , msg , wParam , lParam);
    	
    }
    
    //RegisterWindow 1
    void RegisterWindowClass(HINSTANCE hInstance)
    {
    
    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); //Mouse Cursor 
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //background window colour
    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, 
    					 //NULL,
    					 100, 
    					 100,
    					 648,
    					 514,
    					 GetDesktopWindow(),
    					 NULL,
    					 hInstance,
    					 NULL
    					 );
    }
    
    //RegisterWindow 2
    void RegisterWindowClass2(HINSTANCE hInstance)
    {
    wc2.cbSize = sizeof(WNDCLASSEX);
    wc2.style = CS_HREDRAW; /*| CS_VREDRAW | CS_OWNDC;*/
    wc2.lpfnWndProc = WndProc;
    wc2.cbClsExtra = 0;
    wc2.cbWndExtra = 0;
    wc2.hInstance = hInstance;
    wc2.hIcon = LoadIcon(NULL , IDI_INFORMATION); 
    wc2.hCursor = (HCURSOR)LoadCursor(NULL , IDC_ARROW); //Mouse Cursor 
    //wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH+21); //background window colour
    wc2.hbrBackground = (HBRUSH)(GetStockObject(BLACK_BRUSH+1));
    wc2.lpszMenuName = "new";
    wc2.lpszClassName = WinApp2;
    wc2.hIconSm = NULL;
    
    RegisterClassEx(&wc2);
    }
    
    void CreateAppWindow2(HINSTANCE hInstance)
    {
    
    g_hWnd2 = CreateWindowEx(
    					 NULL, 
    					 WinApp2,
    					 "Basic Windows Application",
                         WS_OVERLAPPEDWINDOW | WS_CHILD,
    					 1, 
    					 1,
    					 500,
    					 200,
    					 g_hWnd,
    					 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
    	{
    	//	UpdateWindow(g_hWnd);
    	//	UpdateWindow(g_hWnd2);
          //use idle time here
    	}
    }
    
    return msg.wParam;
    }

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    The call to RegisterClassEx is failing for both windows because of this:

    Code:
    char *WinApp = "WinApp";
    char *WinApp2 = "WinApp2";
    Change it to:
    Code:
    const char WinApp[] = "WinApp";
    const char WinApp2[] = "WinApp2";
    Also, BLACK_BRUSH+1 should be BLACK_BRUSH

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    wc2.hbrBackground = (HBRUSH)(GetStockObject(BLACK_BRUSH+1));
    You shouldn't add 1 (+1) when using GetStockObject. This is only required when using one of the COLOR_ constants directly. You have it correct for the first window.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    316
    ok thanks for the advice

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  2. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. Problems with standard WIN32 Code
    By BruceLeroy in forum Windows Programming
    Replies: 6
    Last Post: 08-24-2004, 09:20 AM
  5. Problem with creating new window, from another window
    By Garfield in forum Windows Programming
    Replies: 6
    Last Post: 01-11-2004, 01:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21