作者:绿色风
分类:
时间:2022-08-18
浏览:460
楼主 omnw |
EXCEL窗体未提供最大化/最小化按钮,无法实现WINDOWS中窗口最大化/最小化的效果。通过查询找到EH上yuanzhuping和agstick两位版主提供的代码非常实用,现转帖至此以供大家参考!
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
- Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
- Private Const SW_SHOWMAXIMIZED = 3
- 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 WS_MAXIMIZEBOX = &H10000
- Private Const WS_MINIMIZEBOX = &H20000
- Private Const GWL_STYLE = (-16)
- Private Sub UserForm_Activate() '此代码为窗体弹出时最大化
- hWndForm = FindWindow("ThunderDFrame", Me.Caption)
- ShowWindow hWndForm, SW_SHOWMAXIMIZED
- End Sub
- Private Sub UserForm_Initialize()
- Dim hwnd As Long
- Dim lStyle As Long
- hwnd = FindWindow("ThunderDFrame", Me.Caption) '找到窗口的句柄
- lStyle = GetWindowLong(hwnd, GWL_STYLE) '获得窗口的样式
- lStyle = lStyle Or WS_MINIMIZEBOX '在原窗口样式增加最小化按钮
- lStyle = lStyle Or WS_MAXIMIZEBOX '进一步增加最大化按钮
- lStyle = lStyle Or WS_THICKFRAME '进一步增加窗口边框,使得窗口可以通过鼠标拖拉改变大小
- SetWindowLong hwnd, GWL_STYLE, lStyle '将新的窗口样式指定给窗口,成功。
- End Sub
窗体最大最小化按钮.rar |
2楼 rongjun |
学习API函数 |
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一