Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Making a transparent dialog

Posted on 2003-11-21
9
Medium Priority
?
542 Views
Last Modified: 2013-11-20
I am trying to make a transparent dialog. I have succeeded using a bitmap mask to set the windows region to render, however I need to animate the control within the dialog, and this does not work so well with the masking method.

I have managed to make the background appear transparent by intercepting WM_ERASBKGD, however the background moves with the dialog when it is dragged.

I am assuming that what I need to do is repaint all the windows behind my dialog when it is moved. Does this sound right? And if this is the right way to go about it, how do I repaint other windows?

200 points is for if someone can tell me the method and point me in the right direction. If there is a nice full solution or example someone can give me there are more points up for grabs.
0
Comment
Question by:completecontrol
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
9 Comments
 
LVL 19

Accepted Solution

by:
Dexstar earned 800 total points
ID: 9798412
@completecontrol:

If you want to make a window transparent, then it is easiest to use the Windows API function to do it.  It only works on Windows 2000 or higher, but the code looks like this:

      #ifndef WS_EX_LAYERED
      #define WS_EX_LAYERED           0x00080000
      #define LWA_COLORKEY            0x00000001
      #define LWA_ALPHA               0x00000002
      #endif // ifndef WS_EX_LAYERED

      // Preparation for the function we want to import from USER32.DLL
      typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);

      BOOL MakeWindowTransparent( CWnd* pWnd, BYTE nTransLevel )
      {
            BOOL bSuccess = FALSE;
            OSVERSIONINFO os = { sizeof(os) };
            ::GetVersionEx( &os );

            if ( VER_PLATFORM_WIN32_NT == os.dwPlatformId && os.dwMajorVersion >= 5 )
            {
                  lpfnSetLayeredWindowAttributes pSetLayeredWindowAttributes;

                  // Here we import the function from USER32.DLL
                  HMODULE hUser32 = ::GetModuleHandle(_T("USER32.DLL"));
                  pSetLayeredWindowAttributes =
                        (lpfnSetLayeredWindowAttributes)::GetProcAddress( hUser32, "SetLayeredWindowAttributes" );

                  if ( pSetLayeredWindowAttributes )
                  {
                        pWnd->ModifyStyleEx( 0, WS_EX_LAYERED );
                        bSuccess = pSetLayeredWindowAttributes( pWnd->m_hWnd, 0, nTransLevel, LWA_ALPHA );
                  }

                  ::FreeLibrary( hUser32 );
            }
            return bSuccess;
      }

The "nTransLevel" value is how transparent you want the window to be.  255 = Invisible, 0 = Totally Visible.  So, to set it to be 50/50, you would do this:
     MakeWindowTransparent( wnd, 128 );


Hope That Helps,
Dex*
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9798418
@completecontrol:

That function will work on any version of Windows... It just won't set the transparency on version of Windows before 2000.

Dex*
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9798513
@completecontrol:

Finally, here is a link that explains everything in more detail:  http://www.codeproject.com/win32/quaker1.asp

Dex*
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 45

Expert Comment

by:AndyAinscow
ID: 9802154
Your dialog will receive a WM_MOVE message when it is being moved.  Here you need to repaint the background of your dialog.
Maybe have a flag (bool member var) that switches on/off the normal erase background handler you have customised.
Other windows should repaint themselves normally.
0
 

Author Comment

by:completecontrol
ID: 9811718
Thanks for your help. Something urgent has come up at work, so I can't work on this till later in the week. I haven't abandoned the thread though. I'll try your suggestions and see how they go. One thing I should have mentioned though - it has to work on Win98 which is why I was using the SetWindowRgn method. What I really need help on is the repainting stuff.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 9812733
The MW_MOVE and WM_ERASEBACKGROUND should apply to Win98 without any problems.
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9819199
Well, that won't work under Win98, but I'm not sure of anything that will.  When you say you need to make it "transparent", do you mean you need to make it so that you can half see your window and half see what's under it, or you do just want to set a region of the dialog to be completely clear (essentially, make a window that isn't a rectangle)?

Dex*
0
 

Author Comment

by:completecontrol
ID: 9884546
Sorry about not getting back here. I haven't had a chance to work on the project since I first posted. I don't know whne I will either so I am going to award the points to Dexstar for replies above and beyond the call of duty
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9884589
Thank you!  Good luck with that in the future!

D*
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question