G
gy1969
Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下(防止程序运行多个实例)。<br>虽然能够防止程序运行多个实例,但不能恢复最小化的窗口<br>program App1;<br><br>uses<br> Forms,<br> Windows,<br> UForm1 in 'Unit1.pas' {MainForm};<br><br>{$R *.res}<br><br>procedure Running_Enumwindows;<br> function EnumApps(Wnd: HWND; LPARAM: DWord): Boolean; StdCall;<br> var<br> WndCaption: array[0..254] of Char;<br> begin<br> Result := True;<br> GetWindowText(Wnd, @WndCaption, 254);<br> if (Pos('App1', WndCaption) >= 1) then<br> begin<br> if IsIconic(Wnd) then //这里有什么问题吗<br> ShowWindow(Wnd, SW_RESTORE)<br> else<br> SetForeGroundWindow(Wnd); //这里没问题<br> Result := False;<br> Halt;<br> end;<br> end;<br>begin<br> EnumWindows(@EnumApps, 0);<br>end;<br><br>begin<br> Running_Enumwindows;<br> Application.Initialize;<br> Application.Title := 'App1';<br> Application.CreateForm(TForm1, Form1);<br> Application.Run;<br>end.