Rotating windmill VC ++ instance code (Win32 Application)

Source: Internet
Author: User

Rotating windmill-VC ++ instance code (Win32 Application)

// The source code is as follows:
# Include <windows. h>
# Include <stdlib. h>
# Include <string. h>
# Include <math. h>
# Define PI 3.1415926

Int nnum = 0, nmaxnum = 20;

Lresult callback windowproc (
Hwnd, // handle to window
Uint umsg, // message identifier
Wparam, // first Message Parameter
Lparam // second Message Parameter
);
Int winapi winmain (
Hinstance, // handle to current instance
Hinstance hprevinstance, // handle to previous instance
Lpstr lpcmdline, // command line
Int ncmdshow // show state
)

{
Hwnd;
MSG;
Wndclass;
Wndclass. cbclsextra = 0;
Wndclass. cbwndextra = 0;
Wndclass. hbrbackground = (hbrush) getstockobject (white_brush );
Wndclass. hcursor = loadcursor (null, idc_arrow );
Wndclass. hicon = loadicon (null, idi_application );
Wndclass. hinstance = hinstance;
Wndclass. lpfnwndproc = windowproc;
Wndclass. lpszclassname = "ABC ";
Wndclass. lpszmenuname = NULL;
Wndclass. Style = 0;

Registerclass (& wndclass );

Hwnd = createwindow ("ABC", "Rotating windmill", ws_overlappedwindow, cw_usedefault, 0,600,450, null, null, hinstance, null );

Showwindow (hwnd, sw_shownormal );
Updatewindow (hwnd );

While (getmessage (& MSG, hwnd, null, 0 ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}
Return 0;
}

Lresult callback windowproc (
Hwnd, // handle to window
Uint umsg, // message identifier
Wparam, // first Message Parameter
Lparam // second Message Parameter
)
{
HDC;
Hbrush;
Hpen HP;
Paintstruct pS;
Int ncenterx, ncentery;
Double fangle;

Switch (umsg)
{
Case wm_paint:
HDC = beginpaint (hwnd, & PS );
Setmapmode (HDC, mm_anisotropic );
Setwindowextex (HDC, 400,300, null );
Setviewportextex (HDC, 600,450, null );
Setviewportorgex (HDC, 300,200, null );

// Draw the outer circle
HP = createpen (ps_solid, 1, RGB (255, 0, 255 ));
SelectObject (HDC, HP );
Ellipse (HDC,-100,-100,100,100 );

// Draw the blade of the windmill
// Draw a red Blade
Hbrush = createsolidbrush (RGB (255, 0, 0 ));
SelectObject (HDC, hbrush );
Fangle = 2 * PI/nmaxnum * nnum;
Ncenterx = (INT) (50 * Cos (fangle ));
Ncentery = (INT) (50 * sin (fangle ));
Pie (HDC, nCenterX-50, nCenterY-50, ncenterx + 50, ncentery + 50, (INT) (ncenterx + 50 * Cos (fangle), (INT) (ncentery + 50 * sin (fangle), (INT) (ncenterx + 50 * Cos (fangle + PI), (INT) (ncentery + 50 * sin (fangle + PI )));

// Draw the blue Blade
Hbrush = createsolidbrush (RGB (255,255, 0 ));
SelectObject (HDC, hbrush );
Ncenterx = (INT) (50 * Cos (fangle + 2 * PI/3 ));
Ncentery = (INT) (50 * sin (fangle + 2 * PI/3 ));
Pie (HDC, nCenterX-50, nCenterY-50, ncenterx + 50, ncentery + 50, (INT) (ncenterx + 50 * Cos (fangle + 2 * PI/3), (INT) (ncentery + 50 * sin (fangle + 2 * PI/3), (INT) (ncenterx + 50 * Cos (fangle + PI + 2 * PI/3 )), (INT) (ncentery + 50 * sin (fangle + PI + 2 * PI/3 )));

// Draw a yellow Blade
Hbrush = createsolidbrush (RGB (0,255,255 ));
SelectObject (HDC, hbrush );
Ncenterx = (INT) (50 * Cos (fangle + 4 * PI/3 ));
Ncentery = (INT) (50 * sin (fangle + 4 * PI/3 ));
Pie (HDC, nCenterX-50, nCenterY-50, ncenterx + 50, ncentery + 50, (INT) (ncenterx + 50 * Cos (fangle + 4 * PI/3), (INT) (ncentery + 50 * sin (fangle + 4 * PI/3), (INT) (ncenterx + 50 * Cos (fangle + PI + 4 * PI/3 )), (INT) (ncentery + 50 * sin (fangle + PI + 4 * PI/3 )));

Nnum ++;
Sleep (100 );
Invalidaterect (hwnd, null, 1 );
Endpaint (hwnd, & PS );

Return 0;
Case wm_close:
Postquitmessage (0 );
Break;
Default:
Return defwindowproc (hwnd, umsg, wparam, lparam );
}
Return 0;
}

Rotating windmill-VC ++ instance code (Win32 Application)

// The source code is as follows:
# Include <windows. h>
# Include <stdlib. h>
# Include <string. h>
# Include <math. h>
# Define PI 3.1415926

Int nnum = 0, nmaxnum = 20;

Lresult callback windowproc (
Hwnd, // handle to window
Uint umsg, // message identifier
Wparam, // first Message Parameter
Lparam // second Message Parameter
);
Int winapi winmain (
Hinstance, // handle to current instance
Hinstance hprevinstance, // handle to previous instance
Lpstr lpcmdline, // command line
Int ncmdshow // show state
)

{
Hwnd;
MSG;
Wndclass;
Wndclass. cbclsextra = 0;
Wndclass. cbwndextra = 0;
Wndclass. hbrbackground = (hbrush) getstockobject (white_brush );
Wndclass. hcursor = loadcursor (null, idc_arrow );
Wndclass. hicon = loadicon (null, idi_application );
Wndclass. hinstance = hinstance;
Wndclass. lpfnwndproc = windowproc;
Wndclass. lpszclassname = "ABC ";
Wndclass. lpszmenuname = NULL;
Wndclass. Style = 0;

Registerclass (& wndclass );

Hwnd = createwindow ("ABC", "Rotating windmill", ws_overlappedwindow, cw_usedefault, 0,600,450, null, null, hinstance, null );

Showwindow (hwnd, sw_shownormal );
Updatewindow (hwnd );

While (getmessage (& MSG, hwnd, null, 0 ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}
Return 0;
}

Lresult callback windowproc (
Hwnd, // handle to window
Uint umsg, // message identifier
Wparam, // first Message Parameter
Lparam // second Message Parameter
)
{
HDC;
Hbrush;
Hpen HP;
Paintstruct pS;
Int ncenterx, ncentery;
Double fangle;

Switch (umsg)
{
Case wm_paint:
HDC = beginpaint (hwnd, & PS );
Setmapmode (HDC, mm_anisotropic );
Setwindowextex (HDC, 400,300, null );
Setviewportextex (HDC, 600,450, null );
Setviewportorgex (HDC, 300,200, null );

// Draw the outer circle
HP = createpen (ps_solid, 1, RGB (255, 0, 255 ));
SelectObject (HDC, HP );
Ellipse (HDC,-100,-100,100,100 );

// Draw the blade of the windmill
// Draw a red Blade
Hbrush = createsolidbrush (RGB (255, 0, 0 ));
SelectObject (HDC, hbrush );
Fangle = 2 * PI/nmaxnum * nnum;
Ncenterx = (INT) (50 * Cos (fangle ));
Ncentery = (INT) (50 * sin (fangle ));
Pie (HDC, nCenterX-50, nCenterY-50, ncenterx + 50, ncentery + 50, (INT) (ncenterx + 50 * Cos (fangle), (INT) (ncentery + 50 * sin (fangle), (INT) (ncenterx + 50 * Cos (fangle + PI), (INT) (ncentery + 50 * sin (fangle + PI )));

// Draw the blue Blade
Hbrush = createsolidbrush (RGB (255,255, 0 ));
SelectObject (HDC, hbrush );
Ncenterx = (INT) (50 * Cos (fangle + 2 * PI/3 ));
Ncentery = (INT) (50 * sin (fangle + 2 * PI/3 ));
Pie (HDC, nCenterX-50, nCenterY-50, ncenterx + 50, ncentery + 50, (INT) (ncenterx + 50 * Cos (fangle + 2 * PI/3), (INT) (ncentery + 50 * sin (fangle + 2 * PI/3), (INT) (ncenterx + 50 * Cos (fangle + PI + 2 * PI/3 )), (INT) (ncentery + 50 * sin (fangle + PI + 2 * PI/3 )));

// Draw a yellow Blade
Hbrush = createsolidbrush (RGB (0,255,255 ));
SelectObject (HDC, hbrush );
Ncenterx = (INT) (50 * Cos (fangle + 4 * PI/3 ));
Ncentery = (INT) (50 * sin (fangle + 4 * PI/3 ));
Pie (HDC, nCenterX-50, nCenterY-50, ncenterx + 50, ncentery + 50, (INT) (ncenterx + 50 * Cos (fangle + 4 * PI/3), (INT) (ncentery + 50 * sin (fangle + 4 * PI/3), (INT) (ncenterx + 50 * Cos (fangle + PI + 4 * PI/3 )), (INT) (ncentery + 50 * sin (fangle + PI + 4 * PI/3 )));

Nnum ++;
Sleep (100 );
Invalidaterect (hwnd, null, 1 );
Endpaint (hwnd, & PS );

Return 0;
Case wm_close:
Postquitmessage (0 );
Break;
Default:
Return defwindowproc (hwnd, umsg, wparam, lparam );
}
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.