1,486
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
Private Const IMAGE_ICON = 1
Private Const LR_LOADFROMFILE = 16
Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Private Declare Function GetIconInfo Lib "user32" (ByVal hIcon As Long, piconinfo As ICONINFO) As Long
Private Type ICONINFO
fIcon As Long
xHotspot As Long
yHotspot As Long
hbmMask As Long
hbmColor As Long
End Type
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Type BITMAP '14 bytes
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
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 DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) 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 hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Sub Form_Load()
Dim hIcon As Long
hIcon = LoadImage(App.hInstance, "C:\sample.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE)
Dim ii As ICONINFO
Call GetIconInfo(hIcon, ii)
Dim bmp As BITMAP
Call GetObject(ii.hbmColor, Len(bmp), bmp)
Dim hdc As Long
hdc = CreateCompatibleDC(Me.hdc)
Dim hBmp As Long, hBmpOld1 As Long
hBmp = CreateCompatibleBitmap(Me.hdc, bmp.bmWidth, bmp.bmHeight)
hBmpOld1 = SelectObject(hdc, hBmp)
Dim hDCMem As Long
hDCMem = CreateCompatibleDC(Me.hdc)
Dim hBmpOld2 As Long
hBmpOld2 = SelectObject(hDCMem, ii.hbmMask)
Call BitBlt(hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, hDCMem, 0, 0, vbSrcAnd)
Call BitBlt(Me.hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, hDCMem, 0, 0, vbSrcAnd)
Call SelectObject(hDCMem, hBmpOld2)
hBmpOld2 = SelectObject(hDCMem, ii.hbmColor)
Call BitBlt(hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, hDCMem, 0, 0, vbSrcInvert)
Call BitBlt(Me.hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, hDCMem, 0, 0, vbSrcInvert)
Call SelectObject(hDCMem, hBmpOld2)
Call BitBlt(Me.hdc, bmp.bmWidth + 16, 0, bmp.bmWidth, bmp.bmHeight, hdc, 0, 0, vbSrcCopy)
Call SelectObject(hdc, hBmpOld1)
Call DeleteObject(hBmp)
Call DeleteDC(hdc)
Call DeleteDC(hDCMem)
Call DestroyIcon(hIcon)
Set Me.Picture = Me.Image
End Sub
DrawIcon tmpPic.hdc, 0, 0, hIcon
SavePicture tmpPic.Image, I