全屏运行 C++ 控制台程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4053554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running a C++ Console Program in full screen
提问by Sudantha
How to run a C++ Console Program in full screen ? , using VS2008
如何全屏运行 C++ 控制台程序?, 使用 VS2008
回答by Cristian Adam
Just tested this with cl fullscreen.cpp
:
刚刚测试了这个cl fullscreen.cpp
:
#include <iostream>
#include <windows.h>
#pragma comment(lib, "user32")
int main()
{
::SendMessage(::GetConsoleWindow(), WM_SYSKEYDOWN, VK_RETURN, 0x20000000);
std::cout << "Hello world from full screen app!" << std::endl;
std::cin.get();
}
Unfortunatelly it had duplicated the text on the second monitor :)
不幸的是,它在第二台显示器上复制了文本:)
回答by user3127325
try:
尝试:
#include <iostream>
using namespace std;
int main(){
system("mode 650");
system("pause");
return 0;
}
回答by Jonas
#include <windows.h>
SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE),CONSOLE_FULLSCREEN_MODE,0);
回答by Hans Passant
There are not a lot of video adapters around these days that still support this. Run cmd.exe and press Alt+Enter. If you get a message box that says "This system does not support fullscreen mode" then you're done. If it does switch to full screen then you can use SetConsoleDisplayMode() in your main() function. Of course, you don't know what your customer's machine is like, best not to pursue this.
如今,仍然支持这一点的视频适配器并不多。运行 cmd.exe 并按 Alt+Enter。如果您收到一个消息框,显示“此系统不支持全屏模式”,那么您就完成了。如果它确实切换到全屏,那么您可以在 main() 函数中使用 SetConsoleDisplayMode()。当然,你不知道你客户的机器是什么样的,最好不要追求这个。
回答by pitrex29
That's what I'm using:
这就是我正在使用的:
system("mode con COLS=700");
ShowWindow(GetConsoleWindow(),SW_MAXIMIZE);
SendMessage(GetConsoleWindow(),WM_SYSKEYDOWN,VK_RETURN,0x20000000);
It removes the scrollbar :D
它删除了滚动条:D
回答by Andrew
For full screen windowed mode: ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
对于全屏窗口模式: ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
回答by Taohidul Islam
Just add this line (anywhere) before your output,
只需在输出之前添加这一行(任何地方),
system("mode 650");
Such as,
如,
#include<bits/stdc++.h>
using namespace std;
int main(){
system("mode 650");
cout<<"Hey, this words are shown in full screen console! "<<endl;
return 0;
}
回答by Flinsch
Just a workaround: You could use some sort of earlier DOS video modi, for example...
只是一种解决方法:您可以使用某种较早的 DOS 视频 modi,例如...
asm
{
mov ax, 13h
push bp
int 10h
pop bp
}
...to have a resolution of 320x200 pixels.
...具有 320x200 像素的分辨率。
But I'm not sure if this would work for a windows application... Probably not!
但我不确定这是否适用于 Windows 应用程序......可能不会!