A simple windows program

Source: Internet
Author: User

Not used for a long timeC LanguageWrite windowsProgramNow, I am very interested today. Let's write an exercise as a trainer. If you want to learn about VC, you need to understand the system's API. In the future, I will take a look at the "windows programming" book to improve my internal strength. :)

# Include <windows. h>

Lresult callback wndproc (hwnd, uint, wparam, lparam );

Int winapi winmain (hinstance, hinstance hprevinstance,

Pstr szcmdline, int icmdshow)

{

Static tchar szappname [] = text ("hellowin ");

Hwnd;

MSG;

Wndclaswndclass;

Wndclass. Style = cs_hredraw | cs_vredraw;

Wndclass. lpfnwndproc = wndproc;

Wndclass. cbclsextra = 0;

Wndclass. cbwndextra = 0;

Wndclass. hinstance = hinstance;

Wndclass. hicon = loadicon (null, idi_application );

Wndclass. hcursor = loadcursor (null, idc_arrow );

Wndclass. hbrbackground = (hbrush) getstockobject (white_brush );

Wndclass. lpszmenunam = NULL;

Wndclass. lpszclassname = szappname;

If (! Registerclass (& wndclass ))

{

MessageBox (null, text ("this program requires Windows NT! "),

Szappname, mb_iconerror );

Return 0;

}

Hwnd = createwindow (szappname, // window class name

Text ("the hello program"), // window caption

Ws_overlappedwindow, // window style

Cw_usedefault, // initial X position

Cw_usedefault, // initial y position

Cw_usedefault, // initial X size

Cw_usedefault, // initial y size

Null, // parent window handle

Null, // Window menu handle

Hinstance, // program instance handle

Null); // creation Parameters



Showwindow (hwnd, icmdshow );

Updatewindow (hwnd );



While (getmessage (& MSG, null, 0, 0 ))

{

Translatemessage (& MSG );

Dispatchmessage (& MSG );

}

Return msg. wparam;

}

Lresult callback wndproc (hwnd, uint message, wparam, lparam)

{

HDC;

Paintstruct pS;

Rect;



Switch (Message)

{

Case wm_create:

Playsound (text ("hellowin.wav"), null, snd_filename | snd_async );

Return 0;

Case wm_paint:

HDC = beginpaint (hwnd, & PS );



Getclientrect (hwnd, & rect );



Drawtext (HDC, text ("Hello, Windows 98! "),-1, & rect,

Dt_singleline | dt_center | dt_vcenter );

Endpaint (hwnd, & PS );

Return 0;



Case wm_destroy:

Postquitmessage (0 );

Return 0;

}

Return defwindowproc (hwnd, message, wparam, lparam );

}

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.