进程启动完毕,然后调用函数EnumWindows(EnumWindowsProc,0)   
  //EnumWindowsProc是回调函数   
  回调函数EnumWindowsProc为:   
  BOOL   CALLBACK   EnumWindowsProc(HWND   hwnd,LPARAM   lparam)   
  {   
  CString   strPrompt;   
  DWORD   ProcId;   
  DWORD   ThreadId;   
  ThreadId=GetWindowThreadProcessId(hwnd,&ProcId)   
  if(ProcId==ProcessInfo.dwProcessId)   
  {   
  HWND   targetWin;   
  targetWin=hwnd;   
  while(true)   
  {   
  HWND   hTemp;   
  hTemp=GetParent(targetWin);   
  if(hTemp==NULL)   
  break;   
  else   
  targetWin=hTemp;   
  }   
  char   szTemp[255];   
  sprintf(szTemp,"%x",ProcId);   
  CString   strTemp=szTemp;   
  GetWindowText(targetWin,strTemp.GetBuffer(255),255);   
  return   FALSE;   
  }   
  else   
  return   true;   
  }

解决方案 »

  1.   

    function EnumWindowsProc(hwnd:THandle;lparam:Integer):LongBool;stdcall;  
    var
      strTemp,strPrompt:string;  
      ProcId:DWORD;  
      ThreadId:DWORD;
      hTemp,targetWin:THandle;
    begin 
      Result := false; 
      ThreadId:=GetWindowThreadProcessId(hwnd,ProcId)  
      if(ProcId=ProcessInfo.dwProcessId) then  
      begin
        targetWin:=hwnd;  
        while (true) do
        begin  
          hTemp:=GetParent(targetWin);  
          if(hTemp=0) then break
          else targetWin=hTemp;  
        end;  
        strTemp := format('%x',[ProcId]); 
        SetLength(strPrompt,255); 
        SetLength(strPrompt,GetWindowText(targetWin,PChar(strPrompt),255));  
        Exit;
      end
      else  
        Result := true;  
    end;