Why does my transparent-background window turn into black screen after window ghosting?

Aditya Pingle 0 Reputation points
2024-05-10T14:33:43.0133333+00:00

I have a pop-up window that acts as a watermark on my application over a parent window. It has a transparent background (WS_EX_TRANSPARENT), but when the application becomes non-responsive, Windows adds a ghost window with a black background. I tried using different window styles, but it did not work. I'm currently attempting to show the watermark dialog in a background thread, but I would prefer a solution to fix the black background instead. Is there any way to prevent this from happening besides using DisableProcessWindowGhosting? I also don't want to go for child window as it adds another issues to my application.

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,869 questions
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,452 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,569 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Tong Xu - MSFT 2,116 Reputation points Microsoft Vendor
    2024-05-14T02:02:26.03+00:00

    Hello, @Aditya Pingle
    Welcome to Microsoft Q&A!

    I would prefer a solution to fix the black background instead.

    You want to modify the background of ghost window?
    My answer is No.

    The ghost window will replace it when top-level window stops responding in z-order, location, size, and visual attributes. You can move, resize and close but just these actions you can do. Don't try changing the attributes of ghost window.
    **
    You can see the last part of remarks.
    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    0 comments No comments

  2. RLWA32 41,206 Reputation points
    2024-05-17T10:16:52.16+00:00

    Windows will use the background brush specified in a WNDCLASS when it creates a ghost window. If that brush is the stock object NULL_BRUSH or HOLLOW_BRUSH a black background results. If the window class does not specify a background brush but the window procedure handles WM_ERASEBKGND then windows will use whatever brush the handler uses when it creates the ghost window. If the handler does not actually erase the background (simply returns TRUE/FALSE) then the black background results. Also, if the handler uses the abovementioned stock objects the ghost window will also have a black background.

    For example using Sleep() to temporarily stop pumping messages,

    GhostWindow

    To avoid the black background for a ghost window do something other than the above.