⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apibitmap.cls

📁 几个不错的VB例子
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "ApiBitmap"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

' ##MODULE_DESCRIPTION This class returns information about and allows the manipulation of bitmaps


Private mhBitmap As Long

Private Type Size
    cx As Long
    cy As Long
End Type
Private Declare Function GetBitmapDimensionExApi Lib "gdi32" Alias "GetBitmapDimensionEx" (ByVal hBitmap As Long, lpDimension As Size) As Long


Private mStockBitmap As Boolean

Private Declare Function DeleteObjectApi Lib "gdi32" Alias "DeleteObject" (ByVal hObject As Long) As Long

Private Declare Function CreateCompatibleBitmapApi Lib "gdi32" Alias "CreateCompatibleBitmap" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long



Friend Sub CreateCompatibleBitmap(ByVal hdc As Long, ByVal Width As Long, ByVal Height As Long)

Dim lret As Long

lret = CreateCompatibleBitmapApi(hdc, Width, Height)
If lret = 0 Or Err.LastDllError > 0 Then
    Call ReportError(Err.LastDllError, "CreateCompatibleBitmap", GetLastSystemError)
Else
    mhBitmap = lret
End If

End Sub


Public Property Get hBitmap() As Long

    hBitmap = mhBitmap
    
End Property

Public Property Let hBitmap(ByVal newhandle As Long)

    If mhBitmap <> newhandle Then
        mhBitmap = newhandle
    End If
    
End Property

'\\ --[Height]------------------------------------------------------------------------------
'\\ Returns the height of a bitmap in logical pixels
'\\ ----------------------------------------------------------------------------------------
'\\ (c) 2001 - Merrion Computing.  All rights  to use, reproduce or publish this code reserved
'\\ Please check http://www.merrioncomputing.com for updates.
'\\ ----------------------------------------------------------------------------------------
Public Property Get Height() As Long

Dim nSize As Size
Dim lret As Long

lret = GetBitmapDimensionExApi(mhBitmap, nSize)
If lret = 0 Or Err.LastDllError > 0 Then
    Call ReportError(Err.LastDllError, "ApiBitmap:Height", GetLastSystemError)
Else
    Height = nSize.cy
End If

End Property

'\\ --[Width]------------------------------------------------------------------------------
'\\ Returns the width of a bitmap in logical pixels
'\\ ----------------------------------------------------------------------------------------
'\\ (c) 2001 - Merrion Computing.  All rights  to use, reproduce or publish this code reserved
'\\ Please check http://www.merrioncomputing.com for updates.
'\\ ----------------------------------------------------------------------------------------
Public Property Get Width() As Long

Dim nSize As Size
Dim lret As Long

lret = GetBitmapDimensionExApi(mhBitmap, nSize)
If lret = 0 Or Err.LastDllError > 0 Then
    Call ReportError(Err.LastDllError, "ApiBitmap:Width", GetLastSystemError)
Else
    Width = nSize.cx
End If

End Property

Private Sub Class_Terminate()

Dim lret As Long

If mhBitmap > 0 And Not (mStockBitmap) Then
    lret = DeleteObjectApi(mhBitmap)
    If lret = 0 Or Err.LastDllError > 0 Then
        Call ReportError(Err.LastDllError, "ApiBitmap:Terminate", GetLastSystemError)
    End If
End If

End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -