windows 编程- HelloMsg
来源:互联网 发布:知乎绝地求生炸鱼 编辑:程序博客网 时间:2024/06/05 12:48
// Programming windows by Charles Petzold ,fifth edition/* HelloMsg.c */#include <windows.h>int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow){MessageBox(NULL,TEXT("Hello Windows XP!"),TEXT("HellowMsg"),0);//---return 0;}
Program Entry Point
Just as the entry point to a C program is the function main, 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/Windowing/Windows/Window Reference/Window Functions. It is declared in WINBASE.H like so (line breaks and all):
int
WINAPI
WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
);
You'll notice I've made a couple of minor changes in HELLOMSG.C. The third parameter is defined as an LPSTR in WINBASE.H, and I've made it a PSTR. These two data types are both defined in WINNT.H as pointers to character strings. The LP prefix stands for "long pointer" and is an artifact of 16-bit Windows.
I've also changed two of the parameter names from the WinMain declaration; many Windows programs use a system called "Hungarian notation" for naming variables. This system involves prefacing the variable name with a short prefix that indicates the variable's data type. I'll discuss this concept more in Chapter 3. For now, just keep in mind that the prefix i stands for int and sz stands for "string terminated with a zero."
The WinMain function is declared as returning an int. The WINAPI identifieris defined in WINDEF.H with the statement:
#define WINAPI __stdcall
This statement specifies 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.
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 some data from the previous instance into its own data area.
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 parameterto 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. We'll see how this parameter is used in Chapter 3.
- windows 编程- HelloMsg
- HelloMsg
- windows程序设计--1.3.2 HelloMsg.cpp出现错误
- Windows程序设计第五版——源代码001之HelloMsg.c
- 程序1-1 HelloMsg
- windows 编程
- Windows编程
- windows编程
- Windows编程
- windows编程
- windows编程
- windows编程---
- windows编程
- windows编程
- WINDOWS编程
- Windows编程
- windows 编程
- windows编程
- ogre的主要渲染流程(转)
- 关于搬家
- 第五周 任务一
- 开始学习PYTHON
- 获取当前经纬度方法
- windows 编程- HelloMsg
- MATLAB中PLOT 的例子 源代码
- 编程之美-前言
- C++的tie()函数
- Turn on WCF Server Security Event Logging & Auditing
- 查看SQL2008列说明
- MicroKernel & Exokernel 操作系统未来可能的发展
- SHSH备份教程及相关知识介绍
- 使用C#开发基于Winform的手机号码归属地查询工具