Win32 application development Getting Started: a simple Win32 program

First, what is Win32

Win32 refers to the Microsoft Windows operating system 32-bit environment, and Win64 are common to Windows environments.

Here again describes the differences between the lower Win32 Application and Win32 Console Application:

1, different programs

  • Win32 Application is a standard windows procedures , complete with characteristic windows can be controlled by mouse clicks to complete the window.

  • Win32 Console Application is a console application , similar to the MS-DOS window, command line program run only, without message response mechanism.

2, functions of different inlet

  • Win32 Application entry function is the WinMain () , which has a message response mechanism may be running a graphical C ++ program.

  • Win32 Console Application entry function is main () , you can access some windows API functions, if you write a traditional C program, you must establish a Win32 Console program.


Second, the most simple procedure

Creating a win32 application engineering function is to display a message box, casually suggesting some text on it. Specific steps to create a project can refer to: create a simple win32 application . code show as below:

#include <Windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) 
{
    MessageBox(
        NULL,
        TEXT("随便提示一些内容就可以了!哈哈哈!"),      // 内容
        TEXT("这里是标题!"),     // 标题名称
        0);
    return 0;
}

We look at the results:


Next, we start from scratch dissect this simple little program.


Third, analyze

3.1 file

#include <Windows.h>

windows.h is one of the most important include file, which encompasses several other Windows header files, some of these header files also contains some additional headers.

The following are some of the most important and basic header file:

  • WINDEF.H Elementary data type definitions.
  • WINNT.H The definition of the type of support Unicode.
  • WINBASE.H Kernel function.
  • WINUSER.H User interface functions.
  • WINGDI.H Graphics Device Interface function.

These header files define all the data types of Windows, function calls, data structures, and constant identifiers.


3.2 program entry

C program is the main entrance, and the entrance Windows program is WinMain, it is always like this:

int WINAPI WinMain( HINSTANCE hInstance, 
                    HINSTANCE hPrevInstance, 
                    PSTR szCmdLine, 
                    int iCmdShow) 

WinMain return value of the function is defined to int. WINAPI identifier is defined in WINDEF.H, which provides for a function calling convention. And most of our Windows function calls are defined as WiNAPI.

Let's look at part of its argument:

  • The first argument is generally called "instance handle" (Instance Handle). In Windows programs, handle nothing more than a number, in the program use it to identify something. For example, in our example, the handle on this uniquely identifies our program, on behalf of the program itself. In fact, some Windows programs, the handle as call parameters are required. For example, in earlier versions of Windows, when multiple concurrently running the same program, you need to create multiple instances of that program. All instances of the same program share code and read-only memory.
  • A program can view hPrevInstance, which is the second parameter and thus to know whether there are other instances of it are running. It may thus also skip some scattered chores step, the number of data moved from a previous instance of its own data area. But in 32-bit Windows, this concept is no longer used. Thus WinMain second parameter is usually always NULL (defined as 0).
  • WinMain The third parameter is the command line used to run the program (Command Line). Some Windows programs use it when you start to put the files into memory.
  • WinMain The fourth parameter is used to indicate how the program initially display or normal display, or maximized to full screen, or minimize displayed on the taskbar.


3.2 MessageBox function

Finally, we look at the most important MessageBox function.

MessageBox function is used to display a short message. Despite the relatively simple form, small MessageBox displayed in
a small window is actually a dialog box.

We also look at several of its parameters:

  • MessageBox the first argument is usually a window handle. Let it matter.

  • The second parameter text that will appear in the information box strings.

  • The third argument is the text string to be displayed in the title bar. And in this program, we put all the strings are packaged inside TEXT macro code, it is to use TEST("XXX")it wrapped up. In general, you do not need all the strings are packaged TEXT macro code inside, did so because it would be a lot easier when converting the program into Unicode.

  • The fourth parameter is the prefix of MB_some combination of constants beginning. WINUSER.H, as defined in the relevant constants. For example, following these, you can choose one to represent hope in the dialog box which buttons:

    #define MB_OK                   0X00000000L       // ok
    #define MB_OKCANCEL             0x00000001L       // ok和取消
    #define MB_ABORTRETRYIGNORE     0x00000002L       // 中止、重试和取消
    #define MB_YESNOCANCEL          0x00000003L       // yes/no/取消
    #define MB_YESNO                0X00000004L       // yes和no
    #define MB_RETRYCANCEL          0x00000005L       // 重试和取消


reference:

By a simple Windows program Easy programming


Guess you like

Origin www.cnblogs.com/linuxAndMcu/p/12075196.html