• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 626
  • Last Modified:

Button borders not disappearing correctly

I have placed two CButtons on a CStatic dynamically (i.e. I call CButton()->Create( CStatic as parent );

The buttons display fine, but when tabbing around them (changing focus), the default (black) border does not disappear.  It looks as though all the buttons on the window are the default and this is not the case (actually none of them are).

I have found a workaround, but still not sure why this works and if it is a good workaround.  If I override the CButton::OnKillFocus() and call SetButtonStyle(BS_PUSHBUTTON); (before the CWnd::OnKillFocus()), everything works fine.

Why? and is this a fix?
0
tdietz
Asked:
tdietz
  • 2
1 Solution
 
mikeblasCommented:
Are you sure the buttons aren't being given the default button style? Have you checked with Spy++?  Are you responding to WM_GETDLGCODE?

Windows doesn't slap the style on randomly selected buttons.

.B ekiM

0
 
tdietzAuthor Commented:
I don't think they are being given the default style.  I am not doing it.  The buttons are the children of a CStatic and not a CDialog.  Does a CDialog implement extra functionality to remove the dark border when focus changes?

0
 
speedupCommented:
First you should check its style. Are you sure it's DEFAULT button?
Secondly, do you use owner draw function?


0
 
tdietzAuthor Commented:
I guess I am not making it completely clear, so do this simple test:

Create a dialog with a group box on it.
From the Dialog's OnInitDialog, create several pushbuttons (by hand):

m_button1.Create(...., groupBoxHwnd);
m_button2.Create(...., groupBoxHwnd);

make sure you make the groupBox the button's parent.
Do not set any default buttons for any button on the screen (get rid of the OK & CANCEL buttons generated for you already).

When the dialog opens, you will see your buttons and the groupbox, now set focus to one of the buttons and move to the other.  You will notice that the button's border (for the one you were tabbing off of) does not change, it still shows as bold (the focus rect has moved to the second button, but the bold border is on both).

This is a real easy test and can be reproduced under MSVC 5.0 (sp3).

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now