Windows编程(1)-第一个程序

来源:互联网 发布:coc天使升级数据 编辑:程序博客网 时间:2024/05/15 23:44

Code:

/*------------------------------------------------------------------HelloMsg.c -- Displays "Hello, Windows 98!" in a message box    (c) Charles Petzold, 1998--------------------------------------------------------------------*/#include <windows.h>int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,                   PSTR szCmdLine, int iCmdShow){MessageBox (NULL, TEXT ("Hello, Windows 98!"), TEXT ("HelloMsg"), 0);return 0 ;}

1. The Head Files 

WINDOWS.H is a master include file that include other Windows header files, some of which also include other header files. The most important and most basic of these files are:

  • WINDEF.H  Basic type definitions
  • WINNT.H  Type definitions for Unicode support
  • WINBASE.H  Kernel functions
  • WINUSER.H User interface functions
  • WINGDI.H  Graphics device interface funcitons
2. Program Entry Point

The entry point to a Windows program is WinMain, which always appears like this:

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

This entry point is documented in /Platform SDK/User Interface Services/Windows/Window Reference/Window Functions. It is declared in WINBASE.H.

The WinMain function is declared as returning an int. The WINAPI identifier is defined in WINDEF.H with the statement:

#define WINAPI __stdcall

This statement specifiles a calling convention that involves how machine code is generated to place function call arguments on the stack. Most Windows function calls are declared as WINAPI. (该语句指定了一个呼叫约定,包括如何生产机械码以在堆栈中防止函数呼叫的参数。许多Windows函数呼叫声明为WINAPI)

The first parameter to WinMain is something called an "instance handle". In windows programming, a handle is simply a number that an application uses to identify something. In this case, the handle uniquely identifies the program. It is required as an argument(参数)  to some other Windows function calls. 

In early versions of Windows, when you ran the same program concurrently(同时)more than once, you created multiple instances of that program. All instances of the same application shared code and read-only memory(usually resources such as menu and dialog box templates). A program could determine if other instances of itself were running by checking the hPrevInstance parameter. It could then skip certain chores and move same data from the previous instance into its own data area.(同一应用程序的所有instances共享程序和只读内存(通常是例如菜单和对话框模板的资源)。程序通过检查hPrevInstance参数就能够确定自身的其他instance是否正在运行。然后它可以略过一些复杂的工作并从前面的instance将某些数据移到自己的数据区域)

In the 32-bit versions of Windows, this concept has been abandoned. The second parameter to WinMain is always NULL(defined as 0).

The third parameter to WinMain is the command line used to run the program. Some Windows applications use this to load a file into memory when the program is started. 

The fourth parameter to WinMain indicates how the program should be initially displayed--either normally or maximized to fill the window, or minimized to be displayed in the task list bar. 

原创粉丝点击