views:

841

answers:

3

I have a Windows console application written in C++ and want to hide/remove the complete title bar of the console 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.

+4  A: 

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.

Joey
Ok this is good to know, so I will just forget about this and try with an alternative command prompt or leave it as it is.
asdrubael
A: 

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.

ziggystar
Yes this would be an option, to replace the cmd.exe with something like "Console":http://sourceforge.net/projects/console/
asdrubael
+1  A: 

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.

Matt Joiner