<span style="font-family: Arial, Helvetica, sans-serif;">#include <windows.h></span>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MessageBox(NULL, TEXT("Hello World"), TEXT("Hello"), 0); }
windows.h囊括了很多其他windows头文件,下面是最重要也是最基本的头文件:
WINDEF.H 基本数据类型定义。
WINNT.H 支持UNICODE的类型定义。
WINBASE.H 内核函数。
WINUSER.H 用户界面函数。
WINGDI.H 图形设备接口函数。
#define WINAPI _stdcall
__stdcall 是一种函数调用约定。
WINAPI |
The calling convention for system functions. This type is declared in WinDef.h as follows:
CALLBACK, WINAPI, and APIENTRY are all used to define functions with the __stdcall calling convention. Most functions in the Windows API are declared using WINAPI. You may wish to use CALLBACK for the callback functions that you implement to help identify the function as a callback function. |
typedef void *PVOID;
PVOID |
A pointer to any type. This type is declared in WinNT.h as follows:
|
typedef PVOID HANDLE;
HANDLE |
A handle to an object. This type is declared in WinNT.h as follows:
|
typedef HANDLE HINSTANCE;
HINSTANCE |
A handle to an instance. This is the base address of the module in memory. HMODULE and HINSTANCE are the same today, but represented different things in 16-bit Windows. This type is declared in WinDef.h as follows:
|
HINSTANCE hInstance;
实例句柄,用来唯一标示该程序的。
HINSTANCE hPrevInstance;
通过查看hPrevInstance参数从而知道是否有它的其他实例在运行。32位WINDOWS下已经抛弃这一概念。
LPSTR lpCmdLine;
用来运行程序的命令行。
int nCmdShow;
用来指明程序如何显示。
MessageBox
int WINAPI MessageBox( _In_opt_ HWND hWnd, _In_opt_ LPCTSTR lpText, _In_opt_ LPCTSTR lpCaption, _In_ UINT uType );
HWND hWnd
窗口句柄
LPCTSTR lpText
将要在信息框显示的信息
LPCTSTR lpCaption
标题栏上显示的文本
UINT uType
显示按钮的设置
winnt.h
#ifndef VOID #define VOID void typedef char CHAR; typedef short SHORT; typedef long LONG; #if !defined(MIDL_PASS) typedef int INT; #endif #endif
typedef CHAR * PCHAR, * LPCH, * PCH, * NPSTR, * LPSTR, * PSTR ; typedef CONST CHAR * LPCCH, * PCCH, * LPCSTR, * PCSTR ;
typedef WCHAR * PWCHAR, * LPWCH, * PWCH, * NWPSTR, * LPWSTR, * PWSTR ; typedef CONST WCHAR * LPCWCH, * PCWCH, * LPCWSTR, * PCWSTR ;
#ifdef UNICODE typedef WCHAR TCHAR, * PTCHAR ; typedef LPWSTR LPTCH, PTCH, PTSTR, LPTSTR ; typedef LPCWSTR LPCTSTR ; #else typedef char TCHAR, * PTCHAR ; typedef LPSTR LPTCH, PTCH, PTSTR, LPTSTR ; typedef LPCSTR LPCTSTR ; #endif
Windows程序设计是探讨在Windows操作系统这个平台上如何设计程序,从本质上讲是在研究如何通过操作系统的接口,利用操作系统的运行机制与操作系统交互,充分挖掘操作系统的潜力,写出满足我们要求的程序。
从这一点上说,Windows带有窗口的程序设计与传统黑屏的命令行程序设计性质是一样的,只不过Windows操作系统要复杂得多。