|
DirectX 7 编程初步(8) 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)
' Get screen properties. RasterCapsScrn = GetDeviceCaps(hdcSrc, RASTERCAPS) 'Raste capabilities. HasPaletteScrn = RasterCapsScrn And RC_PALtTTEic1 ' Palette support. PaletteSizeScrn = GetDeviceCaps(hdcSrc, SIZEPALETTE) ' Size of palette. If HasPaletteScrn And (PaletteSizeScrn = 256) Then '建立系统调色板的拷贝 LogPal.palVersion = &H300 LogPal.palNumEntries = 256 r = GetSystemPaletteEntries(hdcSrc, 0, 256, LogPal.palPalEntry(0)) hPal = CreatePalette(LogPal)
|