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

VB中程序界面显示在桌面最上层的源代码

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

声明:

‘设置显示最前全局变量
Dim OnTop As Long
‘显示在最前
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 SWP_NOMOVE = &H2 ‘不更动目前视窗位置
Const SWP_NOSIZE = &H1 ‘不更动目前视窗大小
Const HWND_TOPMOST = -1 ‘设定为最上层
Const HWND_NOTOPMOST = -2 ‘取消最上层设定
Const FLAGS = SWP_NOMOVE or SWP_NOSIZE

在按钮的CLICK事件中输入代码

Private Sub showtop_Click()
If OnTop = 1 Then
showtop.Caption = “取消最前”
‘将 APP 视窗设定成永远保持在最上层
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS
OnTop = 2
Else
showtop.Caption = “最前显示”
‘取消最上层设定
SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS
OnTop = 1
End If
End Sub


金刀客博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明VB中程序界面显示在桌面最上层的源代码
喜欢 (8)
发表我的评论
取消评论

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