C中使用FindWindow函数详解从标题获取句柄
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
C#中使用Fin dWind ow函数详解从标题获取句柄
FindWi ndow用来根据类名和窗口名来得到窗口句柄的。
但是这个函数
不能查找子窗口,也不区分大小写。
如果要从一个窗口的子窗口中查找需要使用Fi ndWin dowEX。
1.在C#中使用方法如下:
[DllImp ort("User32.dll", EntryP oint= "FindWi ndow")]
privat e static extern IntPtr FindWi ndow(string
lpClas sName,string lpWind owNam e);
[DllImp ort("User32.dll", EntryP oint= "FindWi ndowE x")]
privat e static extern IntPtr FindWi ndowE x(IntPtr hwndPa rent, IntPtr hwndCh ildAf ter, string lpClas sName, string lpWind owNam e); [DllImp ort("User32.dll", EntryP oint= "FindWi ndow")]
privat e static extern IntPtr FindWi ndow(string
lpClas sName,string lpWind owNam e);
[DllImp ort("User32.dll", EntryP oint= "FindWi ndowE x")]
privat e static extern IntPtr FindWi ndowE x(IntPtr hwndPa rent, IntPtr hwndCh ildAf ter, string lpClas sName, string lpWind owNam e);
2. 实例参考:
IntPtr hWnd = FindWi ndow(null, "test Demo");
这样会查找所有titl e是"test Demo"的窗口。
参考下面的资料解释
3. FindWi ndow参数详解:
Parame ters
lpClas sName
[in] Pointe r to a null-termin atedstring that specif ies the classname or a classatom create d by a previo us call to the Regist erCla ss or Regist erCla ssExfuncti on. The atom must be in the low-orderword of lpClas sName; the high-orderword must be zero.
If lpClas sName points to a string, it specif ies the window classname. The classname can be any name regist eredwith Regist erCla ss or Regist erCla ssEx, or any of the predef inedcontro l-classnames.
If lpClas sName is NULL, it findsany window whosetitlematche s the lpWind owNam e parame ter.
lpWind owNam e
[in] Pointe r to a null-termin atedstring that specif ies the window name (the window's title). If this parame ter is NULL, all window namesmatch.
Return Value
If the functi on succee ds, the return valueis a handle to the window that has the specif ied classname and window name.
If the functi on fails, the return valueis NULL. To get extend ed errorinform ation, call GetLas tErro r.
Remark s
If the lpWind owNam e parame ter is not NULL, FindWi ndowcallsthe GetWin dowTe xt functi on to retrie ve the window name for compar ison. For a descri ption of a potent ial proble m that can arise, see the Remark s for GetWin dowTe xt.
To checkif the Micros oft Intell iType versio n 1.x softwa re is runnin g, call FindWi ndowas follow s:
Copy Code
FindWi ndow("MSITPr o::EventQ ueue",NULL); To checkif the
Intell iType versio n 2.0 softwa re is runnin g, call FindWi ndowas follow s:
Copy Code
FindWi ndow("Type32_Main_Wind ow", NULL); If the Intell iType softwa re is runnin g, it sendsWM_APP COMMA ND messag es to the applic ation. Otherw ise the applic ation must instal l a hook to receiv e WM_APP COMMA ND messag es.
Micros oft Window s 95 or later: FindWi ndowW is suppor ted by the Micros oft Layerfor Unicod e (MSLU). To use this, you must add certai n filesto your applic ation, as outlin ed in Micros oft Layerfor Unicod e on Window s 95/98/Me System s.
Exampl e
For an exampl e, see Retrie vingthe Number of MouseWheelScroll Lines.
Functi on Inform ation
Minimu m DLL Versio n user32.dll
Header Declar ed in Winuse r.h, includ e Window s.h
Import librar y User32.lib
Minimu m operat ing system s Window s 95, Window s NT 3.1
Unicod e Implem ented as ANSI and Unicod e versio ns.。