question

CodeWanderer-1205 avatar image
0 Votes"
CodeWanderer-1205 asked SongZhu-MSFT commented

Win32 Direct2D C++ and Borderless window (help)

How can I create borderless window with Direct2D?

In WPF I cen easely remove window border with click in XAML Designer (Blend) and check NoStyle. I want achieve same look with Win32 and Direct2D, but I am without success and ducomentation under microsoft site is only basic without any deep dive in to Win32.

I am following this tutorials https://docs.microsoft.com/en-us/windows/win32/learnwin32/your-first-direct2d-program

 MainWindow mw;
  if (!mw.Create(L"Circle"
  , WS_OVERLAPPEDWINDOW 
  /*, WS_POPUP // when using this, windows is not displaying*/
  ))
  {
  return 0;
  }

Instead WS_OVERLAPPEDWINDOW I tried use WS_POPUP, but then windows is not displayed, except I can see it on taskbar and close it but the "display area" or client area is blank.

How to make borderless window with Direct2D?


I discovered where is the problem with WS_POPUP style. When I set specific window size (before CW_USEDEFAULT was used) popup window is displayed.
Now I have additional question:
1. doeas this WS_POPUP is ok to use it as borderless window for whole application, or there are better solutions?
2. Can I compose windows style from "nothing"and add aditional controls, like border and with only close button? Where are documentation about "composing style"? Under MS documentation, I can't find those informations.


When I use this (inspired form searching over internet and @SimpleSamples post)

 ~(WS_CAPTION | WS_THICKFRAME  | WS_VSCROLL | WS_HSCROLL | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_DISABLED)

for Create(...) function I got same "look" as WS_POPUP. But it is not mentioned nowhere that I can use ~ which "disable" style and turn on another (as you can see I have to add WS_DISABLED because without it windows is disabled.



windows-apic++
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You asked about how to remove the border from a window using WS_OVERLAPPEDWINDOW. If you have a different question then please post a new question. I already posted the page listing the windows styles, except you can see from the menu in the left in that page that there are also extended styles. To answer your question about the WS_POPUP style, it depends on what you need to do. The WS_POPUP style is not designed for main windows. If you need more about that then create a new question and provide details of what you need to do.

0 Votes 0 ·

The ~ does not really disable a style. It is the C++ One's complement operator. It turns bits off that are on and turns bits on that are off. Windows styles and extended styles are bits in bytes.


0 Votes 0 ·

Thanks to clarify it. I was think that it remove styles, I copied it from some stackoverflow answers, where SetWindowLong is used and I was think that it will work with CreateWindowEX().

0 Votes 0 ·

You say without any deep dive in to Win32. I can understand that you do not want to spend a month learning about Windows. But you need to understand well enough to be able to know what to ask and how to ask. See Window Overviews - Win32 apps. If you just read that much then you will be much more able to know where to look and get help.


0 Votes 0 ·
SongZhu-MSFT avatar image
0 Votes"
SongZhu-MSFT answered SongZhu-MSFT commented

For the first question, yes, you can use WS_POPUP to create a borderless window. But using a borderless window can't keep the title bar.

And the second question, you can try to customize the drawing window, which will achieve the functions you want, such as adding title bars, window frames, etc.

More reference: Borderless window creation, Borderless Window


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks, before I accept answer, please extend your answer about WS_POPUP that windows size has to be set (even when CW_USEDEFAULT is used, it has to be replaced with exact size), becuase without it, windows will have size 0 and it will be invisible due its size. It is for future readers, who are new to windows and styles.

I am aware of that borderless window can't keep the title bar. This is purpose of borderless window, the only client area is displayed, which is what I wanted. And thanks for the link about customize the drawing window.

0 Votes 0 ·

According to the MSDN:

nWidth
if CW_USEDEFAULT is specified for a pop-up or child window, nWidth and nHeight are set to zero.

When you set the WS_POPUP style, the height and width of the window are 0, which causes you to not see the created window, so you need to set the height and width.






0 Votes 0 ·
SimpleSamples avatar image
0 Votes"
SimpleSamples answered CodeWanderer-1205 commented

See Window Styles (Winuser.h) - Win32 apps. WS_OVERLAPPEDWINDOW is actually:

 (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)

So use the following for the styles:

 (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)

For Win32 programming the Spy++ tool is useful. Look in the Visual Studio tools menu for it. Learn to use it. Using it you can look at the actual styles of windows. It does not work for all Windows applications but it works for WPF and Windows Forms applications as well as Win32 applications.



· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks, but it create basic window, without resize posibility.

0 Votes 0 ·

Well, yes. Definitely. But you asked how to remove the border. That reminds me of a sign that said something like Oh no! You did exactly what I asked for! You did not ask for a window that can be resized. You only asked for a window without a border. If you want to create a window like WPF then see what I said about Spy++ in my reply.

0 Votes 0 ·

No, it don't remove border. I don't know what you think about "border" but when I say borderless window I mean without any borders which are visaully visible. Or you didn't understand what I was wrote. It create same window as WS_OVERLAPPEDWINDOW visually.

0 Votes 0 ·

Perhaps what you want is a window without a caption, not without a border. But maybe you want a tool window. If you have a sample window that is what you want then use Spy++ to determine how to do it.

0 Votes 0 ·

I define a border as something created by a WS_BORDER, WS_DLGFRAME or WS_THICKFRAME style or a WS_EX_CLIENTEDGE, WS_EX_DLGMODALFRAME, WS_EX_STATICEDGE or WS_EX_WINDOWEDGE extended style. Borders are the typical way to resize windows. The WS_OVERLAPPEDWINDOW style includes WS_THICKFRAME. If you think you understand windows styles better than me then I should stop trying to help.

0 Votes 0 ·
Show more comments