今天跟着微软的文档和一些博客写了个win32的hello world。
因为代码注释写的比较详细了就不加太多描述了。
这里放一下文档链接和博客链接:
微软文档:创建传统的 Windows 桌面应用程序 (c + +)
参考博客1:跟我一起玩Win32开发(2):完整的开发流程
参考博客2:Win32 API编程简介Demo程序
参考博客3:Windows SDK编程 API入门系列之一:那‘烦人’的Windows数据类型
1、典型的Windows程序结构
图来自参考博客2
2、代码结构
1、 头文件
#include <windows.h>
#include <tchar.h>
2、程序入口点
int CALLBACK WinMain(
_In_ HINSTANCE hInstance,
_In_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nCmdShow
);
- 窗口信息
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);
- 注册WNDCLASSEX
if (!RegisterClassEx(&wcex))
{
MessageBox(NULL,
_T("Call to RegisterClassEx failed!"),
_T("Windows Desktop Guided Tour"),
NULL);
return 1;
}
- 创建窗口
static TCHAR szWindowClass[] = _T("Desk