mingw-gcc编译窗体和console

news/2025/2/12 8:34:12/

下面这段程序,如果用-mconsole选项编译,出来的窗体就会带上命令行,用-mwindows则不会有。

#include <windows.h>/* This is where all the input to the window goes to */
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {switch(Message) {/* Upon destruction, tell the main thread to stop */case WM_DESTROY: {PostQuitMessage(0);break;}/* All other messages (a lot of them) are processed using default procedures */default:return DefWindowProc(hwnd, Message, wParam, lParam);}return 0;
}/* The 'main' function of Win32 GUI programs: this is where execution starts */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {WNDCLASSEX wc; /* A properties struct of our window */HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */MSG msg; /* A temporary location for all messages *//* zero out the struct and set the stuff we want to modify */memset(&wc,0,sizeof(wc));wc.cbSize		 = sizeof(WNDCLASSEX);wc.lpfnWndProc	 = WndProc; /* This is where we will send messages to */wc.hInstance	 = hInstance;wc.hCursor		 = LoadCursor(NULL, IDC_ARROW);/* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);wc.lpszClassName = "WindowClass";wc.hIcon		 = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */wc.hIconSm		 = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */if(!RegisterClassEx(&wc)) {MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);return 0;}hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Caption",WS_VISIBLE|WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, /* x */CW_USEDEFAULT, /* y */640, /* width */480, /* height */NULL,NULL,hInstance,NULL);if(hwnd == NULL) {MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);return 0;}/*This is the heart of our program where all input is processed and sent to WndProc. Note that GetMessage blocks code flow until it receives something, sothis loop will not produce unreasonably high CPU usage*/while(GetMessage(&msg, NULL, 0, 0) > 0) { /* If no error is received... */TranslateMessage(&msg); /* Translate key codes to chars if present */DispatchMessage(&msg); /* Send it to WndProc */}return msg.wParam;
}

http://www.ppmy.cn/news/1224744.html

相关文章

关于新能源汽车的英语翻译

近年来&#xff0c;随着全球对环保和可持续发展的重视&#xff0c;新能源汽车已经成为汽车产业的重要发展方向。各国政府和企业都在加大投入&#xff0c;推动新能源汽车的技术研发和产业化发展&#xff0c;进而促进了新能源汽车翻译的需求不断提升 。那么&#xff0c;关于新能源…

深度学习中文汉字识别 计算机竞赛

文章目录 0 前言1 数据集合2 网络构建3 模型训练4 模型性能评估5 文字预测6 最后 0 前言 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分享的是 &#x1f6a9; 深度学习中文汉字识别 该项目较为新颖&#xff0c;适合作为竞赛课题方向&#xff0c;学长非常推荐&#xf…

Python winreg将cmd/PowerShell(管理员)添加到右键菜单

效果 1. 脚本 用管理员权限运行&#xff0c;重复执行会起到覆盖效果&#xff08;根据sub_key&#xff09;。 icon自己设置。text可以自定义。sub_key可以改但不推荐&#xff08;避免改成和系统已有项冲突的&#xff09;。command不要改。 from winreg import *registry r&q…

【六袆 - MySQL】SQL优化;Explain SQL执行计划分析;

Explain SQL执行计划分析 概念:English Unit案例分析1.分析的SQL2.执行计划分析 【如图】MySQL执行计划参数以及它们的影响或意义:概念: MySQL执行计划(Execution Plan)是数据库系统根据查询语句生成的一种执行策略,用于指导数据库引擎执行查询操作。 English Unit This…

企业微信H5开发遇到的坑

企业微信官方推荐wx.agentConfig引用<script src"https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js"></script>是没有效果的 必须引用以下代码才有效果&#xff0c;这也是我看了社区的回答才有所收获&#xff0c;是一个坑 且VUE引用在线的…

【cpolar】Ubuntu本地快速搭建web小游戏网站,公网用户远程访问

&#x1f3a5; 个人主页&#xff1a;深鱼~&#x1f525;收录专栏&#xff1a;cpolar&#x1f304;欢迎 &#x1f44d;点赞✍评论⭐收藏 目录 前言 1. 本地环境服务搭建 2. 局域网测试访问 3. 内网穿透 3.1 ubuntu本地安装cpolar 3.2 创建隧道 3.3 测试公网访问 4. 配置…

python3:print()打印. 2023-11-18

Python3 print ()不换行输出 import random # 导入random for i in range(10):print(random.randint(1,999), end",") #random.randint(1,999)随机返回1-999间任意一个整数,包括1和999 #print()添加end"" 自定义参数&#xff0c;实现不换行输出效果.end的…

LINUX入门篇【6】----第一个LINUX小程序---进度条及相关知识讲解

前言&#xff1a; 本篇我们将开始尝试构建我们的第一个LINUX的小程序----进度条作为一个十分常见的程序&#xff0c;在我们之后的工程实践中也是需要多次运用&#xff0c;但是介于我们目前还没有去学习网络等方面的知识&#xff0c;没法独立的去利用程序去下载一个真正的程序&…