CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    82

    drawing in the dialog

    I am trying to draw something in a modeless dialog in some where other than OnPaint member function. I used a bitmap to save the drawing and show it in OnPaint. like this

    void CMyDialog::OnPaint()
    {
    CPaintDC dc(this); // device context for painting
    CDC MemDC;
    MemDC.CreateCompatibleDC(&dc);
    MemDC.TextOut(10, 10, "text 1");
    CBitmap* pOldBmp = MemDC.SelectObject(&m_Bmp);
    dc.BitBlt(0, 0, 100, 100, &MemDC, 0, 0, SRCCOPY);
    MemDC.SelectObject(pOldBmp);
    }

    and did some drawing in another function

    void CMyDialog:raw()
    {
    CClientDC dc(this);
    CDC MemDC;
    MemDC.CreateCompatibleDC(&dc);
    CBitmap *pOldBmp = MemDC.SelectObject(&m_Bmp);
    MemDC.TextOut(10, 30, "text 2");
    MemDC.SelectObject(pOldBmp);
    }

    And after I create this modeless dialog, I ran Draw(). But only "text 1" was shown on the dialog, "text 2" was not. I know this method can be used in Doc/View without any problem, but why it didnot work in dialogs?

    could you help me? thank you!

  2. #2
    Join Date
    May 2005
    Posts
    4,954

    Re: drawing in the dialog

    Well what is going on is after your dialog is Init OnPaint() is called and whenever OnPaint() is being called the painting on your dialog will be "1" cause this is what you drawing in OnPaint().

    All drawing should be in OnPaint()!

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  3. #3
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: drawing in the dialog

    adding to golanshahar.... Even if you draw anything else it will be erased because of the code in OnPaint. OnPaint is called whenever the window or it's any area needs to be redrawn, like in case of Window is moved, certain other top level window was minimized and your window comes to top etc... so that makes a lot of times of OnPaint execution.
    Regards,
    Ramkrishna Pawar

  4. #4
    Join Date
    Feb 2004
    Posts
    82

    Re: drawing in the dialog

    But why I can do this similar thing without any problem in View? (using CClientDC in OnDraw instead of using CPaintDC in OnPaint)

    What is the difference between CView and CDialog in terms of doing these kind of drawing job? thanks!

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