把from的borderstyle设置为1,把minibutton和maxbutton设置为TRUE.
1,然后在通用种声明:
‘点击任务栏图标,实现窗体的最大化和最小化,用setwindowrgn实现
Private Declare Function SetWindowRgn Lib “user32” (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) 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 GetSystemMetrics Lib “user32” (ByVal nIndex As Long) As Long
Const SM_CYCAPTION = 4
在Form_Load()中加入:
Dim rgn As Long, capHeight As Long
capHeight = GetSystemMetrics(SM_CYCAPTION) + 3
Me.ScaleMode = 3
rgn = CreateRectRgn(3, capHeight, Me.ScaleWidth, Me.ScaleHeight + capHeight)
SetWindowRgn Me.hwnd, rgn, True
2,建立一个模块,输入以下代码。
Public Declare Function GetWindowLong Lib “user32” Alias _
“GetWindowLongA” (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib “user32” Alias _
“SetWindowLongA” (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public 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 GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOSIZE = &H1
Public Sub ToggleTitleBar(f As Form, ShowTitle As Boolean)
Dim style As Long
style = GetWindowLong(f.hwnd, GWL_STYLE)
If ShowTitle Then
style = style or WS_CAPTION
Else
style = style And Not WS_CAPTION
End If
SetWindowLong f.hwnd, GWL_STYLE, style
SetWindowPos f.hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED or SWP_NOMOVE or SWP_NOZORDER or SWP_NOSIZE
End Sub
在Form_Load()中加入:
ToggleTitleBar Me, False