Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8219545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:12:17+00:00 2026-06-07T13:12:17+00:00

My OnPaint() function calls several other drawing functions. void CGraph::OnPaint () { CPaintDC dc(this);

  • 0

My OnPaint() function calls several other drawing functions.

 void CGraph::OnPaint ()
 {
    CPaintDC dc(this);
    // CMemDC DC(&dc);

    dc.SetViewportOrg (0, 400);
    dc.SetMapMode(MM_ISOTROPIC);
    dc.SetWindowExt(1000, 800);
    dc.SetViewportExt(1000, -800);

    ProcessData ();
    DrawCoordinateSystem (&dc);
    DrawGrid (&dc);
    DrawGraph (&dc);
}

Example of DrawCoordianteSystem:

void CGraph::DrawCoordinateSystem (CDC* pDC)
{
   CPen PenBlack (PS_SOLID, 1, RGB(0, 0, 0));
   pDC->SelectObject (PenBlack);
   // Rectangle round the system
   pDC->Rectangle (0, -400, 1000, 400);
   // Horizontal axis
   pDC->MoveTo (0, 0);
   pDC->LineTo (1000, 0);
   pDC->SetTextColor (RGB(0,0,0));
   pDC->SetBkColor (RGB(240, 240, 240));
   pDC->TextOut (1001, 0, L"0");
   // Vertical axis
   pDC->MoveTo (0, -400);
   pDC->LineTo (0, 400);
}

I now want to avoid flickering with CMemDC. However, i can’t get it to work right. Can somebody show me how to implement CMemDC right?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:12:19+00:00Added an answer on June 7, 2026 at 1:12 pm

    You need to load the memory DC with a bitmap to then BitBlt to the screen DC.

    Try something like:

    CDC dcMem;
    CBitmap bitmap;
    
    dcMem.CreateCompatibleDC( pDC );
    bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height())
    CBitmap* pOldBitmap = dcMem.SelectObject(&bitmap);
    
    ... DO ALL YOUR DRAWING TO dcMem ...
    
    pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &dcMem, 0, 0, SRCCOPY);
    
    dcMem.SelectObject(pOldBitmap)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to customize ToolStripMenuItem by overriding OnPaint function. This is a MyToolStripMenuItem: public
Sometimes I see code like this: LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL&
protected override void OnPaint(PaintEventArgs e) { Win32Helper.StretchBlt(this.Handle, 0, 0, 200, 300,bitmap.GetHbitmap(), 0, 0, bitmap.Width,
I've a UserControl (WinForms, .net 2.0), and I've this: protected override void OnPaint(PaintEventArgs e)
I want to change my window design rapidly. I have OnPaint function which I
I have the following code: int a = 0; protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
I have a custom MFC control, subclassing CWnd. Other than providing OnPaint and PreSubclassWindow
I'm using the RoundRect GDI function to draw a rounded rectangle following this example:
I am using Graphics.DrawString to draw my usercontrol's text like this: protected override void
Since using the DrawArc function in GDI+ isn't very accurate when drawing a small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.