开发者

C++ Console Application, hiding the title bar

开发者 https://www.devze.com 2022-12-09 15:15 出处:网络
I have a Windows console application written in C++ and want to hide/remove the complete title bar of the c开发者_JAVA百科onsole window, including the close, min/max controls etc. I searched a lot but

I have a Windows console application written in C++ and want to hide/remove the complete title bar of the c开发者_JAVA百科onsole window, including the close, min/max controls etc. I searched a lot but didn't found anything useful yet.

I inquire the console HWND with GetConsoleWindow and tried to change the console window style with SetWindowLong by removing the WS_CAPTION flag, but this seems to have no effect at all:

HWND hwnd = GetConsoleWindow();
LONG style = GetWindowLong(hwnd, GWL_STYLE);
style &= ~(WS_BORDER|WS_CAPTION|WS_THICKFRAME);
SetWindowLong(hwnd, GWL_STYLE, style);

SetWindowPos( hwnd, NULL, 0,0,0,0,
       SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE
       |SWP_FRAMECHANGED ); 

I also tried GetSystemMenu/RemoveMenu but this seems only to disable controls like the close button.


You can't. Generally the hWnd of a console window is not guaranteed to be suitable for all window handle operations as, for example, documented here.


You could try a complex solution involving hiding the console window (this is possible), and then setup a window (without the controls) that forwards appropriate events back and forth from the real console window. In particular GDI events to draw the console window contents in your fake console window, and interact with the scrollbar (which in turn adjusts the console...).

This solution is pretty far out, and quite technical.


You can use SetWindowLongPtr(hWnd, GWL_STYLE, WS_POPUP); , which will remove the caption/titlebar and the borders.
Warning: This does introduce a few glitches that I don't know how to fix (I guess they're cached borders?), but at least it does produce the effect that you want.


I think I would write/use two programs. One console program doing the work and a second program being a controllable console window running the first one. Most probably there are already existing console programs out there and some can be started without title bar? Or find an open source one and modify it.

0

精彩评论

暂无评论...
验证码 换一张
取 消