'In a modulePublic Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongPublic prevWndProc As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_NCLBUTTONDOWN = &HA1
Public Const HTCAPTION = 2
Public Const HTCLIENT = 1
Public Const WM_NCHITTEST = &H84Public Function myWndProc1()
prevWndProc = GetWindowLong(Form4.hwnd, GWL_WNDPROC)
'ÒÔWndProcÈ¡´úÔ­´°¿Ú³ÌÐò
SetWindowLong Form4.hwnd, GWL_WNDPROC, AddressOf WndProc
End FunctionPublic Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
WndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam)
If Msg = WM_NCHITTEST And WndProc = HTCLIENT Then
If Form4.isInImage(lParam Mod 65536, lParam \ 65536) Then
WndProc = HTCAPTION
End If
End If
End Function
'in a form has a pictures
Option ExplicitPrivate Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As LongPublic Function isInImage(ByVal x As Integer, ByVal y As Integer) As Boolean
Dim r1 As RECT, r2 As RECT
Dim border As Integer
isInImage = False
GetWindowRect Me.hwnd, r1
GetClientRect Me.hwnd, r2
border = (r1.Right - r1.Left - r2.Right) / 2
If x > r1.Left + border + Image1.Left And x < r1.Left + border + Image1.Left + Image1.Width And y > r1.Top + border + Image1.Top And y < r1.Top + border + Image1.Top + Image1.Height Then
isInImage = True
End If
End FunctionPrivate Sub Form_Load()
myWndProc1
End SubPrivate Sub Form_Unload(Cancel As Integer)
SetWindowLong Me.hwnd, GWL_WNDPROC, prevWndProc
End Sub
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongPublic prevWndProc As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_NCLBUTTONDOWN = &HA1
Public Const HTCAPTION = 2
Public Const HTCLIENT = 1
Public Const WM_NCHITTEST = &H84Public Function myWndProc1()
prevWndProc = GetWindowLong(Form4.hwnd, GWL_WNDPROC)
'ÒÔWndProcÈ¡´úÔ­´°¿Ú³ÌÐò
SetWindowLong Form4.hwnd, GWL_WNDPROC, AddressOf WndProc
End FunctionPublic Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
WndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam)
If Msg = WM_NCHITTEST And WndProc = HTCLIENT Then
If Form4.isInImage(lParam Mod 65536, lParam \ 65536) Then
WndProc = HTCAPTION
End If
End If
End Function
'in a form has a pictures
Option ExplicitPrivate Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As LongPublic Function isInImage(ByVal x As Integer, ByVal y As Integer) As Boolean
Dim r1 As RECT, r2 As RECT
Dim border As Integer
isInImage = False
GetWindowRect Me.hwnd, r1
GetClientRect Me.hwnd, r2
border = (r1.Right - r1.Left - r2.Right) / 2
If x > r1.Left + border + Image1.Left And x < r1.Left + border + Image1.Left + Image1.Width And y > r1.Top + border + Image1.Top And y < r1.Top + border + Image1.Top + Image1.Height Then
isInImage = True
End If
End FunctionPrivate Sub Form_Load()
myWndProc1
End SubPrivate Sub Form_Unload(Cancel As Integer)
SetWindowLong Me.hwnd, GWL_WNDPROC, prevWndProc
End Sub
http://www14.brinkster.com/weblover/DrawForm.zip挡住了"标题栏按钮"的例子
http://www14.brinkster.com/weblover/DrawForm1.zip两个文件都是可执行文件,大小是十几K,下载后把扩展名改为.exe即可
欢迎提出意见!