Solved

Transparent Dialog

Posted on 2000-02-28
7
341 Views
Last Modified: 2013-11-20
How can i get what is behind my dialog box and paint it to the dialog box so that it appears transparent?
0
Comment
Question by:scooter1
  • 5
  • 2
7 Comments
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2567271
You can set the WS_TRANSPARENT style odf the dialog.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2567283
oops should be WS_EX_TRANSPARENT extended style.

In the dialog resource editor there is a checkbox for this on the dialog properties.

in Win2000 there is a new WS_EX_LAYERED that does the job better .. look in the SDK docs.


0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2567294
look at the example in the VC MFC docs on ModifyStyleEX and the SDK docs on "CreateWindowEx" and "Layered Windows" and KB article Q92526
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:scooter1
ID: 2567321
Forgot to be more specific: I'm using VC++ 6.0 on an MFC dialog box based program and i don't want to set the style i want to paint whats behind it, on it. (if that's possible)
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 125 total points
ID: 2567372
Setting the style does this for you and saves all the work.

If you want to copy the screen to a bitmap, try this, supplying the rectangle you want.  Capture before the dialog is displayed, of course, and then BitBlt the appropriate region onto your dialog

HBITMAP FAR CopyScreenToBitmap(LPRECT lpRect)
{
   HDC hScrDC, hMemDC;           // screen DC and memory DC
   HBITMAP hBitmap, hOldBitmap;  // handles to deice-dependent bitmaps
   int nX, nY, nX2, nY2;         // coordinates of rectangle to grab
   int nWidth, nHeight;          // DIB width and height
   int xScrn, yScrn;             // screen resolution

   /* check for an empty rectangle */

   if (IsRectEmpty(lpRect))
      return NULL;

   /*  create a DC for the screen and create
    *  a memory DC compatible to screen DC
    */
   hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
   hMemDC = CreateCompatibleDC(hScrDC);

   /* get points of rectangle to grab */
   nX = lpRect->left;
   nY = lpRect->top;
   nX2 = lpRect->right;
   nY2 = lpRect->bottom;

   /* get screen resolution */
   xScrn = GetDeviceCaps(hScrDC, HORZRES);
   yScrn = GetDeviceCaps(hScrDC, VERTRES);

   /* make sure bitmap rectangle is visible */
   if (nX < 0)
      nX = 0;
   if (nY < 0)
      nY = 0;
   if (nX2 > xScrn)
      nX2 = xScrn;
   if (nY2 > yScrn)
      nY2 = yScrn;
   nWidth = nX2 - nX;
   nHeight = nY2 - nY;

   /* create a bitmap compatible with the screen DC */
   hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);

   /* select new bitmap into memory DC */
   hOldBitmap = SelectObject(hMemDC, hBitmap);

   /* bitblt screen DC to memory DC */
   BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY);

   /*  select old bitmap back into memory DC and get handle to
    *  bitmap of the screen
    */
   hBitmap = SelectObject(hMemDC, hOldBitmap);

   /* clean up */
   DeleteDC(hScrDC);
   DeleteDC(hMemDC);

   /* return handle to the bitmap */
   return hBitmap;
}

From WinCap example,  The WinCap32 example in the SDK (don't have it handy) is a latter example that may be a bit better, don't know.
0
 

Author Comment

by:scooter1
ID: 2567493
um, this is a little over my head, thanks though
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2567521
The way windows works, you need to create a device context for a bitmap, and then select the bitmap into the context so you can draw on in it, move it around etc.  And when creating a bitmap, you usually want it compatible with the display.

That is why the above looks so complicated -- there a lot of housekeeping.

Here is what it does (in summary)

1) makes sure you've actualyl given it a non-empty recatngle
2) get a DC for the display.  This is what we will be copying from
3) creates a DC to draw to the bitmap
4) ensure that the rectangle is within the screen rectangle
5) create the bitmap itself (compatible with the display)
6) select the bitmap into a device context so you can access it
7) copy from the screen to the bitmap
8) clean up afterwards

Anyway, the WS_EX_TRANSPARENT style should do what you want with no need to code anything.

0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 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