windows程序设计.第一个windos程序

Windows程序设计(第5版)

windows程序需要调用API。

第一个Windows程序

1 /*HelloMsg.c -- Displays "Hello World!" in a message box*/
2 #include <Windows.h>
3 
4 int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd) 
5 { 
6     MessageBox(NULL, TEXT("Hello World!"), TEXT("HelloMsg"), 0);
7     return 0; 
8 }

  
头文件:

  windows.h 包含了若干其他windows头文件。列举几个最重要、最基本的头文件:

    WINDEF.H    基本数据类型定义

    WINNT.H     支持Unicode的类型定义

    WINBASE.H  内核函数

    WINUSER.H  用户界面函数

    WINGDI.H    图形设备接口函数

程序入口:

  windows程序的入口是WinMain(),在WinBase.h中可以查看

1 WinMain (
2     _In_ HINSTANCE hInstance,
3     _In_opt_ HINSTANCE hPrevInstance,
4     _In_ LPSTR lpCmdLine,
5     _In_ int nShowCmd
6     );

MessageBox函数:

  在WinUser.h中能查看到

1 MessageBox(
2     _In_opt_ HWND hWnd,
3     _In_opt_ LPCSTR lpText,
4     _In_opt_ LPCSTR lpCaption,
5     _In_ UINT uType);

   第四个参数,可以使用在WinUser.h中定义的相关常量。

 1 /*
 2  * MessageBox() Flags
 3  */
 4 #define MB_OK                       0x00000000L
 5 #define MB_OKCANCEL                 0x00000001L
 6 #define MB_ABORTRETRYIGNORE         0x00000002L
 7 #define MB_YESNOCANCEL              0x00000003L
 8 #define MB_YESNO                    0x00000004L
 9 #define MB_RETRYCANCEL              0x00000005L
10 #if(WINVER >= 0x0500)
11 #define MB_CANCELTRYCONTINUE        0x00000006L
12 #endif /* WINVER >= 0x0500 */
13 
14 
15 #define MB_ICONHAND                 0x00000010L
16 #define MB_ICONQUESTION             0x00000020L
17 #define MB_ICONEXCLAMATION          0x00000030L
18 #define MB_ICONASTERISK             0x00000040L
19 
20 #if(WINVER >= 0x0400)
21 #define MB_USERICON                 0x00000080L
22 #define MB_ICONWARNING              MB_ICONEXCLAMATION
23 #define MB_ICONERROR                MB_ICONHAND
24 #endif /* WINVER >= 0x0400 */
25 
26 #define MB_ICONINFORMATION          MB_ICONASTERISK
27 #define MB_ICONSTOP                 MB_ICONHAND
28 
29 #define MB_DEFBUTTON1               0x00000000L
30 #define MB_DEFBUTTON2               0x00000100L
31 #define MB_DEFBUTTON3               0x00000200L
32 #if(WINVER >= 0x0400)
33 #define MB_DEFBUTTON4               0x00000300L
34 #endif /* WINVER >= 0x0400 */
35 
36 #define MB_APPLMODAL                0x00000000L
37 #define MB_SYSTEMMODAL              0x00001000L
38 #define MB_TASKMODAL                0x00002000L
39 #if(WINVER >= 0x0400)
40 #define MB_HELP                     0x00004000L // Help Button
41 #endif /* WINVER >= 0x0400 */
42 
43 #define MB_NOFOCUS                  0x00008000L
44 #define MB_SETFOREGROUND            0x00010000L
45 #define MB_DEFAULT_DESKTOP_ONLY     0x00020000L
46 
47 #if(WINVER >= 0x0400)
48 #define MB_TOPMOST                  0x00040000L
49 #define MB_RIGHT                    0x00080000L
50 #define MB_RTLREADING               0x00100000L
51 
52 #endif /* WINVER >= 0x0400 */
53 
54 #ifdef _WIN32_WINNT
55 #if (_WIN32_WINNT >= 0x0400)
56 #define MB_SERVICE_NOTIFICATION          0x00200000L
57 #else
58 #define MB_SERVICE_NOTIFICATION          0x00040000L
59 #endif
60 #define MB_SERVICE_NOTIFICATION_NT3X     0x00040000L
61 #endif
62 
63 #define MB_TYPEMASK                 0x0000000FL
64 #define MB_ICONMASK                 0x000000F0L
65 #define MB_DEFMASK                  0x00000F00L
66 #define MB_MODEMASK                 0x00003000L
67 #define MB_MISCMASK                 0x0000C000L

  

原文地址:https://www.cnblogs.com/protogenoi/p/9020121.html