button won`t be redrawn after invalidate()
Hi,
I`ve one image-button installed on my dialog, when you press the
button another dialog will popup beside the button, so that the button
is always visible. Within the popup dialog you can enter an code by
four editfields and press apply.
If you press apply I`ll that the image-button will be changed, it the
user press cancel on the popup dialog, the image should not be
changed.
void ButtonpressHandler()
{
CPwdDialog dlg;
//set some information to the dialog
INT_PTR rtnvalue = dlg.DoModal();
switch(rtnvalue)
{
case APPLY_BTN:
m_BtnLock.SetImage(APPLY_IMAGE);
break;
case CANCEL_BTN:
m_BtnLock.SetImage(CANCEL_IMAGE);
break;
}
}
m_BtnLock is the member variable of the image-button. Within the
SetImage method I changed the HBITMAP image to the specific source.
Both of them are loaded at startup. And after that I call Invalidate()
but the button will not be drawn again.... If I click the button
again, the image will be changed.
void CImageTextButton::SetImage(UINT id)
{
if(m_btnImages.GetSize() < id)
{ /* false */
ASSERT(false);
return;
}
m_btnStandard = (HBITMAP) m_btnImages.GetAt(id);
Invalidate();
}
m_btnImages is an CWordArray holding all possible images for this
button and m_btnStandard will be the button image which will be
shown.
This is my draw method
void CImageTextButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct )
{
CDC *pDC = CDC::FromHandle( lpDrawItemStruct->hDC );
//determine button state
BOOL bIsFocused = (lpDrawItemStruct->itemState & ODS_FOCUS);
BOOL bIsDisabled = (lpDrawItemStruct->itemState & ODS_DISABLED);
/* ************ draw button image ************************* */
HBITMAP bBtn;
if(((m_bIsHovering) && (!bIsDisabled)) || (bIsFocused))
bBtn = m_btnHover;
else if(bIsDisabled)
bBtn = m_btnDis;
else
bBtn = m_btnStandard;
/* if the button didn`t have an hover image / disable image -> do not
draw the button again */
if(bBtn == NULL)
return; //bBtn = m_btnStandard;
/*
this specific button has no hover as well as disabled image....
*/
DrawTransparentBitmap(pDC->m_hDC, bBtn, 0, 0,
m_TransparentImageColor);
/* ************* draw button`s text ************************* */
//wenn button disabled gezeichnet werden soll
if(bIsDisabled)
pDC->SetTextColor(m_TextColorDisabled);
else
pDC->SetTextColor(m_TextColorEnabled);
CString sTitle;
GetWindowText(sTitle);
CRect rpCaption = lpDrawItemStruct->rcItem;
CRect centerRect = rpCaption;
pDC->SetBkMode(TRANSPARENT);
pDC->DrawText(sTitle, -1, rpCaption, DT_WORDBREAK | DT_CENTER |
DT_CALCRECT);
rpCaption.OffsetRect((centerRect.Width() - rpCaption.Width())/2,
(centerRect.Height() - rpCaption.Height())/2);
pDC->DrawText(sTitle, -1, rpCaption, DT_WORDBREAK | DT_CENTER);
}
best regards
Hans