?? modbitmap.bas
字號:
Public Const ENHMETA_SIGNATURE = &H20454D46
' Constants - PICTDESC.picType
Public Const PICTYPE_UNINITIALIZED = -1 ' The picture object is currently uninitialized.
Public Const PICTYPE_NONE = 0 ' A new picture object is to be created without an initialized state. This value is valid only in the PICTDESC structure.
Public Const PICTYPE_BITMAP = 1 ' The picture type is a bitmap. When this value occurs in the PICTDESC structure, it means that the bmp field of that structure contains the relevant initialization parameters.
Public Const PICTYPE_METAFILE = 2 ' The picture type is a metafile. When this value occurs in the PICTDESC structure, it means that the wmf field of that structure contains the relevant initialization parameters.
Public Const PICTYPE_ICON = 3 ' The picture type is an icon. When this value occurs in the PICTDESC structure, it means that the icon field of that structure contains the relevant initialization parameters.
Public Const PICTYPE_ENHMETAFILE = 4 ' The picture type is a Win32-enhanced metafile. When this value occurs in the PICTDESC structure, it means that the emf field of that structure contains the relevant initialization parameters.
' Constants - GetDeviceCaps.nIndex
Public Const HORZSIZE = 4 ' Width, in millimeters, of the physical screen.
Public Const VERTSIZE = 6 ' Height, in millimeters, of the physical screen.
Public Const HORZRES = 8 ' Width, in pixels, of the screen.
Public Const VERTRES = 10 ' Height, in raster lines, of the screen.
Public Const BITSPIXEL = 12 ' Number of adjacent color bits for each pixel.
' Constants - OleCreateBitmapIndiect (Return Values)
Public Const S_OK = 0 ' The new picture object was created successfully.
Public Const E_NOINTERFACE = &H80004002 ' The object does not support the interface specified in riid.
Public Const E_POINTER = &H80004003 ' The address in pPictDesc or ppvObj is not valid. For example, it may be NULL.
Public Const E_INVALIDARG = &H80000003 ' One or more arguments are invalid
Public Const E_OUTOFMEMORY = &H8007000E ' Ran out of memory
Public Const E_UNEXPECTED = &H8000FFFF ' Catastrophic failure
' Constants - GetCurrentObject.uObjectType
Public Const OBJ_BITMAP = 7 ' Returns the current selected bitmap
Public Const OBJ_BRUSH = 2 ' Returns the current selected brush
Public Const OBJ_COLORSPACE = 14 ' Returns the current color space
Public Const OBJ_FONT = 6 ' Returns the current selected font
Public Const OBJ_PAL = 5 ' Returns the current selected pal
Public Const OBJ_PEN = 1 ' Returns the current selected pen
' Constants - CopyImage.fuFlags
Public Const LR_COPYDELETEORG = &H8 ' Deletes the original image after creating the copy.
Public Const LR_COPYFROMRESOURCE = &H4000 ' Tries to reload an icon or cursor resource from the original resource file rather than simply copying the current image. This is useful for creating a different-sized copy when the resource file contains multiple sizes of the resource. Without this flag, CopyImage stretches the original image to the new size. If this flag is set, CopyImage uses the size in the resource file closest to the desired size. This will succeed only if hImage was loaded by LoadIcon or LoadCursor, or by LoadImage with the LR_SHARED flag.
Public Const LR_COPYRETURNORG = &H4 ' Returns the original hImage if it satisfies the criteria for the copy梩hat is, correct dimensions and color depth梚n which case the LR_COPYDELETEORG flag is ignored. If this flag is not specified, a new object is always created.
Public Const LR_CREATEDIBSECTION = &H2000 ' If this is set and a new bitmap is created, the bitmap is created as a DIB section. Otherwise, the bitmap image is created as a device-dependent bitmap. This flag is only valid if uType is IMAGE_BITMAP.
Public Const LR_MONOCHROME = &H1 ' Creates a new monochrome image.
' Constants - RedrawWindow.fuRedraw
Public Const RDW_ERASE = &H4
Public Const RDW_FRAME = &H400
Public Const RDW_INTERNALPAINT = &H2
Public Const RDW_INVALIDATE = &H1
Public Const RDW_NOERASE = &H20
Public Const RDW_NOFRAME = &H800
Public Const RDW_NOINTERNALPAINT = &H10
Public Const RDW_VALIDATE = &H8
Public Const RDW_ERASENOW = &H200
Public Const RDW_UPDATENOW = &H100
Public Const RDW_ALLCHILDREN = &H80
Public Const RDW_NOCHILDREN = &H40
' Constants - DrawIconEx.diFlags
Public Const DI_MASK = &H1 ' Performs the raster operation specified by ropMask.
Public Const DI_IMAGE = &H2 ' Performs the raster operation specified by ropImage.
Public Const DI_NORMAL = &H3 ' Combination of DI_IMAGE and DI_MASK.
Public Const DI_COMPAT = &H4 ' Draws the icon or cursor using the system default image rather than the user-specified image.
Public Const DI_DEFAULTSIZE = &H8 ' Draws the icon or cursor using the width and height specified by the system metric values for cursors or icons, if the cxWidth and cyWidth parameters are set to zero. If this flag is not specified and cxWidth and cyWidth are set to zero, the function uses the actual resource size.
' Constants - SetStretchBltMode.iStretchMode
Public Const BLACKONWHITE = 1 ' Performs a Boolean AND operation using the color values for the eliminated and existing pixels. If the bitmap is a monochrome bitmap, this mode preserves black pixels at the expense of white pixels.
Public Const WHITEONBLACK = 2 ' Performs a Boolean OR operation using the color values for the eliminated and existing pixels. If the bitmap is a monochrome bitmap, this mode preserves white pixels at the expense of black pixels.
Public Const COLORONCOLOR = 3 ' Deletes the pixels. This mode deletes all eliminated lines of pixels without trying to preserve their information.
Public Const HALFTONE = 4 ' Maps pixels from the source rectangle into blocks of pixels in the destination rectangle. The average color over the destination block of pixels approximates the color of the source pixels. After setting the HALFTONE stretching mode, an application must call the SetBrushOrgEx function to set the brush origin. If it fails to do so, brush misalignment occurs.
Public Const MAXSTRETCHBLTMODE = 4 ' (undocumented)
Public Const STRETCH_ANDSCANS = BLACKONWHITE ' Same as BLACKONWHITE.
Public Const STRETCH_ORSCANS = WHITEONBLACK ' Same as WHITEONBLACK.
Public Const STRETCH_DELETESCANS = COLORONCOLOR ' Same as COLORONCOLOR.
Public Const STRETCH_HALFTONE = HALFTONE ' Same as HALFTONE.
' Win32 Function Declarations
Public Declare Function BitBlt Lib "GDI32" (ByVal hDC_Destination As Long, ByVal X_Dest As Long, ByVal Y_Dest As Long, ByVal Width_Dest As Long, ByVal Height_Dest As Long, ByVal hDC_Source As Long, ByVal X_Src As Long, ByVal Y_Src As Long, ByVal RasterOperation As Long) As Long
Public Declare Function CopyCursor Lib "user32" (ByVal pCursor As Long) As Long
Public Declare Function CopyImage Lib "user32" (ByVal hImage As Long, ByVal uType As Long, ByVal OutputWidth As Long, ByVal OutputHeight As Long, ByVal fuFlags As Long) As Long
Public Declare Function CopyIcon Lib "user32" (ByVal hIcon As Long) As Long
Public Declare Function CreateBitmap Lib "GDI32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal cPlanes As Long, ByVal cBitsPerPel As Long, ByRef lpvBits As Any) As Long
Public Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Public Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Long) As Long
Public Declare Function CreateIconIndirect Lib "user32" (ByRef pICONINFO As ICONINFO) As Long
Public Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Long) As Long
Public Declare Function DeleteObject Lib "GDI32" (ByVal hGDIObj As Long) As Long
Public Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Public Declare Function DrawIconEx Lib "user32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal hIcon As Long, ByVal IconWidth As Long, ByVal IconHeight As Long, ByVal AniFrameIndex As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Public Declare Function GetCurrentObject Lib "GDI32" (ByVal hDC As Long, ByVal uObjectType As Long) As Long
Public Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetDeviceCaps Lib "GDI32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
Public Declare Function GetEnhMetaFileHeader Lib "GDI32" (ByVal hEnhancedMetafile As Long, ByVal BufferSize As Long, ByRef lpEMH As ENHMETAHEADER) As Long
Public Declare Function GetIconInfo Lib "user32" (ByVal hIcon As Long, ByRef pICONINFO As ICONINFO) As Long
Public Declare Function GetMapMode Lib "GDI32" (ByVal hDC As Long) As Long
Public Declare Function GetObjectAPI Lib "GDI32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Public Declare Function GetPixel Lib "GDI32" (ByVal hDC As Long, ByVal XPos As Long, ByVal nYPos As Long) As Long
Public Declare Function OleCreatePictureIndirect Lib "OLEPRO32.DLL" (ByRef PicDesc As Any, ByRef RefIID As GUID, ByVal fPictureOwnsHandle As Long, ByRef IPic As StdPicture) As Long 'As IPicture) As Long
Public Declare Function OleTranslateColor Lib "OLEPRO32.DLL" (ByVal OLE_COLOR As Long, ByVal hPALETTE As Long, pColorRef As Long) As Long
Public Declare Function RedrawWindow Lib "user32" (ByVal hWnd As Long, lprcUpdate As Any, ByVal hrgnUpdate As Long, ByVal fuRedraw As Long) As Long
Public Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Public Declare Function SelectObject Lib "GDI32" (ByVal hDC As Long, ByVal hGDIObj As Long) As Long
Public Declare Function SetBkColor Lib "GDI32" (ByVal hDC As Long, ByVal crColor As Long) As Long
Public Declare Function SetMapMode Lib "GDI32" (ByVal hDC As Long, ByVal nMapMode As Long) As Long
Public Declare Function SetPixel Lib "GDI32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
Public Declare Function SetStretchBltMode Lib "GDI32" (ByVal hDC As Long, ByVal iStretchMode As Long) As Long
Public Declare Function StretchBlt Lib "GDI32" (ByVal hDC_Destination As Long, ByVal X_Dest As Long, ByVal Y_Dest As Long, ByVal New_Width As Long, ByVal New_Height As Long, ByVal hDC_Source As Long, ByVal X_Src As Long, ByVal Y_Src As Long, ByVal Orig_Width As Long, ByVal Orig_Height As Long, ByVal RasterOperation As Long) As Long
'========================================================================================================
'
' Convert_HM_PX
'
' When dealing with the "Picture" property of VB objects such as PictureBox or Form, or StdPicture
' objects, the Height & Width properties of such is not measured in Pixels or Twips... but in something
' called "HiMetric". This function takes the height and width measurements of a picture in HiMetric
' and converts it to Pixels so that it can be used with standard Win32 API calls, or with VB objects
' that have their "ScaleMode" property set to "vbPixels"
'
' NOTE - You can also use the "GetBitmapInfo" function to get the height and/or width of a picture
' in pixels.
'
' Parameter: Use:
' --------------------------------------------------
' InputHeight Optional. Specifies the height of the picture in HiMetric
' InputWidth Optional. Specifies the width of the picture in HiMetric
' OutputHeight Optional. Returns the height of the picture in Pixels (if InputHeight is valid)
' OutputWidth Optional. Returns the width of the picture in Pixels (if InputWidth is valid)
' VB_Picture Optional. If set to TRUE, the calculation used to get the desired return value
' uses the Screen.TwipsPerPixel properties to get the TwipsPerPixel instead of
' using a more accurate calculation of TwipsPerPixel. The return value is correct
' for use with the Picture property of VB objects like PictureBox, & StdPicture.
' If set to FALSE, the calculation used to get the desired return value uses a
' calculation to get and use a more accurate measurement of the TwipsPerPixel.
' This is more accurate for use with Win32 API calls.
'
' Return:
' -------
' If the function succeeds, the return is TRUE
' If the function fails, the return is FALSE
'
' --------------------------------------------------
' These type definitions were taken from OCIDL.H
' --------------------------------------------------
' typedef LONG OLE_XPOS_HIMETRIC;
' typedef LONG OLE_YPOS_HIMETRIC;
' typedef LONG OLE_XSIZE_HIMETRIC;
' typedef LONG OLE_YSIZE_HIMETRIC;
'
'========================================================================================================
Public Function Convert_HM_PX(Optional ByVal InputHeight As Long, _
Optional ByVal InputWidth As Long, _
Optional ByRef OutputHeight As Long, _
Optional ByRef OutputWidth As Long, _
Optional ByVal VB_Picture As Boolean = True) As Boolean
On Error Resume Next
Dim TwipsX As Single
Dim TwipsY As Single
' Reset the return values
OutputHeight = 0
OutputWidth = 0
' Make sure the parameters passed are valid
If InputHeight = 0 And InputWidth = 0 Then Exit Function
' If the user specifies to do the convertion for a Visual Basic Picture, use the
' "Screen" object to get the approximate TwipsPerPixel
If VB_Picture = True Then
OutputWidth = CLng(((InputWidth / 2540) * 1440) / Screen.TwipsPerPixelX)
OutputHeight = CLng(((InputHeight / 2540) * 1440) / Screen.TwipsPerPixelY)
' If the user doesn't specify to do the convertion for a Visual Basic Picture, assume
' it's for a Win32 API call and calculate the exact TwipsPerPixel to be more accurate
Else
If GetDisplayInfo(, , TwipsX, TwipsY) = False Then Exit Function
OutputWidth = CLng((InputWidth / 2540 * 1440) / TwipsX)
OutputHeight = CLng((InputHeight / 2540 * 1440) / TwipsY)
End If
' Function succeeded
Convert_HM_PX = True
End Function
'========================================================================================================
'
' Convert_PX_HM
'
' When dealing with the "Picture" property of VB objects such as PictureBox or Form, or StdPicture
' objects, the Height & Width properties of such is not measured in Pixels or Twips... but in something
' called "HiMetric". This function takes the height and width measurements of a picture in Pixels
' and converts it to HiMetric so that it can be used with VB calls, etc.
'
' NOTE - When the "VB_Picture" parameter is set to FALSE, the return values of this function are VERY
' close, but not exact because of how the calculations and number rounding works. To see this effect,
' use the Convert_HM_PX function to take the height/width of a picture and convert them to pixels...
' then take the return values from that and use this function to convert them back to their original
' HiMetrics measurement. The results will be very close, but not exact. This shouldn't be a problem
' because I would think it would be a rare thing that you'd want to convert Pixels to HiMetric (I even
' considered leaving this function out of the module).
'
' Parameter: Use:
' --------------------------------------------------
' InputHeight Optional. Specifies the height of the picture in Pixels
' InputWidth Optional. Specifies the width of the picture in Pixels
' OutputHeight Optional. Returns the height of the picture in HiMetric (if InputHeight is valid)
' OutputWidth Optional. Returns the width of the picture in HiMetric (if InputWidth is valid)
' VB_Picture Optional. If set to TRUE, the calculation used to get the desired return value
' uses the Screen.TwipsPerPixel properties to get the TwipsPerPixel instead of
' using a more accurate calculation of TwipsPerPixel. The return value is correct
' for use with the Picture property of VB objects like PictureBox, & StdPicture.
' If set to FALSE, the calculation used to get the desired return value uses a
' calculation to get and use a more accurate measurement of the TwipsPerPixel.
' This is more accurate for use with Win32 API calls.
'
' Return:
' -------
' If the function succeeds, the return is TRUE
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -