在 Dev-C++中编译运行GUI程序介绍(三)有趣示例一组
前期见
在 Dev-C++中编译运行GUI 程序介绍(一)基础 https://blog.csdn.net/cnds123/article/details/147019078
在 Dev-C++中编译运行GUI 程序介绍(二)示例:祝福程序 https://blog.csdn.net/cnds123/article/details/147019350
本文给出一组可以在 Dev-C++中编译运行的GUI 应用程序。
示例2、简单的猜数字游戏
下面是一个简单的猜数字游戏源码,您可以在 Dev-C++ 中编译和运行它。这个程序创建了一个基本的 GUI 界面,用户可以通过输入数字来进行猜测,程序会提示用户猜的数字是太高、太低还是猜对了。并有猜中计数和“重玩”按钮功能。
运行效果:
源码如下:
#include <windows.h>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
// 全局变量
HWND hwndInput, hwndButton, hwndOutput, hwndCountLabel;
int randomNumber;
int guessCount = 0; // 猜中计数
// 生成随机数
void generateRandomNumber() {
randomNumber = rand() % 100 + 1; // 生成 1 到 100 之间的随机数
guessCount = 0; // 重置猜中计数
}
// 消息处理函数
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CREATE: {
// 创建说明标签
CreateWindow("STATIC", "请输入1到100之间的数字:", WS_CHILD | WS_VISIBLE,
50, 20, 200, 25, hwnd, NULL, NULL, NULL);
// 创建输入框
hwndInput = CreateWindow("EDIT", "", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER,
50, 50, 100, 25, hwnd, NULL, NULL, NULL);
// 创建猜测按钮
hwndButton = CreateWindow("BUTTON", "猜测", WS_CHILD | WS_VISIBLE,
50, 100, 100, 30, hwnd, (HMENU)1, NULL, NULL);
// 创建重玩按钮
CreateWindow("BUTTON", "重玩", WS_CHILD | WS_VISIBLE,
160, 100, 100, 30, hwnd, (HMENU)2, NULL, NULL);
// 创建输出框
hwndOutput = CreateWindow("STATIC", "", WS_CHILD | WS_VISIBLE,
50, 150, 200, 25, hwnd, NULL, NULL, NULL);
// 创建猜中计数标签
hwndCountLabel = CreateWindow("STATIC", "猜测次数: 0", WS_CHILD | WS_VISIBLE,
50, 180, 200, 25, hwnd, NULL, NULL, NULL);
generateRandomNumber(); // 生成第一个随机数
// 设置光标焦点到输入框
SetFocus(hwndInput);
break;
}
case WM_COMMAND: {
if (LOWORD(wParam) == 1) { // 按钮被点击
char buffer[10];
GetWindowText(hwndInput, buffer, sizeof(buffer)); // 获取输入的文本
int guess = atoi(buffer); // 将字符串转换为整数
// 进行猜测判断
string message;
guessCount++; // 增加猜测次数
if (guess < randomNumber) {
message = "太低了!";
} else if (guess > randomNumber) {
message = "太高了!";
} else {
message = "恭喜你,猜对了!";
// 不重置猜测次数,直到用户选择“重玩”
}
// 更新输出框和猜中计数标签
SetWindowText(hwndOutput, message.c_str());
SetWindowText(hwndCountLabel, ("猜测次数: " + to_string(guessCount)).c_str());
// 设置光标焦点到输入框
SetFocus(hwndInput);
}
else if (LOWORD(wParam) == 2) { // 重玩按钮被点击
generateRandomNumber(); // 生成新的随机数
SetWindowText(hwndOutput, ""); // 清空输出框
SetWindowText(hwndCountLabel, "猜测次数: 0"); // 重置猜中计数
SetWindowText(hwndInput, ""); // 清空输入框
SetFocus(hwndInput); // 设置光标焦点到输入框
}
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
srand(static_cast<unsigned int>(time(0))); // 设置随机种子
// 注册窗口类
const char CLASS_NAME[] = "GuessNumberWindow";
WNDCLASS wc = {};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// 创建窗口
HWND hwnd = CreateWindowEx(0, CLASS_NAME, "猜数字游戏", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// 消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
示例3、剪子、包袱、锤游戏
剪子、包袱、锤(又称石头剪刀布)游戏规则
胜负关系:
剪子 胜 包袱(剪刀剪开布)。
包袱 胜 锤(布包裹石头)。
锤 胜 剪子(石头砸坏剪刀)。
手势相同:平局,重新对决。
界面如下
源码如下:
//剪子、包袱、锤游戏
#include <windows.h>
#include <string>
#include <cstdlib>
#include <ctime>
#include <sstream>
using namespace std;
// 全局变量
HWND hwndOutput, hwndComputerChoice;
int computerChoice;
// 生成计算机的选择
void generateComputerChoice() {
computerChoice = rand() % 3; // 0 = 剪子, 1 = 包袱, 2 = 锤
}
// 消息处理函数
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CREATE: {
// 创建剪子按钮
CreateWindow("BUTTON", "剪子 (X)", WS_CHILD | WS_VISIBLE,
50, 50, 100, 30, hwnd, (HMENU)1, NULL, NULL);
// 创建包袱按钮
CreateWindow("BUTTON", "包袱 (Q)", WS_CHILD | WS_VISIBLE,
50, 100, 100, 30, hwnd, (HMENU)2, NULL, NULL);
// 创建锤按钮
CreateWindow("BUTTON", "锤 (P)", WS_CHILD | WS_VISIBLE,
50, 150, 100, 30, hwnd, (HMENU)3, NULL, NULL);
// 创建新局按钮
CreateWindow("BUTTON", "新局", WS_CHILD | WS_VISIBLE,
50, 200, 100, 30, hwnd, (HMENU)4, NULL, NULL);
// 创建输出框
hwndOutput = CreateWindow("STATIC", "", WS_CHILD | WS_VISIBLE,
200, 50, 200, 100, hwnd, NULL, NULL, NULL);
// 创建计算机选择显示框
hwndComputerChoice = CreateWindow("STATIC", "", WS_CHILD | WS_VISIBLE,
200, 150, 200, 25, hwnd, NULL, NULL, NULL);
// 设置随机种子
srand(static_cast<unsigned int>(time(0)));
break;
}
case WM_COMMAND: {
if (LOWORD(wParam) >= 1 && LOWORD(wParam) <= 3) { // 剪子、包袱或锤按钮被点击
int userChoice = LOWORD(wParam) - 1; // 0 = 剪子, 1 = 包袱, 2 = 锤
generateComputerChoice(); // 生成计算机选择
// 计算机选择对应的输出来显示
string computerChoiceStr;
if (computerChoice == 0) computerChoiceStr = "剪子 (X)";
else if (computerChoice == 1) computerChoiceStr = "包袱 (Q)";
else if (computerChoice == 2) computerChoiceStr = "锤 (P)";
// 判断输赢
string result;
if (userChoice == computerChoice) {
result = "平局!";
} else if ((userChoice == 0 && computerChoice == 1) ||
(userChoice == 1 && computerChoice == 2) ||
(userChoice == 2 && computerChoice == 0)) {
result = "你输了!";
} else {
result = "你赢了!";
}
// 更新输出框和计算机选择框
SetWindowText(hwndOutput, result.c_str());
SetWindowText(hwndComputerChoice, ("计算机选择: " + computerChoiceStr).c_str());
} else if (LOWORD(wParam) == 4) { // 新局按钮被点击
SetWindowText(hwndOutput, ""); // 清空输出框
SetWindowText(hwndComputerChoice, ""); // 清空计算机选择框
}
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
// 注册窗口类
const char CLASS_NAME[] = "RockPaperScissorsWindow";
WNDCLASS wc = {};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// 创建窗口
HWND hwnd = CreateWindowEx(0, CLASS_NAME, "剪子、包袱、锤游戏", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 420, 300, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// 消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
示例4、简单计算器
可以在 Dev-C++ 中编译和运行简单计算器(通过计算机键盘输入数)。
界面如下:
代码如下:
#include <windows.h>
#include <string>
#include <sstream>
using namespace std;
// 全局变量
HWND hwndInput1, hwndInput2, hwndOutput, hwndButtonAdd, hwndButtonSub, hwndButtonMul, hwndButtonDiv;
// 计算结果并显示
void Calculate(char operation) {
char buffer1[100], buffer2[100];
GetWindowText(hwndInput1, buffer1, sizeof(buffer1)); // 获取第一个输入框的文本
GetWindowText(hwndInput2, buffer2, sizeof(buffer2)); // 获取第二个输入框的文本
double num1 = atof(buffer1); // 转换为 double
double num2 = atof(buffer2); // 转换为 double
double result = 0.0;
// 根据操作符进行计算
switch (operation) {
case '+': result = num1 + num2; break;
case '-': result = num1 - num2; break;
case '*': result = num1 * num2; break;
case '/':
if (num2 != 0) {
result = num1 / num2;
} else {
SetWindowText(hwndOutput, "错误:除以零");
return;
}
break;
}
// 显示结果
stringstream ss;
ss << result;
SetWindowText(hwndOutput, ss.str().c_str());
}
// 消息处理函数
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CREATE: {
// 创建输入框1
hwndInput1 = CreateWindow("EDIT", "", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER,
50, 20, 100, 30, hwnd, NULL, NULL, NULL);
// 创建输入框2
hwndInput2 = CreateWindow("EDIT", "", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER,
50, 60, 100, 30, hwnd, NULL, NULL, NULL);
// 创建输出框
hwndOutput = CreateWindow("STATIC", "", WS_CHILD | WS_VISIBLE,
50, 100, 200, 30, hwnd, NULL, NULL, NULL);
// 创建加法按钮
hwndButtonAdd = CreateWindow("BUTTON", "+", WS_CHILD | WS_VISIBLE,
200, 20, 30, 30, hwnd, (HMENU)1, NULL, NULL);
// 创建减法按钮
hwndButtonSub = CreateWindow("BUTTON", "-", WS_CHILD | WS_VISIBLE,
200, 60, 30, 30, hwnd, (HMENU)2, NULL, NULL);
// 创建乘法按钮
hwndButtonMul = CreateWindow("BUTTON", "*", WS_CHILD | WS_VISIBLE,
250, 20, 30, 30, hwnd, (HMENU)3, NULL, NULL);
// 创建除法按钮
hwndButtonDiv = CreateWindow("BUTTON", "/", WS_CHILD | WS_VISIBLE,
250, 60, 30, 30, hwnd, (HMENU)4, NULL, NULL);
break;
}
case WM_COMMAND: {
if (LOWORD(wParam) == 1) { // 加法按钮被点击
Calculate('+');
} else if (LOWORD(wParam) == 2) { // 减法按钮被点击
Calculate('-');
} else if (LOWORD(wParam) == 3) { // 乘法按钮被点击
Calculate('*');
} else if (LOWORD(wParam) == 4) { // 除法按钮被点击
Calculate('/');
}
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
// 注册窗口类
const char CLASS_NAME[] = "SimpleCalculator";
WNDCLASS wc = {};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// 创建窗口
HWND hwnd = CreateWindowEx(0, CLASS_NAME, "简单计算器", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 200, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// 消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
示例5、改进版的简单计算器
下面是一个改进版的简单计算器,界面上包含数字按键(0-9)和基本的运算按键(加、减、乘、除)。用户可以通过点击数字按键和运算符按键来输入数字和运算,然后按下“=”按钮来计算结果。
界面如下:
代码如下:
#include <windows.h>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
// 全局变量
HWND hwndDisplay;
string currentInput = ""; // 当前输入
// 更新显示框
void UpdateDisplay() {
SetWindowText(hwndDisplay, currentInput.c_str());
}
// 处理数字和操作符的按钮点击
void ButtonClick(char value) {
currentInput += value; // 追加输入
UpdateDisplay();
}
// 计算结果并显示
void Calculate() {
double num1 = 0.0, num2 = 0.0;
char operation = '+';
size_t pos = 0;
// 解析输入
for (char c : currentInput) {
if (c == '+' || c == '-' || c == '*' || c == '/') {
num1 = atof(currentInput.substr(0, pos).c_str());
operation = c;
pos++;
break;
}
pos++;
}
if (pos < currentInput.length()) {
num2 = atof(currentInput.substr(pos).c_str());
} else {
return; // 没有足够的输入进行计算
}
double result = 0.0;
// 根据操作符进行计算
switch (operation) {
case '+': result = num1 + num2; break;
case '-': result = num1 - num2; break;
case '*': result = num1 * num2; break;
case '/':
if (num2 != 0) {
result = num1 / num2;
} else {
currentInput = "错误:除以零";
UpdateDisplay();
return;
}
break;
}
// 显示结果
stringstream ss;
ss << result;
currentInput = ss.str(); // 更新为结果
UpdateDisplay();
}
// 消息处理函数
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CREATE: {
// 创建显示框
hwndDisplay = CreateWindow("EDIT", "", WS_CHILD | WS_VISIBLE | ES_RIGHT | ES_READONLY,
10, 10, 280, 30, hwnd, NULL, NULL, NULL);
// 创建按钮
const char* buttons[] = {"7", "8", "9", "+",
"4", "5", "6", "-",
"1", "2", "3", "*",
"0", ".", "=", "/"};
int x = 10, y = 50;
for (int i = 0; i < 16; ++i) {
CreateWindow("BUTTON", buttons[i], WS_CHILD | WS_VISIBLE,
x, y, 65, 40, hwnd, (HMENU)(INT_PTR)(i + 1), NULL, NULL);
x += 70;
if ((i + 1) % 4 == 0) {
x = 10;
y += 45;
}
}
// 创建"清空"按钮
CreateWindow("BUTTON", "清空", WS_CHILD | WS_VISIBLE,
10, 230, 280, 30, hwnd, (HMENU)17, NULL, NULL);
break;
}
case WM_COMMAND: {
int id = LOWORD(wParam);
if (id >= 1 && id <= 16) {
const char* buttonValues[] = {"7", "8", "9", "+",
"4", "5", "6", "-",
"1", "2", "3", "*",
"0", ".", "=", "/"};
if (buttonValues[id - 1][0] == '=') {
Calculate();
} else {
ButtonClick(buttonValues[id - 1][0]);
}
} else if (id == 17) { // 清空按钮
currentInput = "";
UpdateDisplay();
}
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
// 注册窗口类
const char CLASS_NAME[] = "SimpleCalculator";
WNDCLASS wc = {};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// 创建窗口
HWND hwnd = CreateWindowEx(0, CLASS_NAME, "手持计算器", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 315, 310, NULL, NULL, hInstance, NULL);
if (hwnd == NULL) {
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// 消息循环
MSG msg = {};
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
示例6、绘制直线、圆和三角形
Windows API中的GDI(Graphics Device Interface,图形设备接口)是一个用于处理图形和图像输出的子系统。它允许程序与各种输出设备(如显示器、打印机等设备无关性)进行交互,绘制图形、文本和图像。
GDI的作用
- 绘制图形:GDI提供了一系列函数,用于绘制基本形状(如线条、矩形、圆形、多边形等)。程序员可以使用这些函数在窗口上绘制想要的图形。
- 文本处理:GDI也可以用于绘制文本。它支持多种字体和文本格式,程序员可以选择字体、大小和颜色来显示文本。
- 图像处理:GDI能够加载并显示位图(BMP)、图标等图像格式。程序员可以将图像绘制到窗口或打印机上。
- 设备无关性:GDI使得程序可以不依赖于特定的硬件设备。无论是在显示器上绘制,还是在打印机上输出,GDI提供的接口都是一致的。这意味着,程序可以在不同的输出设备上运行,而不需要进行太多修改。
- 设备上下文(DC):在GDI中,设备上下文是一种数据结构,表示绘图设备的状态。程序在绘图时需要获取设备上下文,以便使用它来进行绘图操作。
GDI的基本操作
- 创建窗口:在窗口上绘制图形的第一步是创建一个窗口。这可以通过Windows API中的函数来实现。
- 获取设备上下文:在绘制之前,程序需要获取窗口的设备上下文(HDC),这样才能在窗口上进行绘制。
- 绘制操作:
- 使用GDI函数绘制图形(如MoveToEx和LineTo绘制直线)。
- 使用TextOut函数绘制文本。
- 使用BitBlt函数复制图像。
- 释放资源:绘制完成后,程序需要释放获取的设备上下文,以避免资源泄露。
先看效果图:
源码如下:
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// 设置颜色
HPEN hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 255)); // 蓝色
SelectObject(hdc, hPen);
// 画直线
MoveToEx(hdc, 50, 50, NULL); // 起点
LineTo(hdc, 200, 50); // 终点
// 画圆
Ellipse(hdc, 50, 70, 150, 170); // x1, y1, x2, y2
// 画三角形
POINT vertices[] = { {200, 70}, {250, 170}, {150, 170} };
Polygon(hdc, vertices, 3);
// 释放资源
DeleteObject(hPen);
EndPaint(hwnd, &ps);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
const char CLASS_NAME[] = "SampleWindowClass";
WNDCLASS wc = {};
wc.lpfnWndProc = WndProc; // 设置窗口过程
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// 创建窗口
HWND hwnd = CreateWindowEx(0, CLASS_NAME, "绘图示例", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 400, NULL, NULL, hInstance, NULL);
if (hwnd == NULL) {
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// 消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
示例7、绘制红五角星
使用Windows API中的GDI (图形设备接口)。
先看效果图:
源码如下:
#include <windows.h>
#include <math.h>
#define M_PI 3.14159265358979323846 // 定义π(如未定义)
// 计算五角星顶点的函数
void DrawStar(HDC hdc, int centerX, int centerY, int size) {
POINT points[10];
double angle;
int i;
// 计算五角星的顶点
for (i = 0; i < 10; i++) {
angle = (i * 36.0) * (M_PI / 180.0); // 角度转换为弧度
// 外部顶点
if (i % 2 == 0) {
points[i].x = centerX + (int)(size * cos(angle));
points[i].y = centerY - (int)(size * sin(angle));
}
// 内部顶点
else {
points[i].x = centerX + (int)(size * 0.5 * cos(angle));
points[i].y = centerY - (int)(size * 0.5 * sin(angle));
}
}
// 绘制五角星
HPEN hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0)); // 红色
SelectObject(hdc, hPen);
SelectObject(hdc, GetStockObject(NULL_BRUSH)); // 无填充
Polygon(hdc, points, 10); // 绘制五角星
// 释放资源
DeleteObject(hPen);
}
// 消息处理函数
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// 设置背景颜色
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
// 绘制红五角星
DrawStar(hdc, 200, 150, 100);
EndPaint(hwnd, &ps);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
const char CLASS_NAME[] = "StarDrawingWindow";
WNDCLASS wc = {};
wc.lpfnWndProc = WndProc; // 设置窗口过程
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// 创建窗口
HWND hwnd = CreateWindowEx(0, CLASS_NAME, "绘制红五角星", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, NULL, NULL, hInstance, NULL);
if (hwnd == NULL) {
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// 消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}