c++ - 如何使控制台进程不打开?
问题描述
所以,我正在尝试学习如何制作 C/C++ Windows 桌面应用程序,但是我遇到了一个很大的问题,当创建一个完全正常的窗口时,会出现运行控制台应用程序的 cmd。有没有办法让它甚至不打开?我一直在看到一些方法,但它们似乎隐藏了控制台,但过程仍然存在。
这是我的代码:
#define UNICODE
#define _UNICODE
#include <Windows.h>
LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR args, int nCmdShow) {
WNDCLASSW wc = { 0 };
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hInstance = hInstance;
wc.lpszClassName = L"windowClass";
wc.lpfnWndProc = WinProc;
if (!RegisterClass(&wc))
return 1;
HWND hWnd = CreateWindow(L"windowClass", L"Window 1",
WS_OVERLAPPEDWINDOW,
100, 100,
256, 256,
NULL, NULL, NULL, NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg = { 0 };
while (GetMessage(&msg, NULL, NULL, NULL)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
DefWindowProc(hWnd, msg, wParam, lParam);
}
}
解决方案
推荐阅读
- excel - 如何在数据透视表中的多列小计中找到百分比
- ios - 在 Swift 中使用 WillSpeakRange 委托中断 AVSpeechUtterance 并恢复
- html - 可访问性:输入元素可访问性的帮助文本
- php - Composer 自动加载某些子文件夹中缺少的类
- docker - InfluxDB docker 容器磁盘使用情况
- c - STM32F207 Nucleo144板,写入永久内存
- ios - PresentationButton 没有触发两次动作
- python - 让我的 python 脚本工作并调用我的变量的问题
- angular - Executionfailed':app:mergeDebugResources'.java.util.concurrent:com.android.builder.internal.aapt.v2.Aapt2InternalException:AAPT2 aapt2-3.3.0-5013011
- php - 如何在 PHP 中将所有数组元素移动到全局范围?