0
votes

I have the HDC=hdc of a bit map, a rectangle R with logical coordinates in hdc, and the HWND=hwnd of a scroll control created by CreateWindow with SBS_HORZ. The scroll control is is the child of another window. I want to display the scroll control on the bitmap in rectangle R.

I obtained a HDC for the scroll control and used BitBlt to copy the control to the rectangle. All works well if the entire scroll control is visible in it's parent BUT if the scroll bar is obscured, I get what ever is on top of the bar. If the control is off the screen I get nothing.

This is all part of an effort to periodically save a screen image of the app in case you are wondering how the scroll bar can be obscured. I do not want to bring the scroll bar's parent to the front.

Is there anyway I can get a true image of the scroll bar in these conditions?

Or alternatively, could I somehow make a scroll bar that wasn't displayed who's contents I could copy? I do know all the parameters needed.

1

1 Answers

0
votes

I found the following seems to work even if the control is obscured or off the screen. Create a DC and compatible bitmap from the control. Send the control a WM_PRINT message asking it to print itself in the DC/Bitmap. Then copy the bitmap using BitBlt.

Pretty ugly! Is there a better way?

Something like this...

            HDC                 hdcScroll;
            WINDOWPLACEMENT     WP;
            HDC                 memdc;
            HBITMAP             membit;

            hdcScroll = GetDC (hwndScroll);
            GetWindowPlacement (hwndScroll, &WP);
            int Height = WP.rcNormalPosition.bottom - WP.rcNormalPosition.top;
            int Width  = WP.rcNormalPosition.right  - WP.rcNormalPosition.left;
            memdc = CreateCompatibleDC(hdcScroll);                          // destination DC
            membit = CreateCompatibleBitmap(hdcScroll, Width, Height);      //  destination bitmap
            HBITMAP hOldBitmap =(HBITMAP) SelectObject(memdc, membit);  //   add bitmap to DC
            SendMessage (hwndScroll,WM_PRINT,(WPARAM) memdc, PRF_CLIENT);

            BitBlt 
                (hdc,                               // destination HDC
                 rt_scroll.left,                    // dest upper left corner X
                 rt_scroll.top,                     // dest upper left corner Y
                 rt_scroll.right-rt_scroll.left+1,  // width of dest rectangle
                 rt_scroll.bottom-rt_scroll.top+1,  // height of dest rectangle

                 memdc,                             // source HDC
                 0,                                 // source upper left corner X
                 0,                                 // source upper left cornet Y

                 SRCCOPY
                );

            SelectObject(memdc, hOldBitMap);
            DeleteObject (membit);
            DeleteDC (memdc);
            ReleaseDC (hwndScroll, hdcScroll);