如何获取控件句柄当前光标所在的控件的句柄

在VB中,怎么样获取当前鼠标(或光标)所在位置控件的句柄(或名称)??
我在做一个监控所有输入的程序,使用的是VB+API,想获取当前光标所在位置的文本框的句柄或者名称。请各位尽量提供详细的解决方案。在此谢谢你们了。我把我所有的分都拿出来了。谢谢大家了。急啊。
09-09-19 &
截获消息难哦,要用hook 获取句柄还是容易的 用getcursorpos和windowfrompoint就能实现 ====================== 要监听消息也要用hook,你可以去参考syp++ Private Declare Function GetCursorPos Lib &user32& (lpPoint As Any) As Long Private Declare Function WindowFromPoint Lib &user32& (ByVal xPoint As Long, ByVal yPoint As Long) As Long Public Function hWndFromCusror() As Long Dim a(1) As Long GetCursorPos a(0) hWndFromCusror = WindowFromPoint(a(0), a(1)) End Function
请登录后再发表评论!VB&获取当前焦点所在的控件句柄
Option Explicit
Private Declare Function AttachThreadInput Lib "user32" (ByVal
idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long)
Private Declare Function GetWindowThreadProcessId Lib "user32"
(ByVal Hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As
Private Declare Function GetFocus Lib "user32" () As Long
'----------------------------------------------------
'获取当前控件句柄
'----------------------------------------------------
'----------------------------------------------------
Public Function GetHwnd() As Long
&&& Dim Hwnd As
&&& Dim PID As
&&& Dim TID As
hWndFocus As Long
&&&&&&&&&&&&
&&& Hwnd =
GetForegroundWindow
&&& If Hwnd
TID = GetWindowThreadProcessId(Hwnd, PID)
AttachThreadInput App.ThreadID, TID, True
GetHwnd = GetFocus
AttachThreadInput App.ThreadID, TID, False
End Function
------------------------------获取当前鼠标所在Hwnd
Type POINTAPI
Declare Function GetCursorPos Lib "user32 " (lpPoint As POINTAPI)
Declare Function WindowFromPoint Lib "user32 " (ByVal xPoint As
Long, ByVal yPoint As Long) As Long
Sub Timer1_Timer()
& & & Dim P
& & As POINTAPI, h
'获取鼠标当前位置的坐标,以屏幕为坐标系
GetCursorPos P
'获取当前鼠标所在点所属窗口(控件)的句柄
& & & Text1 =
WindowFromPoint(P.X, P.Y)
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。我想在C#中获得控件的句柄,我用过
GetActiveWindows();这个函数,但是提示我不在名称空间内,请问大家:这个函数的名称空间是什么?
还有其他方法可以获得控件的句柄吗?
Control.Handle 就是获取控件绑定到的窗口句柄。
你把上面的Control换成你的控件变量就可以了。
运行QuickSpy.exe,拖动红框内的图标到你想要找句柄的控件上,再点击菜单栏上的[Utils]--[Find Window code gen],再弹出的窗...
好像还没有这个功能。
你就自己慢慢登陆吧,现在都是这样的。
怎样才算通俗,也不知道我下面说的是否通俗?
首先我人为,句柄不是指针(哪怕说是指针的指针,要知道指针包含了太多的信息),若说句柄含有指针的某些意思(或在某种模...
可以啊,你在配置文件对这个参数设的是参数的默认值,当你前台页面中有同名的参数赋了值传递后,在action中得到的是前台赋的值,如果你前台没有赋值,那你actio...
系统(C)如何瘦身的办法:
1.双击我的电脑-右键C盘-属性-常规选项-磁盘清理-磁盘清理要删除的文件的小□打上勾-确定,执行删除.
2.启动IE浏览器-工...
回复 1# marineland行程表能发下参考下吗?谢谢
上面有很多.net的源码,可以参考
答: 你这种要求不可以能做到。
大家还关注
确定举报此问题
举报原因(必选):
广告或垃圾信息
激进时政或意识形态话题
不雅词句或人身攻击
侵犯他人隐私
其它违法和不良信息
报告,这不是个问题
报告原因(必选):
这不是个问题
这个问题分类似乎错了
这个不是我熟悉的地区
相关问答:123456789101112131415温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(369)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'ahk获取光标位置,api获取父窗口句柄',
blogAbstract:'获取光标位置(ByRef left,ByRef top) {;//不用内置的A_CaretX/Y,因为它们在IE8中无效static Size:=8 (A_PtrSize*6) 16static Focused:=8 A_PtrSizeStatic CaretX:=8 (A_PtrSize*6)static CaretY:=CaretX 4VarSetCapacity(Info, Size), NumPut(Size, Info, 0)if !DllCall(\"GetGUIThreadInfo\", \"UInt\", 0, \"Ptr\", &Info)Return, 0if !(HWND:=NumGet(Info, Focused, \"UPtr\"))Return, 0',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:8,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}Option Explicit
Private Declare Function AttachThreadInput Lib "user32" (ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal Hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetFocus Lib "user32" () As Long
'----------------------------------------------------'获取当前控件句柄'----------------------------------------------------'备注:'----------------------------------------------------Public Function GetHwnd() As Long&&& Dim Hwnd As Long&&& Dim PID As Long&&& Dim TID As Long&&& Dim hWndFocus As Long&&&&&&&&&&& &&& Hwnd = GetForegroundWindow&&& &&& If Hwnd Then&&& &&&&&&& TID = GetWindowThreadProcessId(Hwnd, PID)&&&&&&& &&&&&&& AttachThreadInput App.ThreadID, TID, True&&&&&&& &&&&&&& GetHwnd = GetFocus&&&&&&& &&&&&&& AttachThreadInput App.ThreadID, TID, False
&&& End If&&& End Function
阅读(...) 评论() &
欢迎访问翱翔软件

我要回帖

更多关于 获取控件句柄 的文章

 

随机推荐