26

I'm developing a C++ application for Windows. I'm using the Win32 API. How can I open a window without a title bar (without controls, icon and title) and that can not be resized.

The piece of code that I am using for the application to create a window:

hWnd = CreateWindow(szWindowClass, 0, (WS_BORDER),
                    0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL);

To do this in C#, you just define this code:

 FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
 ControlBox = false;
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
blejzz
  • 3,349
  • 4
  • 39
  • 60

6 Answers6

31
hWnd = CreateWindow(szWindowClass, 0, (WS_BORDER ), 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL); 

SetWindowLong(hWnd, GWL_STYLE, 0); //remove all window styles, check MSDN for details

ShowWindow(hWnd, SW_SHOW); //display window
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Mike
  • 1,717
  • 2
  • 15
  • 19
  • that does remove the title bar, but removes the border also, even if i do setWindowLong(hWnd, GWL_STYLE, WS_BORDER); – blejzz Sep 16 '11 at 10:29
  • 1
    Do you want to have border but don't have title? There is no way to do it. – Mike Sep 16 '11 at 10:33
  • 5
    if it is possible in .NET (c#) than it is possible in win32 (c++). A example app would be system volume (windows7) – blejzz Sep 16 '11 at 11:22
  • SetWindowLong(hWnd, GWL_STYLE, WS_SIZEBOX); does the trick, now the problem is when the window is created it isn't properly painted. If i add a menu to it it will properly render when the window is resized.. – blejzz Sep 16 '11 at 11:47
  • 3
    SetWindowLong(hwnd, GWL_STYLE, WS_BORDER | WS_THICKFRAME); SetWindowPos(hwnd, 0, 0, 0, 100, 50, SWP_FRAMECHANGED); //some trick to redraw window ShowWindow(hwnd, SW_SHOW); – Mike Sep 16 '11 at 11:59
  • it worked! thank you. update your answer and i will accept it. Btw do you happen to know how i would prevent resizing the window and changing the cursor to the resize cursor (in c# i just ignored WM_NCHITTEST message, in c++ it's a little more complicated) – blejzz Sep 16 '11 at 12:25
  • 1
    You are correct, just ignore WM_NCHITTEST message in window procedure, you can define your own window procedure in RegisterClass function, or override it after CreateWindow via SetWindowLong(hwnd, GWL_WNDPROC, YourNewWindProc) – Mike Sep 16 '11 at 14:32
  • 2
    `SetWindowLong` could be easily removed. You can use 0 instead of `WS_BORDER` but probably you want `WS_POPUP` style because 0 means `WS_OVERLAPPED`. As mentioned in the comments above, add `WS_THICKFRAME` style to get the sizing border around window, otherwise no visible border is displayed around the window. – Alexey Ivanov Jan 19 '16 at 15:58
5
HWND hWnd ;
hWnd = CreateWindow(szWindowClass, 0, (WS_BORDER ), 0, 0, 100, 100, NULL, NULL, Instance, NULL); 
SetWindowLong(hwnd, GWL_STYLE, WS_BORDER );  // With 1 point border
//OR
SetWindowLong(hwnd, GWL_STYLE, 0 );  // Without 1 point border = white rectangle 
SetWindowPos(hwnd, 0, 150, 100, 250, 250, SWP_FRAMECHANGED); 

if (!hWnd)
 return FALSE ;
else
ShowWindow(hwnd, SW_SHOW);
2

Omit the WS_BORDER style:

See CreateWindow function: http://msdn.microsoft.com/en-us/library/ms632679%28v=vs.85%29.aspx

Window Styles: http://msdn.microsoft.com/en-us/library/ms632600%28v=vs.85%29.aspx

RED SOFT ADAIR
  • 12,032
  • 10
  • 54
  • 92
  • 4
    if i omit WS_BORDER a put 0 instead, the control buttons (close,minimize,maximize) and the title doesn't display, but the title bar area is still visible(where the buttons and text is), i would like to hide it also. – blejzz Sep 16 '11 at 10:10
1
CreateWindowEx(0, szWindowClass, 0, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL);

using SetWindowLong will change the size and post. use the WS_POPUP style

Sarvan Kumar
  • 926
  • 1
  • 11
  • 27
1

We use the following instruction:

hWnd = CreateWindow(
    "Example", "Example No Title Bar", 
     WS_POPUPWINDOW | WS_VISIBLE,
     0, 0, myWindowWidth, myWindowHeight, 
     NULL, NULL, hInstance, NULL); 

Output: Window without title bar and not resizable

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
masarapmabuhay
  • 466
  • 1
  • 9
  • 15
0
SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
Talim
  • 27
  • 5
    Please edit with more information. Code-only and "try this" answers are [discouraged](http://meta.stackexchange.com/questions/196187/is-try-this-bad-practice), because they contain no searchable content, and don't explain why someone should "try this". – Rick Smith Sep 16 '15 at 17:17
  • Too bad this got voted down. It is the correct answer. Why? Because the vendor says so - try reading https://learn.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles . In case the link dies, try "WS_EX_TOOLWINDOW" in your search window and read the documentation. In my case I wanted a floating window without border or title. And...that's exactly what WS_EX_TOOLWINDOW does. I use CreateWindowExand specifying WS_EX_TOOLWINDOW for the dwExStyle parameter. – user1318024 Mar 28 '22 at 12:18