[mfc, custom control] Default Button
-
Hi. I got my own custom button where i am doing all the painting myself. And now there is a problem: default button behavior. You know, like, these fancy regular windows buttons - when you click inside some Edit Box (let it be anywhere on the main app window) - button is drawn with blue shinning color. When you click on another button - that another button becomes default one. When you click inside some other edit box, again - this first button is drawn with a blue shinning color. The thing is : it is not an issue to check the style with:
if( GetStyle() & BS_DEFPUSHBUTTON ) then...
and do some additional drawing. The problem is: how to catch when a user clicked somewhere on another control which is not mine, which is regular windows edit box for example. Or another button which is just windows regular button? How do my button know when to draw some additional stuff to indicate it is a default button? Thanks
011011010110000101100011011010000110100101101110 0110010101110011
-
Hi. I got my own custom button where i am doing all the painting myself. And now there is a problem: default button behavior. You know, like, these fancy regular windows buttons - when you click inside some Edit Box (let it be anywhere on the main app window) - button is drawn with blue shinning color. When you click on another button - that another button becomes default one. When you click inside some other edit box, again - this first button is drawn with a blue shinning color. The thing is : it is not an issue to check the style with:
if( GetStyle() & BS_DEFPUSHBUTTON ) then...
and do some additional drawing. The problem is: how to catch when a user clicked somewhere on another control which is not mine, which is regular windows edit box for example. Or another button which is just windows regular button? How do my button know when to draw some additional stuff to indicate it is a default button? Thanks
011011010110000101100011011010000110100101101110 0110010101110011
MSDN - Implement an NM_CUSTOMDRAW message handler
void CMyCustomDrawControl::OnCustomDraw(NMHDR* pNMHDR,
LRESULT* pResult)
{
LPNMCUSTOMDRAW pNMCD = reinterpret_cast(pNMHDR);
...
} -
MSDN - Implement an NM_CUSTOMDRAW message handler
void CMyCustomDrawControl::OnCustomDraw(NMHDR* pNMHDR,
LRESULT* pResult)
{
LPNMCUSTOMDRAW pNMCD = reinterpret_cast(pNMHDR);
...
} -
Hi. I got my own custom button where i am doing all the painting myself. And now there is a problem: default button behavior. You know, like, these fancy regular windows buttons - when you click inside some Edit Box (let it be anywhere on the main app window) - button is drawn with blue shinning color. When you click on another button - that another button becomes default one. When you click inside some other edit box, again - this first button is drawn with a blue shinning color. The thing is : it is not an issue to check the style with:
if( GetStyle() & BS_DEFPUSHBUTTON ) then...
and do some additional drawing. The problem is: how to catch when a user clicked somewhere on another control which is not mine, which is regular windows edit box for example. Or another button which is just windows regular button? How do my button know when to draw some additional stuff to indicate it is a default button? Thanks
011011010110000101100011011010000110100101101110 0110010101110011
I think your button needs to handle the
WM_KILLFOCUS
[^] message.Unrequited desire is character building. OriginalGriff
-
I think your button needs to handle the
WM_KILLFOCUS
[^] message.Unrequited desire is character building. OriginalGriff
It handles. But i need to catch somehow messages from other controls. Currently i am handling WM_MOUSEACTIVATE on a dialog window (this msg is posted when non-focused control gets focus, so basically when you click on any control on a dialog window , this dialog window gets this message) and then posting some dummy message to all child controls to make my controls redraw them selfs. But. There is one BUT. This message is posted before last control loses focus or something like that, anyways, only after second message my controls redraw them selfs correctly, so its like, "there is one click delay" - unacceptable in my case :(. So there should be some better way i dont know about
011011010110000101100011011010000110100101101110 0110010101110011
-
Hi. I got my own custom button where i am doing all the painting myself. And now there is a problem: default button behavior. You know, like, these fancy regular windows buttons - when you click inside some Edit Box (let it be anywhere on the main app window) - button is drawn with blue shinning color. When you click on another button - that another button becomes default one. When you click inside some other edit box, again - this first button is drawn with a blue shinning color. The thing is : it is not an issue to check the style with:
if( GetStyle() & BS_DEFPUSHBUTTON ) then...
and do some additional drawing. The problem is: how to catch when a user clicked somewhere on another control which is not mine, which is regular windows edit box for example. Or another button which is just windows regular button? How do my button know when to draw some additional stuff to indicate it is a default button? Thanks
011011010110000101100011011010000110100101101110 0110010101110011
You need to several things: 1. Override CWnd::OnGetDlgCode[^] and specify that your control accepts becoming a default push button (
DLGC_DEFPUSHBUTTON
). 2. Handle the BM_SETSTYLE[^] message in your button class, so that you are informed when windows set and removes theBS_DEFPUSHBUTTON
style for your button and paint the button accordingly.0100000101101110011001000111001011101001
-
You need to several things: 1. Override CWnd::OnGetDlgCode[^] and specify that your control accepts becoming a default push button (
DLGC_DEFPUSHBUTTON
). 2. Handle the BM_SETSTYLE[^] message in your button class, so that you are informed when windows set and removes theBS_DEFPUSHBUTTON
style for your button and paint the button accordingly.0100000101101110011001000111001011101001
-
Glad I could help.
0100000101101110011001000111001011101001