先献上效果图,绝非ps
注意:
1. picture的autosize为true
2. picture加载的图片为最终窗体的形状
3. picture move 0,0
4. 图片的背景色为白
5. 代码集成了移动无边框窗体&TOP窗体
6. 如果发现错误请检查"回车"/"符号"
Option Explicit
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal y As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const RGN_XOR = 3
Private Const HTCAPTION = 2
Private Const WM_NCLBUTTONDOWN = &HA1
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim Xs As Long
Private Sub Form_Load()
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
Me.CreatePictureform
End Sub
Function CreatePictureform()
On Error Resume Next
Dim hRgn As Long, hRect As RECT, hTempRgn As Long, tColour As Long, OldScaleMode As Integer, AbsoluteX As Long, AbsoluteY As Long
Dim Color As Long, Hrect1 As RECT
Dim xx As Long, yy As Long
Dim rtn As Long
Me.Picture = Me.Picture1
Me.Width = Me.Picture1.Width
Me.Height = Me.Picture1.Height
OldScaleMode = Me.ScaleMode
Me.AutoRedraw = True
Me.ScaleMode = 3
Color = vbWhite
rtn = GetWindowRect(Me.hwnd, hRect)
hRgn = CreateRectRgn(0, 0, hRect.Right, hRect.Bottom)
For AbsoluteX = 0 To Me.ScaleWidth
For AbsoluteY = 0 To Me.ScaleHeight
tColour = GetPixel(Me.hdc, AbsoluteX, AbsoluteY)
If tColour = Color Then
hTempRgn = CreateRectRgn(AbsoluteX, AbsoluteY, AbsoluteX + 1, AbsoluteY + 1)
rtn = CombineRgn(hRgn, hRgn, hTempRgn, RGN_XOR)
rtn = DeleteObject(hTempRgn)
End If
Next AbsoluteY
Next AbsoluteX
rtn = SetWindowRgn(Me.hwnd, hRgn, True)
DeleteObject hRgn
Me.ScaleMode = OldScaleMode
If Err Then
MsgBox Error, 16, Err
End If
End Function
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, y As Single)
If Button = 1 Then
Dim ReturnVal As Long
Xs = ReleaseCapture()
ReturnVal = SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End If
End Sub