Thread: setting the background of a child window

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

    setting the background of a child window

    ive got a child window and i dont know how to make it a diferent background from the main parent window ,
    ive tried to register another class with a diferent background colour but not sure how to make it work

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    MDI? One solution is OnDraw().

    Kuphryn

  3. #3
    Registered User
    Join Date
    Jun 2005
    Location
    Sarajevo, Bosnia and Herzegovina
    Posts
    18
    WM_CTLCOLOR funcionis just add EDIT, STATIC etc.
    Example WM_CTLCOLOREDIT for changing edit control color and use a GetBkColor();

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    where does it go in this

    Code:
    	HWND hEdit2;
            hEdit2 = CreateWindowEx(WS_EX_WINDOWEDGE, //style type
    			                    "EDIT", //class type
    								"", //what apears in the window
    								WS_CHILD | WS_VISIBLE | WS_BORDER,
    								0, //across 
    								50, //down
    								300, //thinness 
    								350, // height
    								hwnd, 
    								NULL, 
    								GetModuleHandle(NULL), 
    		                        NULL
    								);

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    as Sucur says, just check the WM_CTLCOLOREDIT message of the procedure; that message means that a control is being drawn, with the default pen, color, etc... the important procedure values received are the UNIT (color edit event) and the LPARAM (display context). now you can modify the display context (HDC) with the usual functions for that (SetTextColor, etc...). for the bk color you should exit from the 'event' returning an HBRUSH that will be the bk color of the control, for the text color/bkmode/etc yoou can use the 'normal' funcions provided for that.
    hey, remember to not paint the background color as the text color

    niara

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    care todo a example as i am confuzzed
    and how to i set it so the window will open in full screen mode

  7. #7
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    I think that the fullscreen mode won't change the way of do it; on the message evaluation of the window procedure, just check for the WM_CTLCOLOREDIT, as you chek for the WM_PAINT, or other WM_ message; when you are in it, simply play with the options.
    to work with your code, set a HMENU value, and also set the window instance; something like:
    Code:
    //before any code
    #define HEDIT2 10
    
    //window procedure or dialog procedure, don't mind because the params are the same
    functionProcedure(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
    switch(msg)
        {
        case WM_CREATE://use that if is a window procedure
        case WM_INITDIALOG://use that other if is a dialog procedure
            {
    	HWND hEdit2;
    	hEdit2=CreateWindowEx(0,"EDIT","Text",WS_CHILD|WS_VISIBLE|WS_BORDER,0,50,300,350,hwnd,
    		     (HMENU)HEDIT2,
    		     (HINSTANCE)hInstance,
    		     NULL);
    	}
        break;
        case WM_CTLCOLOREDIT:
            {
    	if((HWND)lParam==GetDlgItem(hwnd,HEDIT2))
        	    {
    	    SetTextColor((HDC)wParam,RGB(0,0,255));
    	    return (int)(HBRUSH)CreateSolidBrush(RGB(255,0,0));
    	    }
    	}
        break;
        }
    }
    HEDIT2 is the edit identifyer, is a simple number. on the WM_CTLCOLOREDIT you can select the control that will be paint: with that message the lParam of the finction is the handler of the control that is being painted, in that case you can't compare directly with 'hEdit2' because isn't a global static variable (you can do it as well declaring at the top of the code -after the windows header, of course-). the other code is simple: the wParam of the function is the HDC where the control will be drawn, so you can interact with it to set the text color and other things; finally you should end the WM_CTLCOLOREDIT case returning the bakground color of the edit control in form of HBRUSH, so create a new hbrush and return it or return the creation of a new hbrush, or create a global hbrush and use it as return value, or etc... (thousands combinations).

    niara

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>how to i set it so the window will open in full screen mode<<

    For a top-level window create your window with only the WS_POPUP window style, with no border-changing extended styles. To get the screen size use GetSystemMetrics, once for width(SM_CXSCREEN) and again for height(SM_CYSCREEN). For a child window, just make sure it has no borders (no extended styles should just about do it) and resize it to fit the parent's client area (since it should cover the screen if the child window is intended to do so). You can resize it within the parent's WM_SIZE handler - search the board if you need further examples as there have been many.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

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. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  3. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  4. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM
  5. Winamp Vis if anyone can help
    By Unregistered in forum Windows Programming
    Replies: 6
    Last Post: 01-27-2002, 12:43 AM