























gnFindWindow(String caption, integer nParentHwnd)
功能:递归式查找所有的窗口,包括多层的子窗口,以找到标题为包含<参数1>的窗口句柄。
这样可以找到报表窗口了。
一般情况下,在VFP里处理不到报表窗口,用这函数取得它句柄后,就可以随心所欲的处置它了。
参数1 :窗口标题的一部分文本。
参数2(选项):父窗口句柄 hwnd,用来限定搜索的范围。不指定的话,以windows desktop 作范围,即在windows所有窗口及子窗口中查找。
返回:窗口句柄。
例子:gnFindWindow('Report Designer', _vfp.hwnd)
{"gnFindWindow", (FPFI) gnFindWindow, 2,"C,.I"}
HWND FindWindowByCaption(HWND hParentWin, char * caption)
{ // hParentWin为0,则取desktop
HWND hChild,hNext,hResult=0;
char cTmp[100] ;
string pattern = caption ;if(hParentWin==0)
hParentWin=GetDesktopWindow();
//(0) 每次的处理:比较窗口标题
GetWindowText(hParentWin,cTmp,100);
string s = cTmp;
//(1) 退出条件:找到 包含caption的窗口
if( s.find(pattern,0) != 0xffffffff )
return hParentWin;
//(2) 退出条件: 无子窗口
if( (hChild=GetWindow(hParentWin,GW_CHILD) )==0 )
return hResult; //(3) 进入方法:列举本窗口下的所有子窗口
hNext = hChild ;
while( hNext !=0 )
{
if( (hResult=FindWindowByCaption(hNext,caption))!=0 )
return hResult;
hNext
= GetWindow(hNext,GW_HWNDNEXT);NullTerminate(
&parm->p[0].val);_RetInt( (
long) FindWindowByCaption(hParent, cCaption), 30);写C++,真是不容易呵,过后再看C#,小菜一碟
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。