Solved

Transparent Dialog

Posted on 2000-02-28
7
339 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 120
ADO Memory leak with DELPHI 2007 37 170
Complete beginner needs help making a cron job 9 109
scoreUp challenge 14 56
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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

919 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now