how to ownerdraw the button borders in VC++6.0 [modified]
-
I've overriden the funx CMyButton::DrawItem(), and some lines in it are:
CDC\* pDC = CDC::FromHandle( lpDrawItemStruct->hDC ); CRect rc = lpDrawItemStruct->rcItem; CPen pen( PS\_SOLID, 1, RGB(0,0,0) ); CPen \*pOld = pDC->SelectObject( &pen ); pDC->LineTo( rc.right, rc.top ); pDC->LineTo( rc.right, rc.bottom ); pDC->LineTo( rc.left, rc.bottom ); pDC->LineTo( rc.left, rc.top ); pDC->SelectObject( pOld );
But the prob occurs that only the upper and left borders drawn can be seen while the lower and right can't. At first, I thought it was caused by the 3D effect of the button. But though I've added BS_FLAT, the prob still exists. In fact, I can't use the following to draw the borders:
pDC->Rectangle( &rc );
Cos I want the button background to be transparent so that the back image of the dialog isn't covered. So anyone knows about this kinda prob and helps me out? Really thx!
modified on Tuesday, April 20, 2010 4:51 AM
-
I've overriden the funx CMyButton::DrawItem(), and some lines in it are:
CDC\* pDC = CDC::FromHandle( lpDrawItemStruct->hDC ); CRect rc = lpDrawItemStruct->rcItem; CPen pen( PS\_SOLID, 1, RGB(0,0,0) ); CPen \*pOld = pDC->SelectObject( &pen ); pDC->LineTo( rc.right, rc.top ); pDC->LineTo( rc.right, rc.bottom ); pDC->LineTo( rc.left, rc.bottom ); pDC->LineTo( rc.left, rc.top ); pDC->SelectObject( pOld );
But the prob occurs that only the upper and left borders drawn can be seen while the lower and right can't. At first, I thought it was caused by the 3D effect of the button. But though I've added BS_FLAT, the prob still exists. In fact, I can't use the following to draw the borders:
pDC->Rectangle( &rc );
Cos I want the button background to be transparent so that the back image of the dialog isn't covered. So anyone knows about this kinda prob and helps me out? Really thx!
modified on Tuesday, April 20, 2010 4:51 AM
1st I miss a
pDC->MoveTo( rc.left, rc.top );
for the starting point before the firstLineTo()
2nd Have you tried to changerc.bottom
andrc.right
? Decrement both should be enough to see the right and bottom lines. ThercItem
rectangle defines the controls boundaries, painting outside this boundaries is prohibited by clipping. -
1st I miss a
pDC->MoveTo( rc.left, rc.top );
for the starting point before the firstLineTo()
2nd Have you tried to changerc.bottom
andrc.right
? Decrement both should be enough to see the right and bottom lines. ThercItem
rectangle defines the controls boundaries, painting outside this boundaries is prohibited by clipping.