【VB】点击控件,窗体不获得焦点

前端之家收集整理的这篇文章主要介绍了【VB】点击控件,窗体不获得焦点前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

首先创建一个Button空间。



然后复制以下代码

Option Explicit
Rem 转移输入焦点的声明
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
Rem 禁止本窗体拥有输入焦点的常数
Private Const HWND_NOTOPMOST = -2
Private Const WS_DISABLED = &H8000000
Private Const GWL_EXSTYLE = (-20)
Private Const GWL_STYLE = (-16)



Private Sub Form_Load()
Rem 窗体调用置顶,且禁止拥有输入焦点
   SetWindowLong Me.hwnd,GWL_EXSTYLE,GetWindowLong(Me.hwnd,GWL_EXSTYLE) Or WS_DISABLED
   
Rem 打开Notepad供测试,并且写入文字
    Dim a
    a = Shell("notepad.exe",vbNormalFocus)
    AppActivate a
    SendKeys "请点击窗体的按钮,看看窗体有没有获得焦点",True
End Sub
然后按下F5运行即可 原文链接:https://www.f2er.com/vb/257134.html

猜你在找的VB相关文章