您的位置:程序门 -> vb -> 基础类



获得句柄后如何操作????


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


获得句柄后如何操作????
发表于:2007-08-06 22:12:08 楼主
获得一程序窗口句柄   想用setwindowpos使窗口置于最上端
然后用sendkeys发送ctrl+w

我这样做
hw   =   findwindow( "ieframe ",   vbnullstring)   '获得句柄
setwindowpos   hw,   hwnd_topmost,   0,   0,   0,   0,   swp_nomove   or   swp_nosize
sendkeys   "^w ",   true

但那个hw好像传不到setwindowpos那   啊  
该怎么做那????

请写下完整的实现代码   谢谢谢谢!!!
发表于:2007-08-06 22:31:311楼 得分:0
用sendmessage吧
发表于:2007-08-06 22:33:302楼 得分:0
你先得确认,hw值,是正确.再之后就是,setwindowpos()是否得窗体得到了聚集.
发表于:2007-08-06 23:18:003楼 得分:0
你这个问题跟前面你发过的两帖应该是有联系的,首先搞清楚ctrl+w作用是什么,它是一个关闭窗体的热键,就是要去实现“关闭”,关闭功能我已经在你领一贴里有回帖。
那么现在要做的不是发送ctrl+w,而是做个keypress事件过程,检查是否有ctrl+w事件发生。没必要把你的目标窗口置上置下的。
发表于:2007-08-06 23:32:214楼 得分:0
const   sc_close   =   &hf060
const   wm_syscommand   =   &h112

private   sub   closelabel()
        dim   handlabel   as   long
        dim   hw   as   long
        hw   =   findwindow( "ieframe ",   vbnullstring)   '获得句柄
        handlabel   =   postmessage(hw,   wm_syscommand,   sc_close,   0&)        
end   sub

假如你的程序存在一个窗体
private   sub   form_keypress(keyascii   as   integer)
        if   keyascii=23   then   closelabel
end   sub
发表于:2007-08-06 23:37:305楼 得分:0
因为你sendkeys发送ctrl+w,哪怕目标窗口收到了,它也不知道干啥,你们之间没有要它干啥的协议。
发表于:2007-08-07 15:50:456楼 得分:0
mmyyxx88()   (   )   信誉:100     2007-8-6   23:32:21     得分:   0    
 
 
     
const   sc_close   =   &hf060
const   wm_syscommand   =   &h112

private   sub   closelabel()
        dim   handlabel   as   long
        dim   hw   as   long
        hw   =   findwindow( "ieframe ",   vbnullstring)   '获得句柄
        handlabel   =   postmessage(hw,   wm_syscommand,   sc_close,   0&)        
end   sub

假如你的程序存在一个窗体
private   sub   form_keypress(keyascii   as   integer)
        if   keyascii=23   then   closelabel
end   sub


---------------------------
为什么不直接用   postmessage   hw,wm_close,0&,0&
 
发表于:2007-08-07 16:23:587楼 得分:0
还是哪个傲游吧?
给你个例子,调试通过
private   declare   function   findwindow   lib   "user32 "   alias   "findwindowa "   (byval   lpclassname   as   string,   byval   lpwindowname   as   string)   as   long
private   declare   function   getwindowtext   lib   "user32 "   alias   "getwindowtexta "   (byval   hwnd   as   long,   byval   lpstring   as   string,   byval   cch   as   long)   as   long

private   sub   command1_click()
dim   title   as   string   *   255,   hw   as   long,   ret   as   long
hw   =   findwindow( "ieframe ",   vbnullstring)   '获得句柄
ret   =   getwindowtext(hw,   title,   255)
appactivate   left(title,   ret)
doevents
sendkeys   "^w ",   true

appactivate   me.caption


end   sub

发表于:2007-08-09 12:24:308楼 得分:0
非常感谢大家!   问题我已经解决   是这样的

option   explicit
private   declare   function   findwindow   lib   "user32 "   alias   "findwindowa "   (byval   lpclassname   as   string,   byval   lpwindowname   as   string)   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
private   const   hwnd_topmost   =   -1
private   const   swp_nomove   =   &h2
private   const   swp_nosize   =   &h1
dim   hw_hwnd   as   long

private   sub   command1_click()


hw_hwnd   =   findwindow( "ieframe ",   vbnullstring)

setwindowpos   hw_hwnd,   hwnd_topmost,   0,   0,   0,   0,   swp_nomove   or   swp_nosize
sendkeys   "^w ",   true
end   sub

hw_hwnd声明成这样就能传了   可能大家没理解我的意思   呵呵
我很奇怪为什么那么多人不用傲游   傲游不是用的最多的吗?

那么大家都用什么呢   是firefox吗?

还有就是能否说下你们的学vb的过程   都是怎样学的   是学校教?   还是自学?
我是自学   买了vb编程的两本书   感觉很困难!!!尤其是现在学的vb   api编程   更是找不到教程

大家都是怎么学成现在的水平啊??   我也想成老鸟!!

mmyyxx88   我给你发站内信了
发表于:2007-08-09 12:38:129楼 得分:0
我是自学的,但从来也没有买过书

你为什么不结贴呢,你这个问题都发了两次了
发表于:2007-08-09 20:08:5610楼 得分:0
结贴了   你们是不是就不能回复了啊??
发表于:2007-08-09 20:14:4611楼 得分:0
我很奇怪为什么那么多人不用傲游   傲游不是用的最多的吗?

那么大家都用什么呢   是firefox吗?


快速检索

最新资讯
热门点击