已知无是进程ID,如何得知MDI主窗口的类名或句柄
已知无是进程ID,怎么得知MDI主窗口的类名或句柄? - C++ Builder / Windows SDK/API
有网上找了些代码,但都不合我的要求,
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
unsigned long id;
HWND thwnd;
id=GetWindowThreadProcessId(hwnd,NULL);
if(id==(unsigned long)lParam)
{ char xx[100]="\0";
while((thwnd=GetParent(hwnd))!=NULL)
{
hwnd=thwnd;
}
GetClassName(hwnd,xx,100)
MessageBox(NULL,xx,NULL,MB_OK); //这个返回的是工程类TApplication,而的MDI主窗口类名为TFormMain,我想返回TFormMain,但不知如何获得句柄 hwnd的值???
return false;
}
return true;
}
调用:
STARTUPINFO StartInfo;
PROCESS_INFORMATION ProceInfo;
ZeroMemory(&StartInfo,sizeof(StartInfo));
StartInfo.cb=sizeof(StartInfo);
CreateProcess(NULL, //lpApplicationName: PChar
"C:\\MDI.exe", //lpCommandLine: PChar
NULL, //lpProcessAttributes: PSecurityAttributes
NULL, //lpThreadAttributes: PSecurityAttributes
true, //bInheritHandles: BOOL
CREATE_NEW_CONSOLE,
NULL,
NULL,
&StartInfo,
&ProceInfo);
Sleep(5000);
EnumWindows(EnumWindowsProc,ProceInfo.dwThreadId);
MDI.exe运行步骤:
在主窗口FormMain的Paint事件里,ShowModal一个窗口A,在A窗口点击“确定”按键后才激活主窗口FormMain
------解决方案--------------------
Application->MainForm->Handle
有网上找了些代码,但都不合我的要求,
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
unsigned long id;
HWND thwnd;
id=GetWindowThreadProcessId(hwnd,NULL);
if(id==(unsigned long)lParam)
{ char xx[100]="\0";
while((thwnd=GetParent(hwnd))!=NULL)
{
hwnd=thwnd;
}
GetClassName(hwnd,xx,100)
MessageBox(NULL,xx,NULL,MB_OK); //这个返回的是工程类TApplication,而的MDI主窗口类名为TFormMain,我想返回TFormMain,但不知如何获得句柄 hwnd的值???
return false;
}
return true;
}
调用:
STARTUPINFO StartInfo;
PROCESS_INFORMATION ProceInfo;
ZeroMemory(&StartInfo,sizeof(StartInfo));
StartInfo.cb=sizeof(StartInfo);
CreateProcess(NULL, //lpApplicationName: PChar
"C:\\MDI.exe", //lpCommandLine: PChar
NULL, //lpProcessAttributes: PSecurityAttributes
NULL, //lpThreadAttributes: PSecurityAttributes
true, //bInheritHandles: BOOL
CREATE_NEW_CONSOLE,
NULL,
NULL,
&StartInfo,
&ProceInfo);
Sleep(5000);
EnumWindows(EnumWindowsProc,ProceInfo.dwThreadId);
MDI.exe运行步骤:
在主窗口FormMain的Paint事件里,ShowModal一个窗口A,在A窗口点击“确定”按键后才激活主窗口FormMain
------解决方案--------------------
Application->MainForm->Handle