作者:绿色风
分类:
时间:2022-08-17
浏览:192
楼主 0Mouse |
Q:以非模式状态显示窗体后如何将光标置于指定文本框控件内呢? 预期效果示意图:
A:插入一个模块,录入以下代码:
- '声明相关的API函数
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
- (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
- Private Declare Function GetWindowRect Lib "user32" _
- (ByVal hWnd As Long, lpRect As RECT) As Long
- Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
- Private Declare Function SetCursorPos Lib "user32" _
- (ByVal x As Long, ByVal y As Long) As Long
- Private Declare Sub mouse_event Lib "user32" _
- (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, _
- ByVal cButtons As Long, ByVal dwExtraInfo As Long)
- Private Const MOUSEEVENTF_LEFTDOWN = &H2 '声明按下鼠标左键常量
- Private Const MOUSEEVENTF_LEFTUP = &H4 '声明松开鼠标左键常量
- Private Type POINTAPI '自定义POINTAPI类型
- x As Long
- y As Long
- End Type
- Private Type RECT '自定义RECT类型
- Left As Long
- Top As Long
- Right As Long
- Bottom As Long
- End Type
- Sub 以非模式状态显示窗体后将光标置于指定文本框控件内()
- 信息查询.Show 0 '以非模式状态显示窗体
- Dim hWnd As Long '声明用于存储窗口句柄的变量
- Dim myRECT As RECT '声明用于存储窗口区域的变量
- Dim myPos As POINTAPI '声明用于存储光标位置的变量
- hWnd = FindWindow("ThunderDFrame", 信息查询.Caption) '获取窗口句柄
- GetWindowRect hWnd, myRECT '获取窗口区域
- GetCursorPos myPos '获取光标位置
- SetCursorPos myRECT.Left + 40, myRECT.Top + 132 '指定光标位置
- mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '模拟单击操作
- SetCursorPos myPos.x, myPos.y '还原光标位置
- End Sub
附件: 以非模式状态显示窗体后将光标置于指定文本框控件内.rar |
2楼 rongjun |
学习了 |
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一