BitMap from userform

BrettCarr

New Member
Joined
Mar 22, 2006
Messages
3
Hi Guys,
I am putting together as Little Vba that configures glass shower screens, The user see's glass panels In a user form. Once the user has configured the panel(glass panel) He see's a representation of the panel in the form. How can i get all the labels and bitmaps just in the one frame(the Panel),(not the whole form) and make all the lil bits (labels and bitmaps and so on) in to one Bitmap and paste it into a oreder form???
wich is a spread sheet.
I cannot find anything to even remotly point me in the right direction

Please people any sugestion will be a marked inprovment on where im at

If i can get this right it will be a great help to my company and make us all smile with glee :lol:
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
So you basically want a screen capture of your frame?

Userform containing Frame1 and CommandButton1. Thanks to Jaafar for helping me on this post.

Download example below.

ScreenCaptureControlOnUserform.zip

Copy this code into your userform:
<table border="1" bgcolor="White"><caption ALIGN=left><font size="2" face=Courier New>Example VBA Code:</FONT></caption><tr><td><font size="2" face=Courier New>  <font color="#0000A0">Private</font> <font color="#0000A0">Sub</font> CommandButton1_Click()
       <font color="#0000A0">Dim</font> sh <font color="#0000A0">As</font> Shape
       <font color="#0000A0">Set</font> sh = CaptureWindowToRange(Frame1, [B5], Me.Caption)
      <font color="#008000"> 'you can resize and reposition the picture by way of the</font>
      <font color="#008000"> 'reference provided with the shape object</font>
       MsgBox sh.Name & " added to range B5"
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>
  
</FONT></td></tr></table>

Copy this code into a standard module:
<table border="1" bgcolor="White"><caption ALIGN=left><font size="2" face=Courier New>Example VBA Code:</FONT></caption><tr><td><font size="2" face=Courier New>  <font color="#0000A0">Option</font> <font color="#0000A0">Explicit</font>
  
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> CreateCompatibleDC <font color="#0000A0">Lib</font> "Gdi32" (ByVal hDC <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> CreateCompatibleBitmap <font color="#0000A0">Lib</font> "Gdi32" (ByVal hDC <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> nWidth <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> nHeight <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> GetDeviceCaps <font color="#0000A0">Lib</font> "Gdi32" (ByVal hDC <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> iCapabilitiy <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> GetSystemPaletteEntries <font color="#0000A0">Lib</font> "Gdi32" (ByVal hDC <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> wStartIndex <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> wNumEntries <font color="#0000A0">As</font> Long, lpPaletteEntries <font color="#0000A0">As</font> PALETTEENTRY) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> CreatePalette <font color="#0000A0">Lib</font> "Gdi32" (lpLogPalette <font color="#0000A0">As</font> LOGPALETTE) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> SelectObject <font color="#0000A0">Lib</font> "Gdi32" (ByVal hDC <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> hObject <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> BitBlt <font color="#0000A0">Lib</font> "Gdi32" (ByVal hDCDest <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> XDest <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> YDest <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> nWidth <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> nHeight <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> hDCSrc <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> XSrc <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> YSrc <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> dwRop <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> DeleteDC <font color="#0000A0">Lib</font> "Gdi32" (ByVal hDC <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> GetForegroundWindow <font color="#0000A0">Lib</font> "user32" () <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> SelectPalette <font color="#0000A0">Lib</font> "Gdi32" (ByVal hDC <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> hPalette <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> bForceBackground <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> RealizePalette <font color="#0000A0">Lib</font> "Gdi32" (ByVal hDC <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> GetWindowDC <font color="#0000A0">Lib</font> "user32" (ByVal hwnd <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> GetDC <font color="#0000A0">Lib</font> "user32" (ByVal hwnd <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> GetWindowRect <font color="#0000A0">Lib</font> "user32" (ByVal hwnd <font color="#0000A0">As</font> Long, lpRect <font color="#0000A0">As</font> RECT) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> ReleaseDC <font color="#0000A0">Lib</font> "user32" (ByVal hwnd <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> hDC <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> GetDesktopWindow <font color="#0000A0">Lib</font> "user32" () <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> FindWindow <font color="#0000A0">Lib</font> "user32" <font color="#0000A0">Alias</font> "FindWindowA" (ByVal lpClassName <font color="#0000A0">As</font> String, <font color="#0000A0">ByVal</font> lpWindowName <font color="#0000A0">As</font> String) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> OleCreatePictureIndirect <font color="#0000A0">Lib</font> "olepro32.dll" (PicDesc <font color="#0000A0">As</font> PicBmp, RefIID <font color="#0000A0">As</font> GUID, <font color="#0000A0">ByVal</font> fPictureOwnsHandle <font color="#0000A0">As</font> Long, IPic <font color="#0000A0">As</font> IPicture) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> SetClipboardData <font color="#0000A0">Lib</font> "user32" (ByVal wFormat <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> hMem <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> CopyImage <font color="#0000A0">Lib</font> "user32" (ByVal handle <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> imageType <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> newWidth <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> newHeight <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> lFlags <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> EmptyClipboard <font color="#0000A0">Lib</font> "user32" () <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> CloseClipboard <font color="#0000A0">Lib</font> "user32" () <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> OpenClipboard <font color="#0000A0">Lib</font> "user32" (ByVal hwnd <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> GetCursorPos <font color="#0000A0">Lib</font> "user32" (lpPoint <font color="#0000A0">As</font> POINTAPI) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> WindowFromPoint <font color="#0000A0">Lib</font> "user32" (ByVal xpoint <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> ypoint <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> ClientToScreen <font color="#0000A0">Lib</font> "user32" (ByVal hwnd <font color="#0000A0">As</font> Long, lpPoint <font color="#0000A0">As</font> POINTAPI) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  
  <font color="#0000A0">Private</font> <font color="#0000A0">Type</font> PALETTEENTRY
      peRed <font color="#0000A0">As</font> <font color="#0000A0">Byte</font>
      peGreen <font color="#0000A0">As</font> <font color="#0000A0">Byte</font>
      peBlue <font color="#0000A0">As</font> <font color="#0000A0">Byte</font>
      peFlags <font color="#0000A0">As</font> <font color="#0000A0">Byte</font>
  <font color="#0000A0">End</font> <font color="#0000A0">Type</font>
  
  <font color="#0000A0">Private</font> <font color="#0000A0">Type</font> PicBmp
      Size <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
      <font color="#0000A0">Type</font> <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
      hBmp <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
      hPal <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
      Reserved <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">End</font> <font color="#0000A0">Type</font>
  
  <font color="#0000A0">Private</font> <font color="#0000A0">Type</font> LOGPALETTE
      palVersion <font color="#0000A0">As</font> <font color="#0000A0">Integer</font>
      palNumEntries <font color="#0000A0">As</font> <font color="#0000A0">Integer</font>
      palPalEntry(255) <font color="#0000A0">As</font> PALETTEENTRY ' Enough for 256 colors.
  <font color="#0000A0">End</font> <font color="#0000A0">Type</font>
  
  <font color="#0000A0">Private</font> <font color="#0000A0">Type</font> GUID
      Data1 <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
      Data2 <font color="#0000A0">As</font> <font color="#0000A0">Integer</font>
      Data3 <font color="#0000A0">As</font> <font color="#0000A0">Integer</font>
      Data4(7) <font color="#0000A0">As</font> <font color="#0000A0">Byte</font>
  <font color="#0000A0">End</font> <font color="#0000A0">Type</font>
  
  <font color="#0000A0">Private</font> <font color="#0000A0">Type</font> RECT
      Left <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
      Top <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
      Right <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
      Bottom <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">End</font> <font color="#0000A0">Type</font>
  
  <font color="#0000A0">Private</font> <font color="#0000A0">Type</font> POINTAPI
       X <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
       Y <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">End</font> <font color="#0000A0">Type</font>
  
  <font color="#0000A0">Private</font> <font color="#0000A0">Const</font> RASTERCAPS <font color="#0000A0">As</font> <font color="#0000A0">Long</font> = 38
  <font color="#0000A0">Private</font> <font color="#0000A0">Const</font> RC_PALETTE <font color="#0000A0">As</font> <font color="#0000A0">Long</font> = &H100
  <font color="#0000A0">Private</font> <font color="#0000A0">Const</font> SIZEPALETTE <font color="#0000A0">As</font> <font color="#0000A0">Long</font> = 104
  <font color="#0000A0">Private</font> <font color="#0000A0">Const</font> vbSrcCopy <font color="#0000A0">As</font> <font color="#0000A0">Long</font> = &HCC0020
  <font color="#0000A0">Private</font> <font color="#0000A0">Const</font> vbPicTypeBitmap <font color="#0000A0">As</font> <font color="#0000A0">Long</font> = 1
  <font color="#0000A0">Private</font> <font color="#0000A0">Const</font> LOGPIXELSX = 88
  <font color="#0000A0">Private</font> <font color="#0000A0">Const</font> LOGPIXELSY = 90
  <font color="#0000A0">Private</font> <font color="#0000A0">Const</font> IMAGE_BITMAP = 0
  <font color="#0000A0">Private</font> <font color="#0000A0">Const</font> LR_COPYRETURNORG = &H4
  <font color="#0000A0">Private</font> <font color="#0000A0">Const</font> CF_BITMAP = 2
  
  <font color="#0000A0">Public</font> <font color="#0000A0">Function</font> CaptureWindowToRange(Frame <font color="#0000A0">As</font> Frame, Range <font color="#0000A0">As</font> Range, UserformCaption <font color="#0000A0">As</font> String) <font color="#0000A0">As</font> Shape
       <font color="#0000A0">Dim</font> FrameHandle <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
       <font color="#0000A0">Dim</font> FrameRect <font color="#0000A0">As</font> RECT
       <font color="#0000A0">Dim</font> ReturnValue <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
       <font color="#0000A0">Dim</font> UserformHandle <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
       <font color="#0000A0">Dim</font> MyPicHandle <font color="#0000A0">As</font> IPictureDisp
      
       UserformHandle = FindWindow("ThunderDFrame", UserformCaption)
       FrameHandle = GetFrameHandle(Frame, UserformHandle)
       ReturnValue = GetWindowRect(FrameHandle, FrameRect)
       <font color="#0000A0">Set</font> MyPicHandle = CaptureWindow(FrameHandle, False, 0, 0, _
           FrameRect.Right - FrameRect.Left, FrameRect.Bottom - FrameRect.Top)
      
      <font color="#008000"> 'KPD-Team 2001</font>
      <font color="#008000"> 'URL: http://www.allapi.net/</font>
      <font color="#008000"> 'E-Mail: KPDTeam@Allapi.net</font>
       <font color="#0000A0">Dim</font> hNew <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
       hNew = CopyImage(MyPicHandle, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)
       OpenClipboard UserformHandle
       EmptyClipboard
       SetClipboardData CF_BITMAP, hNew
       CloseClipboard
       Range(1).Select
       ActiveSheet.Paste
       <font color="#0000A0">Set</font> CaptureWindowToRange = ActiveSheet.Shapes(Selection.Name)
  <font color="#0000A0">End</font> <font color="#0000A0">Function</font>
  
  <font color="#0000A0">Private</font> <font color="#0000A0">Function</font> GetFrameHandle(Frame <font color="#0000A0">As</font> Frame, UserformHandle <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
       <font color="#0000A0">Dim</font> className <font color="#0000A0">As</font> <font color="#0000A0">String</font>
       <font color="#0000A0">Dim</font> retValue <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
       <font color="#0000A0">Dim</font> PT <font color="#0000A0">As</font> POINTAPI
       <font color="#0000A0">Dim</font> LeftInPixels <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
       <font color="#0000A0">Dim</font> TopInPixels <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
      
      <font color="#008000"> 'thanks to Jaafar on mr.excel.com for this snippet</font>
       LeftInPixels = Frame.Left / PointsPerPixelX
       TopInPixels = Frame.Top / PointsPerPixelY
       PT.X = LeftInPixels
       PT.Y = TopInPixels
       ClientToScreen UserformHandle, PT
  
       GetFrameHandle = WindowFromPoint(PT.X, PT.Y)
  <font color="#0000A0">End</font> <font color="#0000A0">Function</font>
  
  <font color="#008000">'http://support.microsoft.com/default.aspx?scid=kb;en-us;Q161299</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Function</font> CaptureWindow(ByVal hWndSrc <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> Client <font color="#0000A0">As</font> Boolean, <font color="#0000A0">ByVal</font> LeftSrc <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> TopSrc <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> WidthSrc <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> HeightSrc <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> IPictureDisp
  
  <font color="#0000A0">Dim</font> hDCMemory <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Dim</font> hBmp <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Dim</font> hBmpPrev <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Dim</font> r <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Dim</font> hDCSrc <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Dim</font> hPal <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Dim</font> hPalPrev <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Dim</font> RasterCapsScrn <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Dim</font> HasPaletteScrn <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Dim</font> PaletteSizeScrn <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Dim</font> LogPal <font color="#0000A0">As</font> LOGPALETTE
  
   <font color="#008000"> ' Depending on the value of Client get the proper device context.</font>
    <font color="#0000A0">If</font> Client <font color="#0000A0">Then</font>
       hDCSrc = GetDC(hWndSrc) ' <font color="#0000A0">Get</font> device context for client area.
    <font color="#0000A0">Else</font>
       hDCSrc = GetWindowDC(hWndSrc) ' <font color="#0000A0">Get</font> device context for entire
                                    <font color="#008000"> ' window.</font>
    <font color="#0000A0">End</font> <font color="#0000A0">If</font>
  
   <font color="#008000"> ' Create a memory device context for the copy process.</font>
    hDCMemory = CreateCompatibleDC(hDCSrc)
   <font color="#008000"> ' Create a bitmap and place it in the memory DC.</font>
    hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
    hBmpPrev = SelectObject(hDCMemory, hBmp)
  
   <font color="#008000"> ' Get screen properties.</font>
    RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS) ' capabilities.
    HasPaletteScrn = RasterCapsScrn <font color="#0000A0">And</font> RC_PALETTE ' support.
    PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE)
                                                         
  
    <font color="#0000A0">If</font> HasPaletteScrn <font color="#0000A0">And</font> (PaletteSizeScrn = 256) <font color="#0000A0">Then</font>
       LogPal.palVersion = &H300
       LogPal.palNumEntries = 256
       r = GetSystemPaletteEntries(hDCSrc, 0, 256, LogPal.palPalEntry(0))
       hPal = CreatePalette(LogPal)
      <font color="#008000"> ' Select the new palette into the memory DC and realize it.</font>
       hPalPrev = SelectPalette(hDCMemory, hPal, 0)
       r = RealizePalette(hDCMemory)
    <font color="#0000A0">End</font> <font color="#0000A0">If</font>
  
   <font color="#008000"> ' Copy the on-screen image into the memory DC.</font>
    r = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc, vbSrcCopy)
  
  <font color="#008000">' Remove the new copy of the on-screen image.</font>
    hBmp = SelectObject(hDCMemory, hBmpPrev)
  
   <font color="#008000"> ' If the screen has a palette get back the palette that was</font>
   <font color="#008000"> ' selected in previously.</font>
    <font color="#0000A0">If</font> HasPaletteScrn <font color="#0000A0">And</font> (PaletteSizeScrn = 256) <font color="#0000A0">Then</font>
       hPal = SelectPalette(hDCMemory, hPalPrev, 0)
    <font color="#0000A0">End</font> <font color="#0000A0">If</font>
  
   <font color="#008000"> ' Release the device context resources back to the system.</font>
    r = DeleteDC(hDCMemory)
    r = ReleaseDC(hWndSrc, hDCSrc)
  
   <font color="#008000"> ' Call CreateBitmapPicture to create a picture object from the</font>
   <font color="#008000"> ' bitmap and palette handles. Then return the resulting picture</font>
   <font color="#008000"> ' object.</font>
    <font color="#0000A0">Set</font> CaptureWindow = CreateBitmapPicture(hBmp, hPal)
  <font color="#0000A0">End</font> <font color="#0000A0">Function</font>
  
  <font color="#008000">'http://support.microsoft.com/default.aspx?scid=kb;en-us;Q161299</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Function</font> CreateBitmapPicture(ByVal hBmp <font color="#0000A0">As</font> Long, <font color="#0000A0">ByVal</font> hPal <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> IPictureDisp
     <font color="#0000A0">Dim</font> r <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  
      <font color="#0000A0">Dim</font> Pic <font color="#0000A0">As</font> PicBmp
     <font color="#008000"> ' IPicture requires a reference to "Standard OLE Types."</font>
      <font color="#0000A0">Dim</font> IPic <font color="#0000A0">As</font> IPictureDisp
      <font color="#0000A0">Dim</font> IID_IDispatch <font color="#0000A0">As</font> GUID
  
     <font color="#008000"> ' Fill in with IDispatch Interface ID.</font>
      <font color="#0000A0">With</font> IID_IDispatch
         .Data1 = &H20400
         .Data4(0) = &HC0
         .Data4(7) = &H46
      <font color="#0000A0">End</font> <font color="#0000A0">With</font>
  
     <font color="#008000"> ' Fill Pic with necessary parts.</font>
      <font color="#0000A0">With</font> Pic
         .Size = Len(Pic) ' Length of structure.
         .Type = vbPicTypeBitmap ' <font color="#0000A0">Type</font> of Picture (bitmap).
         .hBmp = hBmp ' Handle to bitmap.
         .hPal = hPal ' Handle to palette (may be null).
      <font color="#0000A0">End</font> <font color="#0000A0">With</font>
  
     <font color="#008000"> ' Create Picture object.</font>
      r = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
  
     <font color="#008000"> ' Return the new Picture object.</font>
      <font color="#0000A0">Set</font> CreateBitmapPicture = IPic
  <font color="#0000A0">End</font> <font color="#0000A0">Function</font>
  
  <font color="#008000">''thanks to Stephen Bullen</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Function</font> PointsPerPixelX() <font color="#0000A0">As</font> <font color="#0000A0">Double</font>
       <font color="#0000A0">Dim</font> hDC <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
       hDC = GetDC(0)
       PointsPerPixelX = 72 / GetDeviceCaps(hDC, LOGPIXELSX)
       ReleaseDC 0, hDC
  <font color="#0000A0">End</font> <font color="#0000A0">Function</font>
  
  <font color="#008000">'thanks to Stephen Bullen</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Function</font> PointsPerPixelY() <font color="#0000A0">As</font> <font color="#0000A0">Double</font>
       <font color="#0000A0">Dim</font> hDC <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
       hDC = GetDC(0)
       PointsPerPixelY = 72 / GetDeviceCaps(hDC, LOGPIXELSY)
       ReleaseDC 0, hDC
  <font color="#0000A0">End</font> <font color="#0000A0">Function</font>
</FONT></td></tr></table>
 
Upvote 0

Forum statistics

Threads
1,224,899
Messages
6,181,629
Members
453,058
Latest member
rmd0725

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top