Solved

Transparent Dialog

Posted on 2000-02-28
7
338 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 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

12 Experts available now in Live!

Get 1:1 Help Now