Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 348
  • Last Modified:

Transparent Dialog

How can i get what is behind my dialog box and paint it to the dialog box so that it appears transparent?
0
scooter1
Asked:
scooter1
  • 5
  • 2
1 Solution
 
RONSLOWCommented:
You can set the WS_TRANSPARENT style odf the dialog.
0
 
RONSLOWCommented:
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
 
RONSLOWCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
scooter1Author Commented:
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
 
RONSLOWCommented:
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
 
scooter1Author Commented:
um, this is a little over my head, thanks though
0
 
RONSLOWCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now