那就要自己画一个controlbox.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 CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As LongPrivate Const GWL_WNDPROC = (-4) Private Const GWL_STYLE = (-16) Private Const WS_CAPTION = &HC00000 Private Const WM_NCACTIVATE = &H86Private 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 Const SWP_FRAMECHANGED = &H20 Private Const SWP_NOMOVE = &H2 Private Const SWP_NOZORDER = &H4 Private Const SWP_NOSIZE = &H1Dim OldProcess As Long, fOwner As FormPublic Sub SetNewCaptionBar(frm As Form) SetWindowLong frm.hwnd, GWL_STYLE, GetWindowLong(frm.hwnd, GWL_STYLE) Xor WS_CAPTION SetWindowPos frm.hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOZORDER Or SWP_NOSIZE frm.Refresh OldProcess = SetWindowLong(frm.hwnd, GWL_WNDPROC, AddressOf WndProc) Set fOwner = frm End SubFunction WndProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Select Case wMsg Case WM_NCACTIVATE fOwner.RedrawCaptionBar CBool(wParam) Case WM_SYSCOMMAND If wParam = SC_CLOSE Then Set fOwner = Nothing SetWindowLong hwnd, GWL_WNDPROC, OldProcess End If End Select WndProc = CallWindowProc(OldProcess, hwnd, wMsg, wParam, lParam) End Function'-----form code - reguire same controls on form as above + TimerPrivate Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function DrawCaption Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long, pcRect As RECT, ByVal un As Long) As Long Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) 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 Declare Sub ReleaseCapture Lib "user32" () Const WM_NCLBUTTONDOWN = &HA1 Const HTCAPTION = 2 Const WM_SYSCOMMAND = &H112 Const SC_CLOSE = &HF060 Const SC_CONTEXTHELP = &HF180 Const SC_MAXIMIZE = &HF030 Const SC_MINIMIZE = &HF020 Const SC_RESTORE = &HF120Const TitleHeight = 20 Dim yClick As SinglePrivate Sub Command1_Click(Index As Integer) Picture1.SetFocus Dim SysCmd As Long Select Case Index Case 0 SysCmd = SC_CLOSE Case 1: SysCmd = IIf(WindowState = vbNormal, SC_MAXIMIZE, SC_RESTORE) Case 2 SysCmd = SC_MINIMIZE Case 3 SysCmd = SC_CONTEXTHELP Case 4 MsgBox "Owner draw caption bar demo" & vbCrLf & "by Arkadiy Olovyannikov", vbInformation + vbOKOnly, "Information" Exit Sub End Select SendMessage hwnd, WM_SYSCOMMAND, SysCmd, 0& End SubPrivate Sub Form_DblClick() If yClick > 0 Then Command1_Click 1 End SubPrivate Sub Form_Load() AutoRedraw = True Caption = "Owner Draw TitleBar Demo" ScaleMode = vbPixels Label1.BackStyle = 0 Label1.ForeColor = vbRed Label1.AutoSize = True Label1.Font.Bold = True Label1 = Time Picture1.AutoSize = True Picture1.ScaleMode = vbPixels Set Picture1 = Icon Picture1.Move 0, 0, 20, 20 Command1(0).Font = "Marlett" Command1(0).Width = 16 Command1(0).Height = 16 Command1(0).TabStop = False For i = 1 To 4 Load Command1(i) Command1(i).Visible = True Next i Command1(0).Caption = "r" Command1(2).Caption = "0" Command1(3).Caption = "s" Command1(4).Font = "Times New Roman" Command1(4).Font.Bold = True Command1(4).Caption = "i" SetNewCaptionBar Me End SubPrivate Sub Form_Resize() RedrawCaptionBar True End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) yClick = 0 If y > TitleHeight Then Exit Sub If Button = 1 Then yClick = y Call ReleaseCapture Call SendMessage(Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&) End If End SubPrivate Sub Label1_DblClick() Command1_Click 1 End SubPrivate Sub Label1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) If Button = 1 Then Call ReleaseCapture Call SendMessage(Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&) End If End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) Call ReleaseCapture SendKeys "% " End SubPublic Sub RedrawCaptionBar(bActive As Boolean) Dim r As RECT Cls SetRect r, 0, 0, ScaleWidth, TitleHeight DrawCaption hwnd, hdc, r, &H28 - bActive If Me.WindowState = vbMaximized Then Command1(1).Caption = 2 Else Command1(1).Caption = 1 For i = 0 To Command1.Count - 1 If i < 1 Then n = 2 Else n = 3 Command1(i).Move ScaleWidth - (i + 1) * Command1(0).Width - n, 2 Next i Label1.Move Command1(Command1.Count - 1).Left - Label1.Width, TitleHeight / 2 - Label1.Height / 2 On Error Resume Next Picture1.BackColor = IIf(bActive, vbActiveTitleBar, vbInactiveTitleBar) If bActive Then Picture1.SetFocus End SubPrivate Sub Timer1_Timer() Label1 = Time End Sub
不知道是否合你的意思
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 CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As LongPrivate Const GWL_WNDPROC = (-4)
Private Const GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000
Private Const WM_NCACTIVATE = &H86Private 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 Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOSIZE = &H1Dim OldProcess As Long, fOwner As FormPublic Sub SetNewCaptionBar(frm As Form)
SetWindowLong frm.hwnd, GWL_STYLE, GetWindowLong(frm.hwnd, GWL_STYLE) Xor WS_CAPTION
SetWindowPos frm.hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOZORDER Or SWP_NOSIZE
frm.Refresh
OldProcess = SetWindowLong(frm.hwnd, GWL_WNDPROC, AddressOf WndProc)
Set fOwner = frm
End SubFunction WndProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case wMsg
Case WM_NCACTIVATE
fOwner.RedrawCaptionBar CBool(wParam)
Case WM_SYSCOMMAND
If wParam = SC_CLOSE Then
Set fOwner = Nothing
SetWindowLong hwnd, GWL_WNDPROC, OldProcess
End If
End Select
WndProc = CallWindowProc(OldProcess, hwnd, wMsg, wParam, lParam)
End Function'-----form code - reguire same controls on form as above + TimerPrivate Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function DrawCaption Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long, pcRect As RECT, ByVal un As Long) As Long
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) 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 Declare Sub ReleaseCapture Lib "user32" ()
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2
Const WM_SYSCOMMAND = &H112
Const SC_CLOSE = &HF060
Const SC_CONTEXTHELP = &HF180
Const SC_MAXIMIZE = &HF030
Const SC_MINIMIZE = &HF020
Const SC_RESTORE = &HF120Const TitleHeight = 20
Dim yClick As SinglePrivate Sub Command1_Click(Index As Integer)
Picture1.SetFocus
Dim SysCmd As Long
Select Case Index
Case 0
SysCmd = SC_CLOSE
Case 1:
SysCmd = IIf(WindowState = vbNormal, SC_MAXIMIZE, SC_RESTORE)
Case 2
SysCmd = SC_MINIMIZE
Case 3
SysCmd = SC_CONTEXTHELP
Case 4
MsgBox "Owner draw caption bar demo" & vbCrLf & "by Arkadiy Olovyannikov", vbInformation + vbOKOnly, "Information"
Exit Sub
End Select
SendMessage hwnd, WM_SYSCOMMAND, SysCmd, 0&
End SubPrivate Sub Form_DblClick()
If yClick > 0 Then Command1_Click 1
End SubPrivate Sub Form_Load()
AutoRedraw = True
Caption = "Owner Draw TitleBar Demo"
ScaleMode = vbPixels
Label1.BackStyle = 0
Label1.ForeColor = vbRed
Label1.AutoSize = True
Label1.Font.Bold = True
Label1 = Time
Picture1.AutoSize = True
Picture1.ScaleMode = vbPixels
Set Picture1 = Icon
Picture1.Move 0, 0, 20, 20
Command1(0).Font = "Marlett"
Command1(0).Width = 16
Command1(0).Height = 16
Command1(0).TabStop = False
For i = 1 To 4
Load Command1(i)
Command1(i).Visible = True
Next i
Command1(0).Caption = "r"
Command1(2).Caption = "0"
Command1(3).Caption = "s"
Command1(4).Font = "Times New Roman"
Command1(4).Font.Bold = True
Command1(4).Caption = "i"
SetNewCaptionBar Me
End SubPrivate Sub Form_Resize()
RedrawCaptionBar True
End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
yClick = 0
If y > TitleHeight Then Exit Sub
If Button = 1 Then
yClick = y
Call ReleaseCapture
Call SendMessage(Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If
End SubPrivate Sub Label1_DblClick()
Command1_Click 1
End SubPrivate Sub Label1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 1 Then
Call ReleaseCapture
Call SendMessage(Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If
End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Call ReleaseCapture
SendKeys "% "
End SubPublic Sub RedrawCaptionBar(bActive As Boolean)
Dim r As RECT
Cls
SetRect r, 0, 0, ScaleWidth, TitleHeight
DrawCaption hwnd, hdc, r, &H28 - bActive
If Me.WindowState = vbMaximized Then Command1(1).Caption = 2 Else Command1(1).Caption = 1
For i = 0 To Command1.Count - 1
If i < 1 Then n = 2 Else n = 3
Command1(i).Move ScaleWidth - (i + 1) * Command1(0).Width - n, 2
Next i
Label1.Move Command1(Command1.Count - 1).Left - Label1.Width, TitleHeight / 2 - Label1.Height / 2
On Error Resume Next
Picture1.BackColor = IIf(bActive, vbActiveTitleBar, vbInactiveTitleBar)
If bActive Then Picture1.SetFocus
End SubPrivate Sub Timer1_Timer()
Label1 = Time
End Sub