gpt4 book ai didi

c - 在C中隐藏应用程序窗口

转载 作者:行者123 更新时间:2023-11-30 16:29:50 24 4
gpt4 key购买 nike

我知道如何通过以下代码隐藏 C# 中控制台应用程序的窗口:

using System.Runtime.InteropServices;
//Insert below before the main function
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();

[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

const int SW_HIDE = 0;
const int SW_SHOW = 5;

///End of before main


//now insert this under main function


var handle = GetConsoleWindow();

// Hide
ShowWindow(handle, SW_HIDE);

// Show
ShowWindow(handle, SW_SHOW);

现在的问题是,如何在C而不是C++中隐藏窗口?我一直在寻找解决方案,但我在 C++ 中找到了所有解决方案。

最佳答案

所有 WinAPI 调用都是 C 声明(不是 C++)。

所以,你也这样做:

//don't need to declare anything just:
#include <Windows.h>

//insert this in the main function
HWND handle = GetConsoleWindow();

// Hide
ShowWindow(handle, SW_HIDE);

// Show
ShowWindow(handle, SW_SHOW);

关于c - 在C中隐藏应用程序窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51578442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com