Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make cross forward plan an application when the other one works 1

Status
Not open for further replies.

fll

Programmer
May 7, 2002
30
BE
I have an application which turns behind the other one and I would like to put it in front of at the precise moment.

How then I to do it?

Thank you in advance.

;-)

Laurent
 
Application.BringToFront

This procedure puts the application in front of all the others application delphi but not in front of other current applications.

How to put the application in front of all the others?


Thank you in advance.


Laurent

;-)
 
This is the code we use to manage our two executables. To get the class name for the application, you can use the Code-insight tool that comes with delphi. If the application you want to manage is written in delphi, the class name will be TApplication. The window name (ASTR_MainFormWindowName), is typically the caption on your main form at the time delphi creates it. You do not need both parameters, but if you have more than one delphi application running, TApplication may not find the one you want without the second parameter.

I hope this helps.


function OpenPreviousInstance (ASTR_ApplicationClassName, ASTR_MainFormWindowName:string):boolean;

//Either parameter can be nil. You only need one in most cases.
var
AppHandle : THandle;
begin
result := false;
AppHandle := FindWindow (PChar (ASTR_ApplicationClassName) , Pchar(ASTR_MainFormWindowName));
if AppHandle <> 0 then
begin
if IsIconic(AppHandle) then
ShowWindow(AppHandle,SW_Restore)
else
BringWindowToTop(AppHandle);
SetForegroundWindow(AppHandle);
CloseHandle(AppHandle);
result := true;
exit;
end;
CloseHandle(AppHandle);
end;
 
If I type &quot;openpreviousinstance('tapplication','Form1')&quot; in a procedure, I obtain every time for the APPHANDLE the value 0.The rest of the function is not thus done.


Laurent

;-)

 
If the other application is not running yet, you need to execute the other program first. We include the the fmxutils.pas (in the delphi demos) in our uses clause and call like this:

if OpenPreviousInstance('Tapplication','CARS') = false then
ExecuteFile('CarsFB.exe','','C:\Apps\CarsFb\Bin\',sw_ShowNormal);

If the application you are trying to contact is already running, then perhaps you do not have the correct name for the application. Try running it with the second parameter as nil : OpenPreviousInstance('TApplication',nil)
This should open the first delphi application the system finds running. If this works, I would try the WinSight and see if the application you are trying to open has a different name than you expect for some reason.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top