在C# 如果取得一个进程内的所有窗口句柄,我想对指定子窗体进行操作置顶.我现在只能通过process.MainWindowHandle 取得主窗口句柄,
使用GetWindow 取不到了窗体?下面有段C++的,不记得地址了 也看不太明白:HWND hPowerpoint,hCloseWindow;
char ChildWinName[30];
CString m_sOpenPptName; //列举Powerpoint窗口的所有子窗口的回调函数
BOOL CALLBACK
EnumChildProc(HWND hwnd, LPARAM arg)
{
if(strcmp(ChildWinName,"")==0) return TRUE;
CWnd *pWnd=CWnd::FromHandle( hwnd ); //注意这一行
if( pWnd->IsWindowVisible() )
{
CString subwn;
pWnd->GetWindowText(subwn);
if(strcmp(subwn,ChildWinName)==0)
{
ShowWindow(hwnd,SW_SHOWNORMAL);
hCloseWindow=hwnd;
}
}
return TRUE;
}//列举所有顶层窗口的回调函数
BOOL CALLBACK
EnumWindowsFn(HWND hwnd, LPARAM arg)
{
hPowerpoint=NULL;
char str[30];
char temp[50];
char tempchar[2];
bool start=false;
GetWindowText(hwnd,str,21);
if(strcmp(str,"Microsoft PowerPoint")==0)
{
BringWindowToTop(hwnd);
GetWindowText(hwnd,temp,50);
strcpy(ChildWinName,""); for(int i=0;i<50;i++)
{
if( temp[i]=='[' )
{
start=true;
continue;
}
if( temp[i]==']' )
{
break;
}
if(start)
{
tempchar[0]=temp[i];
tempchar[1]='\0';
strcat(ChildWinName,tempchar);
}
}
if(strcmp(ChildWinName,"")==0) return true;
hPowerpoint=hwnd;
if(hPowerpoint!=NULL)
{
EnumChildWindows(hPowerpoint,EnumChildProc,NULL);
}
}
return true;
}
使用GetWindow 取不到了窗体?下面有段C++的,不记得地址了 也看不太明白:HWND hPowerpoint,hCloseWindow;
char ChildWinName[30];
CString m_sOpenPptName; //列举Powerpoint窗口的所有子窗口的回调函数
BOOL CALLBACK
EnumChildProc(HWND hwnd, LPARAM arg)
{
if(strcmp(ChildWinName,"")==0) return TRUE;
CWnd *pWnd=CWnd::FromHandle( hwnd ); //注意这一行
if( pWnd->IsWindowVisible() )
{
CString subwn;
pWnd->GetWindowText(subwn);
if(strcmp(subwn,ChildWinName)==0)
{
ShowWindow(hwnd,SW_SHOWNORMAL);
hCloseWindow=hwnd;
}
}
return TRUE;
}//列举所有顶层窗口的回调函数
BOOL CALLBACK
EnumWindowsFn(HWND hwnd, LPARAM arg)
{
hPowerpoint=NULL;
char str[30];
char temp[50];
char tempchar[2];
bool start=false;
GetWindowText(hwnd,str,21);
if(strcmp(str,"Microsoft PowerPoint")==0)
{
BringWindowToTop(hwnd);
GetWindowText(hwnd,temp,50);
strcpy(ChildWinName,""); for(int i=0;i<50;i++)
{
if( temp[i]=='[' )
{
start=true;
continue;
}
if( temp[i]==']' )
{
break;
}
if(start)
{
tempchar[0]=temp[i];
tempchar[1]='\0';
strcat(ChildWinName,tempchar);
}
}
if(strcmp(ChildWinName,"")==0) return true;
hPowerpoint=hwnd;
if(hPowerpoint!=NULL)
{
EnumChildWindows(hPowerpoint,EnumChildProc,NULL);
}
}
return true;
}
HWND FindWindow(LPCTSTR IpClassName,LPCTSTR IpWindowName)
第一个参数用一个标识类名的字符串。第二个参数是窗口的标题,在这个具体的地方你给个null好了。调用成功返回句柄,失败返回null
已经搞定,原来有这么好的函数.问个小小的问题, 这东东怎么结贴啊~_~
我设置的一个视频窗口置顶后,只要打开还移动其它窗体,刚才被置顶的窗口将不为最顶层,我的 SetWindowPos(handle, -1, 50, 50, 300, 260, 3);
是呼只是激活,并未置顶, 如果让它保持置顶?