سؤال

My OnPaint() method in a derived CStatic-control is supposed to be cutting of parts of the drawing which are bigger than the control, as far as I know. However it doesn't do this.

void CGraph::OnPaint ()
{
   CPaintDC dc(this);
   dc.SetViewportOrg (0, 400);
   dc.SetMapMode(MM_ISOTROPIC);
   dc.SetWindowExt(1000, 800);
   dc.SetViewportExt(1000, -800);

   // MessageBox(L"OnPaint");
   ProcessData ();
   DrawCoordinateSystem (&dc);
   DrawGrid (&dc);
   DrawGraph (&dc);
}
هل كانت مفيدة؟

المحلول 2

@JohnCz Got it now.

CDC* pDC = GetDC();
CRect rClient();
GetClientRect(rClient);
CRgn ClipRgn;
if (ClipRgn.CreateRectRgnIndirect(&rClient))
{
    pDC->SelectClipRgn(&ClipRgn);
}


// Drawing content


pDC->SelectClipRgn(NULL);
ReleaseDC(pDC);

Thanks for your answer

نصائح أخرى

Depends on the definition of a method.

OnPaint is not really a method; it is a static member function used to handle a WM_PAINT message by mapping it in the message map array.

For a C++, I personally prefer to call it a member function for clarity.

You can create your own handler using ON_MESSAGE macro and call it whatever you desire. The code snippet does not tell much, since it does not show the code for drawing (painting). You should include code that actually performs paining.

The best would be if you could attach project demonstrating your problem.

Did you try to paint a simple bitmap that has a size bigger than a window?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top