This article describes the C + + implementation of the graphical interface of the clock disk code, shared for everyone to reference.
The specific implementation code is as follows:
Copy Code code as follows:
The array of point can be used so
Point pt[]={
0, 450,
225,390,
390,225,
450,0,
390,-225,
225,-390,
0,-450,
-225,-390,
-390,-225,
-450,0,
-390,225,
-225,390
};
Setisotropic function: Set coordinate system
Change the coordinate system with these four functions:
void Setisotropic (HDC HDC, int cx, int cy) {
:: Setmapmode (hdc, mm_isotropic); Set the coordinate mapping method
:: Setwindowextex (HDC, 1000, 1000, NULL); Set logical units for a coordinate system
:: Setviewportextex (HDC, CX,-cy, NULL); Set the scope of the coordinate system direction and coordinate system, that is, define fields and ranges
:: Setviewportorgex (hdc, CX/2, CY/2, NULL); Set the coordinate system origin coordinates}
Copy Code code as follows:
Case WM_PAINT:
HDC = BeginPaint (hWnd, &ps);
TODO: Add any drawing code here ...
Draw a clock plate
int cxclient, cyclient;
RECT RECT;
:: GetClientRect (HWnd, &rect);
Cxclient = Rect.right-rect.left;
Cyclient = Rect.bottom-rect.top;
Setisotropic (hdc, cxclient, cyclient);
#define SQUARESIZE 10
:: SelectObject (HDC,:: Getstockobject (Black_brush));
for (int i=0;i<12;i++)
{
:: Ellipse (hdc, pt[i].x-squaresize,pt[i].y+squaresize,pt[i].x+squaresize, pt[i].y-squaresize);
}
EndPaint (HWnd, &ps);
Break
I hope this article will help you with the C + + program design.