Win32 Direct2D C++ and Borderless window (help)

Code Wanderer 396 Reputation points
2021-05-10T16:51:08.473+00:00

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://learn.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 @Sam of Simple Samples 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 API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,352 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,441 questions
{count} votes

Accepted answer
  1. Song Zhu - MSFT 906 Reputation points
    2021-05-11T02:06:05.433+00:00

    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.


1 additional answer

Sort by: Most helpful
  1. Sam of Simple Samples 5,516 Reputation points
    2021-05-10T18:19:03.17+00:00

    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.