• 欢迎访问金刀客博客!
  • 2019,春节快乐!

点击任务栏图标实现窗体的最大化和最小化的2种办法

原创天空 admin 3433次浏览 已收录 0个评论

把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


金刀客博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明点击任务栏图标实现窗体的最大化和最小化的2种办法
喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到