win32开发入门

概览:

New

打开VS2019 创建新项目 -> windows桌面应用程序 (是C++类哦),源代码在文末。

裁剪

代码文件只留下framework.hmain.cpp(可能为项目名.cpp).

并在framework.h删掉#include "targetver.h",hello world不需要这些部分也可以运行。

hello world

  • main.cpp
1
2
3
4
5
6
7
8
9
// WindowsProject1.cpp : 定义应用程序的入口点。
//

#include "framework.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
MessageBox(NULL, TEXT("Hello windows,are you there?"), TEXT("Hello world"), 1);
return 0;
}
  • framework.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// header.h: 标准系统包含文件的包含文件,
// 或特定于项目的包含文件
//

#pragma once

#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容
// Windows 头文件
#include <windows.h>
// C 运行时头文件
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>

效果

Download Now