如何判断一个Windows句柄是一个Window的句柄而不是Button之类的句柄(300分)

  • 主题发起人 主题发起人 轻舞肥羊
  • 开始时间 开始时间

轻舞肥羊

Unregistered / Unconfirmed
GUEST, unregistred user!
又有300分了~~我有花不完的银子[:D]<br><br>不要用Delphi的思维方式来看问题!看清楚了,是Windows句柄,可以是从任意应用程序得到的!用IsWindow判断后,再怎么做才能确定它是一个Window的句柄?
 
GetClassName
 
Delphi的思维方式???<br>hehe
 
爱元元的哥哥已经说了。
 
用ShowWindow(Handle, SW_SHOWMINNOACTIVE);看一下是否能....方法是苯了點。[:D]
 
getclassname能得到類名。但如果是自己做的窗口類,但起的名字又是怪怪的。好象不行。得做一些技術處理。<br><br>
 
我认为GetClassName &nbsp;根本没有什么作用. 应该获取window的样式.根据样式来判断是否为窗体.
 
其实按钮本来就是窗口。<br>不过还是可以通过一些信息来判断<br>先获得ClassName,再获得ClassInfo<br>typedef struct _WNDCLASSEX { &nbsp; &nbsp;// wc &nbsp;<br>&nbsp; &nbsp; UINT &nbsp; &nbsp;cbSize; <br>&nbsp; &nbsp; UINT &nbsp; &nbsp;style; <br>&nbsp; &nbsp; WNDPROC lpfnWndProc; <br>&nbsp; &nbsp; int &nbsp; &nbsp; cbClsExtra; <br>&nbsp; &nbsp; int &nbsp; &nbsp; cbWndExtra; <br>&nbsp; &nbsp; HANDLE &nbsp;hInstance; <br>&nbsp; &nbsp; HICON &nbsp; hIcon; <br>&nbsp; &nbsp; HCURSOR hCursor; <br>&nbsp; &nbsp; HBRUSH &nbsp;hbrBackground; <br>&nbsp; &nbsp; LPCTSTR lpszMenuName; <br>&nbsp; &nbsp; LPCTSTR lpszClassName; <br>&nbsp; &nbsp; HICON &nbsp; hIconSm; <br>} WNDCLASSEX; <br>&nbsp;基本可以判断
 
我认为这样比较好: <br>Var FResult: LongInt;<br>begin<br>FResult:= GetParent(YourHandle);<br>if FResult= 0 then ShowMessage('窗体句柄')<br>else if FResult= ERROR_INVALID_HANDLE then ShowMessage('无效句柄')<br>else ShowMessage('其他句柄');<br>end;<br>还有什么问题请贴出??????<br>呵呵~~~~~~~~~~~~~~~~`
 
Netsoft:<br>&nbsp; 请看看MyIE2的MDI子窗口,Delphi的Object Inspector窗口,它们都有父的!
 
好像button除了句柄还有id,window的id为0,是不是通过这个可以判断<br>if getwindowlong(hwnd,GWL_ID)=0 then<br>&nbsp; window<br>else<br>&nbsp; button
 
var<br>&nbsp; &nbsp;H:THandle =你的handle;<br>&nbsp; &nbsp;B:Boolean = False;<br><br>function EnumWindowsFunc (WindowHandle: Thandle;lParam: longInt): Boolean; Export; StdCall;<br>begin<br>&nbsp; &nbsp;if H=WindowHandle then <br>&nbsp; &nbsp;begin <br>&nbsp; &nbsp; &nbsp; B:=True;<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;Result := True;<br>end;<br><br>EnumWindows(@EnumWindowsFunc, 0);<br>if B=True then showMessage('这是一个form句柄,真tmd难找!');
 
楼上老兄,<br>人家好象找的是其他应用程序的句柄,而不是自己的
 
我日,“你的handle”的意思就是“你需要查找的句柄”,[:D]
 
现在的人都疯了
 
我日,我看错了,我看成“怎么根据句柄判断一个窗口是按扭了”<br>嘿嘿,楼上的和我们这里的几个朋友有一样的新口头禅啊
 
TO 爱元元的哥哥:<br>&nbsp; 你的代码可以识别Delphi的Object Inspector窗口了,但还是不能识别MDIChild窗口,另外,它把任务栏(Shell_TrayWnd)以及开始菜单左边的竖条(BaseBar)也认为是Window,不知道是什么原因..能解释一下你的原理吗?
 
看来这三百分真难得呀,<br>理论上就是 爱元元的哥哥 老兄的正确啦,<br>EnumWindows函数的意思就是:枚举窗口列表中的所有父窗口(顶级和被所有窗口);<br>呵呵~~~~~~~~~~~~~~~~~
 
基本上是不可能了, 对于Windows来说,都是一样的WINDOW,都有窗口过程,都有句柄<br>EnumWindows可以枚举到一些窗口,但是另一些如上面说到的MYIE的MDI子窗口是枚举不到的<br>或许你看看看各个WINDOW的STYLE及EXSTYLE,也许能从中找到一些规律<br>
 
window和button的区别是什么?如果这个问题弄清楚了,我想问题就解决了
 
后退
顶部