Home > Software engineering >  Written by drawing in the OnPaint function, but not draw line, debugging, confirm this program is ru
Written by drawing in the OnPaint function, but not draw line, debugging, confirm this program is ru

Time:09-21


The else
{
CDialogEx: : OnPaint ();


PAINTSTRUCT ps;


GetDlgItem (IDC_STATIC_PAINT) - & gt; GetClientRect (rectPaint);

CPaintDC Dc (GetDlgItem (IDC_STATIC_PAINT));
Dc. SetBkColor (RGB (0, 0, 0));
Dc. FillSolidRect (rectPaint, RGB (255255255));
//GetClientRect (the rect);
CPen pen;
Pen. CreatePen (PS_SOLID, 2, RGB (0, 0, 0));




Dc. SelectObject (pen);
Dc. MoveTo (200, 15);
Dc. LineTo (200, 185);
//Dc MoveTo (128, 160);
Dc. LineTo (600, 185);

Dc. MoveTo (200, 185);
Dc. LineTo (115, 255);

Dc. MoveTo (200, 15);
Dc. LineTo (195, 25);

Dc. MoveTo (200, 15);
Dc. LineTo (205, 25);

Dc. MoveTo (115, 255);
Dc. LineTo (118, 245);

Dc. MoveTo (115, 255);
Dc. LineTo (120, 258);

Dc. MoveTo (600, 185);
Dc. LineTo (590, 180);

Dc. MoveTo (600, 185);
Dc. LineTo (590, 190);
for (int i=0; I & lt; ThreadCount; I++)
{
Dc. MoveTo (200, 15);
Dc. The LineTo (200 + 10 * I, 190);
}

//pen. CreatePen (PS_SOLID, 10, RGB (0, 0, 0));
//Dc SelectObject (pen);
for (int i=0; I & lt; DataLen; I++)
{
Double Angle=45 + 0.167 * I;
int x;
Int y=dataNeeded [I] * sin (Angle)/100;
If (angle<90)
{
X=dataNeeded [I] * cos (Angle)/100;
Dc. SetPixel (240 + x + 2 * cos (45), 140 - y - 2 * cos (45), RGB (0, 0, 255));
}
The else
{
X=dataNeeded [I] * cos (abs (Angle))/100;
Dc. SetPixel (240 + x * cos (45), 140 + y + 2 * cos (45), RGB (0, 0, 255));
}


}
Dc. BitBlt (rectPaint - & gt; Left, rectPaint - & gt; Top, rectPaint - & gt; Width (), rectPaint - & gt; Height (), & amp; Dc, 0, 0, SRCCOPY);

CodePudding user response:

Brush figure not implemented in real time, but when the dialog box to minimize, maximize, can come out

CodePudding user response:

CDialogEx: : OnPaint (); After all controls in the dialog box will be Invalidate ()
Ended until the dialog box OnPaint (), all controls to redraw (so this dialog OnPaint () to control the paint was covered in)
In the dialog box to draw controls,
1. The OnPaint ();//draw the dialog itself, at the same time, Invalidate () all controls,
2. All controls UpdateWindow ();//window effective! (DC) effectively
3. All controls effectively the GetDC ();
4. Draw all controls!

CodePudding user response:

/* InvalidateRect function is invalid window's client area,
Send the role of low priority WM_PAINT message UpdateWindow is redrawing the client area at the same time effective immediately,
Note the following PaintWindow function, with GetDC function get equipment environment handle, here is the key,
GetDC and BeginPaint is different from the GetDC returns a handle to handle after you can use this anywhere in the client area drawing,
Whether valid or invalid area, at the same time the GetDC not make dead space effectively, so you remove the UpdateWindow,
The following PaintWindow still does, but after drawing the figure your child window controls the client area is invalid,
As a result, the system sends a WM_PAINT message to the window procedure of child Windows, the default window procedure will be filled with a brush,
There should be and the background color of the same brush so nothing shows,
*/
Void PaintTheBlock (HWND hCtrl, int iColor, int iFigure)
{
InvalidateRect (hCtrl, NULL, FALSE);//TRUE);
UpdateWindow (hCtrl);
PaintWindow (hCtrl, iColor, iFigure);
}

CodePudding user response:

Advice from a new class to handle the WM_PAINT CStatic derived

CodePudding user response:

Refresh the

CodePudding user response:

If minimized after reduction, you will be drawn, that just means that you didn't call the refresh function.

You only need to call invalidate a function in the window class.

Of course, this would probably appear the phenomenon of the splash screen.

The best thing to do is, when you draw GetClientDC directly, directly on the client area, do not use the OnPaint message response. Of course, in order to window card new, draw something is still there, is also a need to call in the OnPaint map to map your.
  • Related