Re: something about clipping in OnCustomdraw
On 12 Okt., 08:58, Joseph M. Newcomer <newco...@flounder.com> wrote:
On Fri, 10 Oct 2008 15:48:51 -0700 (PDT), Malachy Moses <malachy.mo...@gm=
ail.com> wrote:
On Oct 10, 10:40 am, ".rhavin grobert" <cl...@yahoo.de> wrote:
On 10 Okt., 18:16, ".rhavin grobert" <cl...@yahoo.de> wrote:
On 10 Okt., 18:02, ".rhavin grobert" <cl...@yahoo.de> wrote:
hi folks;-)
the following snipped comes from a customdraw-fn in a slider. As y=
ou
can see, i draw my own thumb and want to set some text in the cont=
rol:
____________________________________________________________
class SHTC_API CQSlider : public CSliderCtrl
{
public:
CQSlider();
virtual ~CQSlider();
// ... other stuff ... //
// set sliders text, may contain '%d' (or %x...) f=
or value
void QTitleSet(LPCTSTR szTitle);
protected:
//{{AFX_MSG(CQSlider)
afx_msg void OnCustomdraw(NMHDR* pNMHDR, LRESULT* =
pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
void _DrawThumb(NMCUSTOMDRAW& nmcd);
void _DrawText(NMCUSTOMDRAW& nmcd);
CString m_scTitle;
};
//----------------------------------------------------------------=
---------=AD----
void CQSlider::OnCustomdraw(NMHDR* pNMHDR, LRESULT* pResult)
{
NMCUSTOMDRAW nmcd = *(LPNMCUSTOMDRAW)pNMHDR;
switch (nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW |=
CDRF_NOTIFYPOSTPAINT;
break;
case CDDS_ITEMPREPAINT:
switch (nmcd.dwItemSpec)
{
case TBCD_TICS:
*pResult = CDRF_=
DODEFAULT;
break;
case TBCD_THUMB:
_DrawThumb(nmcd);
*pResult = CDRF_=
SKIPDEFAULT;
break;
case TBCD_CHANNEL:
*pResult = CDRF_=
DODEFAULT;
break;
}
break;
case CDDS_POSTPAINT:
_DrawText(nmcd);
break;
default:
*pResult = CDRF_DODEFAULT;
}
}
//----------------------------------------------------------------=
---------=AD----
void CQSlider::_DrawText(NMCUSTOMDRAW& nmcd)
{
CDC* pDC = CDC::FromHandle(nmcd.hdc);
CRect rcClient;
GetClientRect(&rcClient);
CString scText;
scText.Format(m_scTitle, GetPos());
pDC->SetBkMode(TRANSPARENT);
pDC->SelectClipRgn(NULL);
pDC->DrawText(scText, rcClient, DT_CENTER | DT_BOT=
TOM |
DT_SINGLELINE);
}
____________________________________________________________
the problem is: first time (initial, get focus), the text is drawn
correctly, but then, when moving the slider, everything except =
the
thumb gets clipped, so pDC->SelectClipRgn(NULL) seems to dont do
anything at all.
any suggestions welcome,
~.rhavin;)
oh and i should add that pDC->SelectClipRgn(NULL) returns SIMPLEREGI=
ON
but shouldnt it return NULLREGION !?
played with SetBoundsRect(), but that doesnt help either;-/- Hide quot=
ed text -
- Show quoted text -
I'm not certain that this will help, but I recommend two changes:
Surround your work with the DC with calls to SaveDC and RestoreDC, and
call CDC::Detach before exiting. So:
//----------------------------------------------------------------------=
---=AD----
void CQSlider::_DrawText(NMCUSTOMDRAW& nmcd)
{
CDC* pDC = CDC::FromHandle(nmcd.hdc);
int iSaveDC = pDC->SaveDC();
CRect rcClient;
GetClientRect(&rcClient);
CString scText;
scText.Format(m_scTitle, GetPos());
pDC->SetBkMode(TRANSPARENT);
pDC->SelectClipRgn(NULL);
pDC->DrawText(scText, rcClient, DT_CENTER | DT_BOTTOM |
DT_SINGLELINE);
pDC->RestoreDC( iSaveDC );
pDC->Detach();
}
The Detach is not required. There is no call on a destructor when a CDC*=
leaves scope.
joe
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm
....and the SaveDC()/RestoreDC() doesnt help either. So there is is
still the problem of clipping. *MAY* it be that the hdc i get in
NMCUSTOMDRAW is some kind of memory-dc and that my work is clipped
because just a certain part is bitblt'ed into screen? but that leaves
the question why a simple ::SelectClipRgn(nmcd.hdc, NULL) returns
SIMPLEREGION instead of the expected NULLREGION.
Any enlightenment highly appreciated,
~.rhavin;)