Private Declare Function CreateCompatibleDC Lib “GDI32” (ByVal hDC As Long) As Long Private Declare Function CreateCompatibleBitmap Lib “GDI32” (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function GetDeviceCaps Lib “GDI32” (ByVal hDC As Long, ByVal iCapabilitiy As Long) As Long Private Declare Function GetSystemPaletteEntries Lib “GDI32” (ByVal hDC As Long, ByVal wStartIndex As Long, ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) As Long Private Declare Function CreatePalette Lib “GDI32”(lpLogPalette As LOGPALETTE) As Long Private Declare Function SelectObject Lib “GDI32”(ByVal hDC As Long, ByVal hObject As Long) As Long Private Declare Function BitBlt Lib “GDI32”(ByVal hDCDest As Long, ByVal XDest As Long, ByVal YDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hdcSrc As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) As Long Private Declare Function DeleteDC Lib “GDI32”(ByVal hDC As Long) As Long Private Declare Function GetForegroundWindow Lib “USER32” () As Long Private Declare Function SelectPalette Lib “GDI32”(ByVal hDC As Long, ByVal hPalette As Long, ByVal bForceBackground As Long) As Long Private Declare Function RealizePalette Lib “GDI32” (ByVal hDC As Long) As Long Private Declare Function GetWindowDC Lib “USER32” (ByVal hWnd As Long) As Long Private Declare Function GetDC Lib “USER32"(ByVal hWnd As Long) As Long Private Declare Function GetWindowRect Lib “USER32”(ByVal hWnd As Long, lpRect As RECT) As Long Private Declare Function ReleaseDC Lib “USER32”(ByVal hWnd As Long, ByVal hDC As Long) As Long Private Declare Function GetDesktopWindow Lib “{USER32"() As Long Private Type PicBmp Size As Long Type As Long hBmp As Long hPal As Long Reserved As Long End Type Private Declare Function OleCreatePictureIndirect Lib “olepro32.dll” (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long Public Function SaveTohBmp(ByVal hdcSrc As Long, ByVal LeftSrc As Long, _ ByVal TopSrc As Long, ByVal WidthSrc As Long, ByVal HeightSrc As Long) As Picture Dim hDCMemory As Long Dim hBmp As Long Dim hBmpPrev As Long Dim r As Long Dim hPal As Long Dim hPalPrev As Long Dim RasterCapsScrn As Long Dim HasPaletteScrn As Long Dim PaletteSizeScrn As Long Dim LogPal As LOOGPALETTE '建立一个内存图形设备句柄 hDCMemory=CreateCompatibleDC(hdcSrc) '建立一个bitmap并保存到hDCMemory中 hBmp = CreateCompatibleBitmap(hdcSrc, WidthSrc, HeightSrc) hBmpPrev = SelectObject(hDCMemory, hBmp) RasterCapsScrn = GetDeviceCaps(hdcSrc, RASTE图CAPS) 'rRaste HasPaletteScrn = RasterCapsScrn And RC_PALtTTEic1 ' Palette PaletteSizeScrn = GetDeviceCaps(hdcSrc, SIZEPALETTE) ' Size of If HasPaletteScrn And (PaletteSizeScrn = 256) The
(编辑:anna sui)
|