VB 窗体最小化与还原
在无边框情况下,窗体显示在系统任务栏里(ShowInTaskbar=True)就是点击在如下位置的程序名,可以最小化和还原窗体还有在无边框情况下,窗体显示在系统任务栏里(...
在无边框情况下,窗体显示在系统任务栏里(ShowInTaskbar = True)就是点击在如下位置的程序名,可以最小化 和 还原窗体 还有 在无边框情况下,窗体显示在系统任务栏里(ShowInTaskbar = True)时候最大化窗体就会把任务栏遮住,有什么办法可以像其它程序一样,最大化时漏出任务栏?
展开
3个回答
2013-09-11
展开全部
VB程序运行时,把窗口最大化后,窗口是不能被调整大小的(最小化除外),在程序中也不行。
设计时,可以正常窗口呈现,并屏蔽窗体的最大化按钮,自己做个替代的“最大化”按钮,实现窗体放大。当点击“最大化”时,触发Form的ReSize事件,在Form的ReSize事件中,写入:
Private Sub Form_Resize()
Form1.Left = 0
Form1.Top = 0
Form1.Width = Screen.Width
Form1.Height = Screen.Height - GetTaskbarHeight
End Sub
(当程序启动时,也会同时触发Form_ReSize的)
其中,GetTaskbarHeight的获取要写进模块文件中:
Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
Public Const SPI_GETWORKAREA = 48
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Function GetTaskbarHeight() As Integer
Dim lRes As Long
Dim rectVal As RECT
lRes = SystemParametersInfo(SPI_GETWORKAREA, 0, rectVal, 0)
GetTaskbarHeight = ((Screen.Height / Screen.TwipsPerPixelX) -rectVal.Bottom) * Screen.TwipsPerPixelX
End Function
但是,这样做还要考虑到有些人把任务栏移到其他地方的,比如左侧,右侧,甚至隐藏,所以,也是很麻烦的哦
设计时,可以正常窗口呈现,并屏蔽窗体的最大化按钮,自己做个替代的“最大化”按钮,实现窗体放大。当点击“最大化”时,触发Form的ReSize事件,在Form的ReSize事件中,写入:
Private Sub Form_Resize()
Form1.Left = 0
Form1.Top = 0
Form1.Width = Screen.Width
Form1.Height = Screen.Height - GetTaskbarHeight
End Sub
(当程序启动时,也会同时触发Form_ReSize的)
其中,GetTaskbarHeight的获取要写进模块文件中:
Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
Public Const SPI_GETWORKAREA = 48
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Function GetTaskbarHeight() As Integer
Dim lRes As Long
Dim rectVal As RECT
lRes = SystemParametersInfo(SPI_GETWORKAREA, 0, rectVal, 0)
GetTaskbarHeight = ((Screen.Height / Screen.TwipsPerPixelX) -rectVal.Bottom) * Screen.TwipsPerPixelX
End Function
但是,这样做还要考虑到有些人把任务栏移到其他地方的,比如左侧,右侧,甚至隐藏,所以,也是很麻烦的哦
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
2013-09-11
展开全部
在模块中写入一下内容:Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject 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 Sub Command1_Click()
Dim RRGN As Long
RRGN = CreateRectRgn(0, 0, Form1.Width / 15, Form1.Height / 15)
SetWindowRgn Me.hwnd, RRGN, True
DeleteObject RRGN
End SubPrivate Sub Command2_Click()
Me.Height = Screen.Height + 1500
Me.Width = Screen.Width
Me.Move 0, -350
Timer1.Enabled = True
End SubPrivate Sub Command3_Click()
Unload Me
End SubPrivate Sub Command4_Click()
Dim RRGN As Long
RRGN = CreateRectRgn(0, 22, Form1.Width / 15, Form1.Height / 15)
SetWindowRgn Me.hwnd, RRGN, True
DeleteObject RRGN
End SubPrivate Sub Timer1_Timer()
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3
End Sub 这段程序有1个BUG之处就是不能完全遮盖任务栏,运行时先将timer的enabled属性设置为false。Interval属性设置为10
Public Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject 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 Sub Command1_Click()
Dim RRGN As Long
RRGN = CreateRectRgn(0, 0, Form1.Width / 15, Form1.Height / 15)
SetWindowRgn Me.hwnd, RRGN, True
DeleteObject RRGN
End SubPrivate Sub Command2_Click()
Me.Height = Screen.Height + 1500
Me.Width = Screen.Width
Me.Move 0, -350
Timer1.Enabled = True
End SubPrivate Sub Command3_Click()
Unload Me
End SubPrivate Sub Command4_Click()
Dim RRGN As Long
RRGN = CreateRectRgn(0, 22, Form1.Width / 15, Form1.Height / 15)
SetWindowRgn Me.hwnd, RRGN, True
DeleteObject RRGN
End SubPrivate Sub Timer1_Timer()
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3
End Sub 这段程序有1个BUG之处就是不能完全遮盖任务栏,运行时先将timer的enabled属性设置为false。Interval属性设置为10
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-11
展开全部
第一个问题代码:
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 Const GWL_STYLE = (-16)
Private Const WS_SYSMENU = &H80000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_MAXIMIZEBOX = &H10000
Private Sub Form_Load()
Dim lStyle As Long
lStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
lStyle = lStyle Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX Or WS_SYSMENU
SetWindowLong Me.hwnd, GWL_STYLE, lStyle
End Sub
第二问题没看懂
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 Const GWL_STYLE = (-16)
Private Const WS_SYSMENU = &H80000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_MAXIMIZEBOX = &H10000
Private Sub Form_Load()
Dim lStyle As Long
lStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
lStyle = lStyle Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX Or WS_SYSMENU
SetWindowLong Me.hwnd, GWL_STYLE, lStyle
End Sub
第二问题没看懂
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询