Win32.01. the simplest Windows Application

Source: Internet
Author: User
1 /*
2 The simplest Windows ApplicationProgram
3 As you may think, this is the simplest windows application. It only starts a form, but it has basic functions such as maximization, minimization, Window Scaling, and closing.
4 This is a standard Windows application, on which we can expand to implement more complex applications, such as adding new controls, menus, multiple forms, and even plotting.
5
6 For Windows programs, you must register the window class (10 parameters, including the window handler). Then, createwindow, showwindow, and updatewindow implement the window.
7 And then enable message loop (transmission, distribution). Note that the message processing function must process the wm_destroy message.
8 For more information about the message processing mechanism of windows, Hou Jie's book "an in-depth introduction to MFC" is also available for reference.
9
10 Program from programming windows, author chales Petzold, this program is just a memo. 2010-07-18 Phoenix @ Home
11 */
12 # Include < Windows. h >
13
14 Lresult callback wndproc (hwnd, uint message, wparam, lparam)
15 {
16 Switch (Message)
17 {
18 Case Wm_destroy:
19 Postquitmessage ( 0 );
20 Return   0 ;
21 }
22 Return Defwindowproc (hwnd, message, wparam, lparam );
23 }
24
25 Int _ Stdcall winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, Int Nshowcmd)
26 {
27 Tchar szappname [] = L " Simplewindow " ;
28 MSG;
29 Hwnd hwndmain;
30 Wndclass;
31
32 // The wndclass structure has 10 members. You must set all the members to register successfully.
33 Wndclass. lpszclassname = Szappname;
34 Wndclass. hicon = Loadicon (null, idi_application );
35 Wndclass. hcursor = Loadcursor (null, idc_arrow );
36 Wndclass. lpfnwndproc = Wndproc; // Message Processing Process of the specified window
37 Wndclass. hinstance = Hinstance;
38 Wndclass. cbclsextra =   0 ;
39 Wndclass. cbwndextra =   0 ;
40 Wndclass. Style = Cs_hredraw | Cs_vredraw;
41 Wndclass. lpszmenuname = NULL;
42 Wndclass. hbrbackground = (Hbrush) getstockobject (white_brush );
43
44 If ( ! Registerclass ( & Wndclass )) // Registration window class
45 {
46 MessageBox (null, text ( " This program requires Windows NT. " ), Text ( " Windows NT required " ), Mb_iconstop );
47 Return   0 ;
48 }
49
50 // Createwindow, showwindow, updatewindow: create a window, display and update the window view
51 Hwndmain = Createwindow (szappname, text ( " The simple Windows Application " ), Ws_overlappedwindow,
52 Cw_usedefault,
53 Null, null, hinstance, null );
54 Showwindow (hwndmain, nshowcmd );
55 Updatewindow (hwndmain );
56
57 // Message loop: starts a message loop.
58 While (Getmessage ( & MSG, null, 0 , 0 ))
59 {
60 Translatemessage ( & MSG );
61 Dispatchmessage ( & MSG );
62 }
63
64 Return MSG. wparam;
65 }

Related Article

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.