CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2003
    Posts
    260

    Tabbing problem with transparent CButton

    Hello Everyone,

    This should probably be a quick solution - please help me.

    I have successfully gotten transparent background for my CButton class with either
    1) return 1 in OnEraseBackground()
    2)
    Code:
     
    filtering out CButton in OnCtlColor
    	else if (nCtlColor == CTLCOLOR_BTN)
    	{
    		HBRUSH hbr = (HBRUSH)GetStockObject( HOLLOW_BRUSH );
    		pDC->SetBkMode( TRANSPARENT );
    		return hbr;
    	}
    That is all good until I realized that the tabbing is screwed with the transparent background of mine.

    Normally with 2 buttons, it should toggle between the two with the combinations of:
    10 (button1 on focus, button 2 is not)
    01 (button1 not focus, button 2 is )


    However, now it becomes the following, in another word, there are 2 extra combinations, and I know SetFocus is tabbed to the right button since it invokes the right actions, but the button is just not drawn correctly.

    00 (both are not on focus) -> extra !!
    10 (button1 on focus, button 2 is not)
    11 (both buttons on focus) -> extra
    01 (button1 not focus, button 2 is )

    I need the transparent background since it is gradient. I have tried the following code and the combination is right:
    Code:
     
    void CColorButton::DrawFilledRect(CDC *DC, CRect R)
    { 
    	CBrush B;
    	B.CreateSolidBrush(RGB(250,250,250));
    	DC->FillRect(R, &B);
    }
    Why is there 2 extra combinations and how does the window clear and re-draw the background after 4 cycles. I would imagine that it wouldn't. Clearly I am clueless.

    Thank you,

    Jiac

  2. #2
    Join Date
    Jul 2003
    Posts
    260

    Re: Tabbing problem with transparent CButton

    This may not have a quick solution? But still please give me some pointers. I don't understand why after the 4th cycle the window gets repainted.

    Help...

  3. #3
    Join Date
    Jul 2005
    Posts
    767

    Re: Tabbing problem with transparent CButton

    I am sorry I do not understand your problem. Also where are the two buttons?? and what are the 4 combinations??

  4. #4
    Join Date
    Jul 2003
    Posts
    260

    Re: Tabbing problem with transparent CButton

    Hello Mr. Beans and everyone,

    Thank you for your reply, sorry that I haven't had a chance to post what I meant.
    Please see the attached exe for what I meant and the source files to test it out.

    Thank you,
    Jiac
    Attached Files Attached Files

  5. #5
    Join Date
    Jul 2005
    Posts
    767

    Re: Tabbing problem with transparent CButton

    I think you trying owner drawn/fancy buttons, if so you can check this and this.

  6. #6
    Join Date
    Jul 2003
    Posts
    260

    Re: Tabbing problem with transparent CButton

    Yes, I want to do owner draw, but since the background dialog contains a bitmap, I want a transparent button, so the button is not going to be fancy but just owner draw.

    The article on CButtonST v3.9 (MFC Flat buttons) is more suitable to my need since it is also transparent; howerver, it doesn't address tabbing, or I can't tab into it.

    Please help,

    Jiac

  7. #7
    Join Date
    Apr 1999
    Posts
    3,585

    Re: Tabbing problem with transparent CButton

    From MSDN: DrawFocusRect()...

    Since this is a Boolean XOR function, calling this function a second time with the same rectangle removes the rectangle from the display.
    You must call this method to draw and remove the focus rect each time the focus changes. You are not calling this method for the previous focus rect.
    Gort...Klaatu, Barada Nikto!

  8. #8
    Join Date
    Jul 2003
    Posts
    260

    Re: Tabbing problem with transparent CButton

    Thank you for getting back.
    How should I do that to draw the rect twice? I have tried to put that

    "DrawFocusRect(lpDIS->hDC, (LPRECT)&focusRect);"

    in DrawItem() but it is not working. Please tell me more specific.

    In addition, I have looked into the link you sent about the flat buttons, this clears the background by including PaintBk(), as a different approach, I thought I'd let you know.


    PS: Do you happen to know, or someone, how to bypass the black background checkbox seen when using XP theme background with setting the background to transparent?

    A big thank you for your help.
    Jiac

  9. #9
    Join Date
    Jul 2003
    Posts
    260

    Re: Tabbing problem with transparent CButton

    PS: For the checkbox being black, there are 2 solutions, one is bitblt and another is to call EnableThemeDialogTexture. I tried the first one and it works.

    Thank you and until next time.

    Jiac

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured