Home > Software engineering >  MFC beginner problems for answers
MFC beginner problems for answers

Time:09-24

Using the new default VS2017 MFC project, try to output text in ontouch function, line drawing, nowhere else changes, compiles without error, but the runtime View area is blank, please answer

CodePudding user response:

 
Void CSDI3View: : ontouch * pDC (CDC)
{
CSDI3Doc * pDoc=GetDocument ();
ASSERT_VALID (pDoc);
//TODO: add the draw code for native data here

//save DC
Int nSaveDC=pDC - & gt; SaveDC ();

//the client area coordinates range
CRect rcClient;
GetClientRect (& amp; RcClient);

//fill background
PDC - & gt; FillSolidRect (rcClient, RGB (250, 250, 250));

Draw a line//
{
//create the brush
CPen linePen (PS_SOLID, 2, RGB (255, 0, 0));
//candidate brush
CPen * pOldPen=pDC - & gt; SelectObject (& amp; LinePen);
//move to the starting point for
PDC - & gt; MoveTo (rcClient TopLeft ());
Draw a line//
PDC - & gt; LineTo (rcClient BottomRight ());
//restore brush
PDC - & gt; SelectObject (pOldPen);
}

//write
{
//create a font
CFont mFont;
MFont. CreatePointFont (240, _T (" Arial "));
//candidate font
CFont * pOldFont=pDC - & gt; SelectObject (& amp; MFont);

//set the font color
Int txColor=pDC - & gt; SetTextColor (RGB (0, 0, 255));

//set the background transparent
Int bkMode=pDC - & gt; SetBkMode (TRANSPARENT);

//output font
PDC - & gt; TextOut (10, 10, _T (" font "));

//recovery background model
PDC - & gt; SetBkMode (bkMode);
//resume font color
PDC - & gt; SetTextColor (txColor);
//resume font
PDC - & gt; SelectObject (pOldFont);
}

//restore DC
PDC - & gt; RestoreDC (nSaveDC);

}

CodePudding user response:

Finished drawing up refreshed

CodePudding user response:

RestoreDC is restored, removed

CodePudding user response:

refer to the original poster Wilbot response:
using the new default VS2017 MFC project, try to output text in ontouch function, line drawing, nowhere else changes, compiled without error, but the runtime View area is blank, please answer


Ontouch code post
  • Related