GUI programming under Windows--windows

Source: Internet
Author: User

Creating a GUI-based window program under Windows is simple and can be implemented using either MFC or the Win32 API. This article simply organizes the basic coding framework for the Windows API to create GUI applications.

Common windows include: Desktop windows, application Windows, dialog boxes, and controls. From a programmatic point of view, creating a GUI application requires the implementation of the entry function WinMain, which is defined in the following format:

int WINAPI WinMain (hinstance hinstance, hinstance hprevinstance,     int

This does not explain its specific meaning, and it is interesting to refer to Windows programming or the relevant information on MSDN.

WinMain typically consists of the following processes:

1. Registration window class (Windows Class);

2. Create window (CreateWindow);

3. Message Loop (window procedure callback, message queue).

If you use a window class already defined by the operating system, you can omit the first step, or omit the third step if you do not need to customize the window message processing mechanism (some data directly invokes the default implementation of the dialog box to give the shortest implementation of the Windows program, basically based on this principle).

For information about the window class, you can refer to the window class overview that I've been sorting out a while ago.

If you compare the above three steps with the C + + programming language, the first step is to register the window class in order to give the new type of declaration and implementation, which contains some necessary properties and methods, but the operating system provides the API to find the type of the type name (string) The second step to create a window is the class instantiation process, where you need to specify the class name (string) to be created, and the third step is to invoke the protocol for the previously instantiated type variable that needs to be used (message handling and delivery) in accordance with the conventions provided by the operating system.

The following is a declaration of the CreateWindowEx function.

HWND WINAPI CreateWindowEx (  _in_      DWORD dwexstyle,  _in_opt_  lpctstr lpclassname,  _in_opt_  lpctstr lpwindowname,  _in_      DWORD dwstyle,  _in_      int  x,  _in_       int  y,  _in_      int  nwidth,  _in_      int  nheight,  _in_opt_  HWND hwndparent,  _in_opt_  HMENU HMENU,  _in_opt_  HInstance hinstance,  _in_opt_  lpvoid lpparam);

All of these parameters are basically a customizable property for a window. Not as window name, window style (the prototype for Window style,ws_xxx), where Windows is started, menus, parent windows, and so on.

What needs to be explained is the return value of the CreateWindowEx function, hwnd. The description of the HWND type in MSDN is just a word, handle to a window, as its name implies, a handle to a window. Although the definition of HWND in VS is not void * and is not an int type, the window handle is global, is maintained by the operating system, and can be used across processes, perhaps this is also FindWindow One way to implement a function (another is the one that Microsoft has provided to maintain compatibility with 16-bit operating systems). In view of this, the HWND can be seen as an internal structure maintained by the operating system, and the application should not attempt to understand the internal implementation of the change results.

GUI programming under Windows--windows

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.