Click to See Complete Forum and Search --> : Drawing in a dialog box


Philippe
June 18th, 1999, 05:16 AM
Hi everybody,

New problem today for me. I've created a dialog box and I would like to create a true or virtual area in
which one I want to draw (lines, texts and so on).

Is there any control (standard in VC or extended by another firm) which can make this ?
If not, how can I draw in a dialog box ? I have tried to put my own draw code before and after the CDialog:OnPaint() function, but in all cases, my own drawn objects appear and disappear.

Thanks.

olivier
June 18th, 1999, 05:29 AM
- First Create a Class CMyCtrl which inherates from CWnd, and draw whatever you want in the OnPaint Method
the Create method should be like this :

BOOL CGraphCtrl::Create(DWORD dwStyle, const RECT& rect,
CWnd* pParentWnd, UINT nID)
{
BOOL result;
static CString className = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW);

result = CWnd::CreateEx(WS_EX_CLIENTEDGE | WS_EX_STATICEDGE,
className, NULL, dwStyle,
rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
pParentWnd->GetSafeHwnd(), (HMENU)nID);
return result;
}
[/ccode ]


Then in your ressource dialog box add a Picture control (IDC_MY_CONTROL)
Add CMyCtrl m_MyCtrl in the .h of your dialog box class
then on your InitDialog method do something like :

[ccode]
CRect rect;
GetDlgItem((IDC_MY_CONTROL))->GetWindowRect(rect) ;
ScreenToClient(rect) ;
// create the control
m_MyCtrl.Create(WS_VISIBLE | WS_CHILD, rect, this) ;