【VB】点击控件,窗体不获得焦点
发布时间:2020-12-17 07:41:27 所属栏目:百科 来源:网络整理
导读:首先创建一个Button空间。 然后复制以下代码 Option ExplicitRem 转移输入焦点的声明Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long,ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLo
首先创建一个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运行即可 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |