How to get the Handle that is executed in winexec or shellexecute?

前端 未结 3 1810
温柔的废话
温柔的废话 2021-01-28 09:54

i use to create a custom function like winexec(...):Hwnd that will retun the handle of executed application.

i did use the findwindow() but having problem if it change w

3条回答
  •  无人共我
    2021-01-28 10:30

    Try example 6 from this page (http://delphidabbler.com/tips/134) and just modify it a little bit. That's what I did.

    if you want to split where you check and where you review your result you can do something like

    var
      //...
      runNext : Boolean;
      //...
    
    begin
    { startup code from other sample here }
    
    // but instead of if
    runNext := ShellExecuteEx(@SEInfo);
    
    { some more code here }
    
        // need delay before running next process
        // run loop until window with Handle is closed
    if runNext then
        with SEInfo do
         repeat
          GetExitCodeProcess(SEInfo.hProcess, ExitCode);
          Sleep(20);
          Application.ProcessMessages;
          CheckSynchronize();
        until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
    
    { next process code here }
    end;
    

    I realize some of you will drop hate mail on this for throwing in Sleep(), but I'd rather not lock windows up until that execute is finished when I'm processing a boatload of stuff and waiting.

提交回复
热议问题