|
|
Comments and Discussions
|
|
 |

|
Hi CodeProject,
I tried to print your sample control from Internet Explorer 5.0. The result I got was incorrect. Basically, I saw Two rectangles (one inside the other) lined up as follows (dots represent whitespace):
+-----------------+
|a................|
|..+--------------+
|..|..............|
|..|..............|
|..|..............|
+--+--------------+
The char "a" represents the content of the tree control. It was printed at about 2 point font
|
|
|
|
|
|
|

|
Hi there.
I got the same problem, but the fix appears to be pretty simple :
HRESULT CDesignTimePaintingObj::OnDraw(ATL_DRAWINFO& di)
{
RECT& rc = *(RECT*)di.prcBounds;
// we are drawn throug IViewObject?
if(m_hWnd == 0)
{
// was there a resize since the last painting?
SIZE newSize = {abs(rc.right - rc.left), abs(rc.bottom - rc.top)};
if((newSize.cx != m_sizeBmp.cx) || (newSize.cy != m_sizeBmp.cy))
{
m_bRecreateBitmap = true;
}
// should we recreate the Bitmap?
if(m_bRecreateBitmap == true)
{
// First, create the Windows, so that they can draw themselves
CreateChildWindows(0);
if(m_hBmp != NULL)
{
::DeleteObject(m_hBmp);
m_hBmp = NULL;
}
m_bRecreateBitmap = false;
m_sizeBmp.cx = newSize.cx;
m_sizeBmp.cy = newSize.cy;
// Create the Bitmap
m_hBmp = ::CreateCompatibleBitmap(di.hdcDraw, m_sizeBmp.cx, m_sizeBmp.cy);
if(m_hBmp == NULL)
{
m_bRecreateBitmap = true;
return S_OK;
}
POINT pt;
POINT poiOffset;
// prepare painting the NonClientArea of the TreeView
poiOffset.x = ::GetSystemMetrics(SM_CXEDGE) + 1;
poiOffset.y = ::GetSystemMetrics(SM_CYEDGE) + 1;
// Select the Bitmap as a drawing >Context
HDC hBmpDC = ::CreateCompatibleDC(di.hdcDraw);
HBITMAP hOldBmp = (HBITMAP) ::SelectObject(hBmpDC, m_hBmp);
// Position the Windows in the Hidden one
m_wndTree.SetWindowPos(HWND_TOP, &rc, SWP_NOZORDER);
::SetViewportOrgEx(hBmpDC, poiOffset.x, poiOffset.y, &pt);
// force The temporary Window to Draw itself and copy it into the Bitmap
m_wndTree.SendMessage(WM_PAINT, (WPARAM)hBmpDC, 0);
::SetViewportOrgEx(hBmpDC, pt.x, pt.y, NULL);
===>comment this out //::DrawEdge(hBmpDC, &rc, EDGE_BUMP, BF_RECT);
::SelectObject(hBmpDC, hOldBmp);
::DeleteDC(hBmpDC);
}
// Copy the Bitmap to the Container
HDC hBmpDC = ::CreateCompatibleDC(di.hdcDraw);
HBITMAP hOldBmp = (HBITMAP) ::SelectObject(hBmpDC, m_hBmp);
::BitBlt(di.hdcDraw, rc.left, rc.top, m_sizeBmp.cx, m_sizeBmp.cy, hBmpDC, 0, 0, SRCCOPY);
::SelectObject(hBmpDC, hOldBmp);
::DeleteDC(hBmpDC);
}
return S_OK;
}
|
|
|
|

|
Hi,
this line is needed in some contaioners we use! e.g. in an MFC - Dialog or in Containers, that are written by us.
I never tried the control in IE, sorry.
Gerolf
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
An article that discusses drawing a control at designtime
| Type | Article |
| Licence | CPOL |
| First Posted | 30 Nov 1999 |
| Views | 92,543 |
| Downloads | 1,804 |
| Bookmarked | 57 times |
|
|