共计 848 个字符,预计需要花费 3 分钟才能阅读完成。
提醒:本文最后更新于 2019-06-11 10:51,文中所关联的信息可能已发生改变,请知悉!
有时候需要把某些窗体置顶到屏幕的最前面,方便的编辑或输入数据,所以网上查了窗口置顶的函数,找到了红尘如烟的窗口置顶自定义函数,只要在模块中申明一下的函数,再到需要置顶的窗体的 Load 下调用就可以了,不需要的时候再调用取消置顶,具体如下:
Option Compare Database
Option Explicit
Private 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
Const API_SWP_NOSIZE = &H1
Const API_SWP_NOMOVE = &H2
Const API_HWND_TOPMOST = -1
Const API_HWND_NOTOPMOST = -2
Public Type POINTAPI
X As Long
Y As Long
End Type‘====================================================================
Function setFormPos(frm As Form, Optional bln As Boolean = True) As Boolean
If bln = True Then
SetWindowPos frm.hwnd, -1, 0, 0, 0, 0, 3‘置顶
Else
SetWindowPos frm.hwnd, -2, 0, 0, 0, 0, 3‘正常
End If
If Err.Number = 0 Then
setFormPos = True
Else
setFormPos = False
End If
End Function
// 实际使用
Private Sub Form_Load()
setFormPos Me‘调用函数,置顶
Private Sub Form_Load()
setFormPos Me, False‘调用函数,取消置顶
正文完