CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    7

    Drawing in a dialog box

    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.


  2. #2
    Join Date
    May 1999
    Location
    Paris, France
    Posts
    216

    Re: Drawing in a dialog box

    - 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) ;





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured