Thread: Button as a groupbox

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Button as a groupbox

    I'm using CreateWindowEx() to create a button as a groupbox.
    When the groupbox is created, i change the fontsize/face.
    The problem is that the original font displays behind the new font.
    What can i do to prevent this?

  2. #2
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    I am not really sure of what is happening, but you could try to force a repaint of the window you are changing. A button is just a window like any other, so you should be able to invalidate it.

  3. #3
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Did invalidating the window work, knutso? Sorry, I'm curious.

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    No, i tried that before i asked...
    I tried InvalidateRect(), but with the same result..
    Code:
    // Invalidate
    GetWindowRect(tp[FRM], &r1);
    InvalidateRect(tp[FRM], &r1, 1);
    // Create buttonframe
    HWND CreateFrame(HINSTANCE *pInst, HWND hWnd, char *achTxt, int x, int y, int w, int h, char chFontSz){
    	HWND hwBuf;
    	if((hwBuf=CreateWindowEx(0, "BUTTON", achTxt, WS_CHILD|BS_GROUPBOX, x, y, w, h, hWnd, 0, *pInst, 0))!=NULL){
    		SetFont(hwBuf, chFontSz, "Ms Sans Serif");
    		ShowWindow(hwBuf, SW_SHOW); 
    		return(hwBuf);
    	}else
    		return(0);
    }
    I'm handling the WM_CTLCOLORSTATIC message, but i do no painting.

  5. #5
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    I was about to tell you that you needn't call GetWindowRect(), as you can pass NULL (for pointer to RECT) to InvalidateRect() to invalidate the entire window, but this is not true. It just invalidates the entire client area. InvalidateRect() is only used for the purpose of invalidating the client area of windows, unless you pass NULL as the window handle, which invalidates all windows, and sends every window a WM_ERASEBKGND and WM_NCPAINT. Can you try doing that, instead? If the window refreshes itself properly, then you will know you just need to invalidate the non client area part of the window (even though InvalidateRect() is not the way to do this for a single window).

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Same result:
    InvalidateRect(0, 0, TRUE);

    I also tried to SW_HIDE/SW_SHOW the frames.
    It seems the control paints the original font, and then paints the new, smaller font on top..?

  7. #7
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Drag another window over top of it, and then move it out of the way. This way the OS is handling the painting of both the client and non-client areas. Let us know what happens.

  8. #8
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Give WS_CLIPCHILDREN & WS_CLIPSIBLINGS a try.

  9. #9
    Registered User
    Join Date
    Sep 2003
    Posts
    23
    Originally posted by knutso
    No, i tried that before i asked...
    I tried InvalidateRect(), but with the same result..
    Code:
    // Invalidate
    GetWindowRect(tp[FRM], &r1);
    InvalidateRect(tp[FRM], &r1, 1);
    I'm handling the WM_CTLCOLORSTATIC message, but i do no painting.
    None of variables has hwnd as part of it's name,
    but, I suppose tp[FRM] is of type HWND?

    What you are doing is Getting the Rect of a control,
    and invalidating that area within control. Maybe you
    should InvalidateRect on the parent window, like
    Code:
    GetWindowRect(tp[FRM], &r1);
    InvalidateRect(GetParent(tp[FRM]), NULL, 1);
    And for GetWindowRect MSDN sais:
    hWnd - in: Handle to the window.
    lpRect - out: Pointer to a RECT structure that receives the screen
    coordinates of the upper-left and lower-right corners of the window.
    So if you don't send NULL to InvalidateRect(), you
    should convert r1 from screen coordinates to client values
    with ScreenToClient()

    Delf

  10. #10
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    HWND tp[xx]; == Array with hWnd's to keep the tabposition
    I'll give ScreenToClient() a try, but i tried InvalidateRect(0, 0, 1) with the same result.
    I'll come back when i've tried ScreenToClient()..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-28-2008, 08:30 PM
  2. elliptical button
    By geek@02 in forum Windows Programming
    Replies: 0
    Last Post: 11-21-2006, 02:15 AM
  3. writing text over a deleted button
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-02-2005, 11:32 AM
  4. Window won't display on button command!?
    By psychopath in forum Windows Programming
    Replies: 6
    Last Post: 06-22-2004, 08:12 PM
  5. disabling button in another prog
    By timmygax in forum Windows Programming
    Replies: 11
    Last Post: 10-29-2001, 03:40 PM