Setfocus / killfocus on cbutton
Hi,
do you know how is it possible to change the focus from one button to
another button?
When I use the TAB control to go from one button to the next button,
the focus will be changed, so that the next button will get the focus.
Everything works correct.
But if I use the mouse to click on another button I also want to
acchieve this behaviour. At the moment the focus will stay on the last
button. Which message handler do I have to use to change the focus
using the mouse?
BEGIN_MESSAGE_MAP(CImageTextButton, CButton)
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)
ON_WM_KILLFOCUS()
ON_WM_SETFOCUS()
END_MESSAGE_MAP()
I`m not sure if kill focus and set focus will be the right place for
this? And furthermore which code I have to place in these handlers?
void CImageTextButton::OnSetFocus(CWnd* pOldWnd)
{
CButton::OnSetFocus(pOldWnd);
}
void CImageTextButton::OnKillFocus(CWnd * pNewWnd)
{
CButton::OnKillFocus(pNewWnd);
} // End of OnKillFocus
In my DrawItem method I will use a different image for the button, if
the button has the focus rectangle.
void CImageTextButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct )
{
CDC *pDC = CDC::FromHandle( lpDrawItemStruct->hDC );
// The color inside the HBITMAP that should be transparent
COLORREF cTransparentColor = RGB(0,0,0);
BOOL bIsFocused = (lpDrawItemStruct->itemState & ODS_FOCUS);
BOOL bIsDisabled = (lpDrawItemStruct->itemState & ODS_DISABLED);
HBITMAP m_Btn;
if(((bIsFocused) && (!bIsDisabled)))
m_Btn = m_btnFocus;
else if(bIsDisabled)
m_Btn = m_btnDis;
else
m_Btn = m_btnStandard;
//and so on
}
best regards
Hans