Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetDC Lib "user32" (ByVal Hwnd 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 CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 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 DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal Hwnd 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 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 Any) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTBOTTOMRIGHT = 2 '移动
Private Hwnd As Long, Clicked As Boolean, Refresh As Boolean
Private Sub UserForm_Initialize()
Dim lngMe As Long
Hwnd = FindWindow(vbNullString, Me.Caption)
lngMe = GetWindowLong(Hwnd, -16) And Not &HC00000
SetWindowLong Hwnd, -16, lngMe: DrawMenuBar Hwnd
lngMe = GetWindowLong(Hwnd, -20) And Not &H1&
SetWindowLong Hwnd, -20, lngMe
Me.Width = 600: Me.Height = 0
End Sub
UserForm2
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetDC Lib "user32" (ByVal Hwnd 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 CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 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 DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal Hwnd 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 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 Any) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTBOTTOMRIGHT = 2 '移动
Private Hwnd As Long, Clicked As Boolean, Refresh As Boolean
Private Sub MakeRegion(hDC As Long, Width As Long, Height As Long)
Dim X As Long, Y As Long, xStart As Long, FirstRgn As Boolean
Dim FullRgn As Long, LineRgn As Long, InLine As Boolean
DoEvents
For Y = 0 To Height - 1
For X = 0 To Width
If GetPixel(hDC, X, Y) = vbWhite Or X = Width Then '取得一个点(Pixel)的颜色
If InLine Then
InLine = False: LineRgn = CreateRectRgn(xStart, Y, X, Y + 1)
If Not FirstRgn Then
FullRgn = LineRgn
FirstRgn = True
Else
CombineRgn FullRgn, FullRgn, LineRgn, 2 '(RGN_OR)设置为两个区域相加
End If
End If
Else
If Not InLine Then InLine = True: xStart = X
End If
Next
Next
SetWindowRgn Hwnd, FullRgn, True
DeleteObject LineRgn: DeleteObject FullRgn
End Sub
Private Sub UserForm_Activate()
MakeRegion GetDC(Hwnd), 600, 32
End Sub
Private Sub UserForm_Initialize()
Dim lngMe As Long
Hwnd = FindWindow(vbNullString, Me.Caption)
lngMe = GetWindowLong(Hwnd, -16) And Not &HC00000
SetWindowLong Hwnd, -16, lngMe: DrawMenuBar Hwnd
lngMe = GetWindowLong(Hwnd, -20) And Not &H1&
SetWindowLong Hwnd, -20, lngMe
Me.Width = 600: Me.Height = 32
End Sub