dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: How to draw a rectangle in OnDraw?

  1. #1
    Join Date
    Dec 2017
    Posts
    4

    How to draw a rectangle in OnDraw?

    I am using OpenGL in MFC and I split the screen in to 3 subviews (View1, View2 and View3). An MyOpenGL class is derived from the CView and 3 subviews derived from the MyOpenGL class. As initializing the OpenGL, I create and store a DC to a member m_pDC. Now I want to draw a rectangle in OnDraw(CDC *pDC) of the View1 but it does not work. The pDC parameter in OnDraw(CDC* pDC) is always NULL so I cannot use it to draw a rectangle. If I use m_pDC to draw a rectangle, the rectangle is not shown in the screen. However, if I use m_pDC to draw a rectangle in the OnLButtonDblClk() function, it works.

    So how to draw a rectangle in the OnDraw(CDC *pDC) when the pDC parameter is always NULL. Please, help me.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,591

    Re: How to draw a rectangle in OnDraw?

    How did you implement this OnDraw? With a Wizard or "by hand"?
    How and when did you check the pDC is NULL?
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2017
    Posts
    1

    Re: How to draw a rectangle in OnDraw?

    Hello,

    how to draw the empty rectangle with etc. borderWidth=3 and borderColor=black and part within rectangle don't have content or color. Which function in Canvas to use

    try this example this example is useful for you try this one

    Code:
    Paint myPaint = new Paint();
    myPaint.setColor(Color.rgb(0, 0, 0));
    myPaint.setStrokeWidth(10);
    c.drawRect(100, 100, 200, 200, myPaint);
    It draws rectangle and fill it with black color but I want just "frame" around like this image:
    Last edited by 2kaud; December 13th, 2017 at 07:37 AM. Reason: Added code tags and removed advertising

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,591

    Re: How to draw a rectangle in OnDraw?

    Quote Originally Posted by miaavery View Post
    ...
    try this example this example is useful for you try this one

    Code:
    Paint myPaint = new Paint();
    myPaint.setColor(Color.rgb(0, 0, 0));
    myPaint.setStrokeWidth(10);
    c.drawRect(100, 100, 200, 200, myPaint);
    :
    What is Paint?
    What is c?
    In what OS, environment does it appear to work?
    Victor Nijegorodov

  5. #5
    Join Date
    Dec 2017
    Posts
    4

    Re: How to draw a rectangle in OnDraw?

    Thanks for the reply VictorN, I created OnDraw with a wizard. Everytime I click on a screen, I invoke the OnDraw(CDC *pDC) but the pDC parameter is always NULL. In somehow, I get it worked with the following code:

    Code:
    void CView1::OnDraw(CDC* pDC)
    {
       ....
       if (pDC)
    	render_clicked_points(pDC);
       else
      {	
            // m_pDC is a pointer to CDC object when I initialize OpenGL
    	render_clicked_points(m_pDC);
      }
    }
    Thanks for the reply again.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,591

    Re: How to draw a rectangle in OnDraw?

    Could you post a very short project example (in zip archive) reproducing your problem?
    Victor Nijegorodov

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)