Windows编程(1)-第一个程序
2013-05-28 17:00
351 查看
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.
/*------------------------------------------------------------------
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.
相关文章推荐
- windows编程第一个程序
- windows编程--第一个WinMain程序
- 【Window编程】Step.1 我的第一个Windows程序
- windows驱动编程入门(第一个程序)
- C/C++_log2000_windows编程之第一个控制台程序项目part2
- windows编程入门之第一个程序
- 第一个Win32窗口程序,纪念自己的Windows编程之旅
- Windows编程C++之第一个Windows程序
- Windows程序编程(1):数据类型
- windows系统下的第一个console程序
- windows下caffe运行我的第一个程序
- Delphi-网络编程-第一个网络方面作品(UDP聊天程序)
- 【VS开发】【OpenGL开发】OpenGL---Windows下配置与第一个OpenGL程序
- unix 网路编程(卷一)第一个程序编译过程
- java网络编程之Netty第一个程序(四)
- 《windows应用高级编程-C#编程篇》书中程序的小问题及改进
- Windows网络编程入门:简单的客户端和服务器通信程序调试
- 基于visual c++之windows核心编程代码分析(44)监测任意程序函数起始地址
- Windows程序设计--第一个窗口程序
- 走进Zend Framework框架编程(三):运行第一个程序