Dennis van der Meulen
Guest
|
Hello,
I want to make the form inside an executable behave like a form inside an add-in or a form inside an dll.
Let me explain:
1. form inside an add-in
var
SaveHandle: HWND;
begin
SaveHandle := Application.Handle;
Application.Handle := GetForegroundWindow;
Form1 := TForm1.Create(Application);
try
Form1.ShowModal;
finally
Application.Handle := SaveHandle;
FreeAndNil(Form1);
end;
end;
This form inside an add-in is part of the add-in. When this form is on the screen the add-in cannot be accessed.
Perfect!
2. form inside an dll
var
myFilePath: string
myDLLHandle: THandle;
ShowForm: TShowForm;
begin
myFilePath := Self.COMAddInClassFactory.FilePath;
myDLLHandle := LoadLibrary(PChar(myFilePath + 'my.dll'));
if myDLLHandle <> 0 then
begin
try
@ShowForm := GetProcAddress(myDLLHandle, 'ShowForm');
if Addr(ShowForm) <> nil then
begin
try
ShowForm;
except
on E: SysUtils.Exception do
ShowMessage('ShowForm: ' + E.Message);
end;
end;
finally
FreeLibrary(myDllHandle);
end;
end;
end;
A form inside this dll is part of the add-in. When this form is on the screen the add-in cannot be accessed.
Before the form inside the dll is created I do : Application.Handle := GetForegroundWindow;
Perfect!
3. form inside an exe
var
myFilePath: string
begin
myFilePath := Self.COMAddInClassFactory.FilePath;
ShellExecute(0, 'OPEN', PChar(myFilePath + 'my.exe'),
PChar(IntToStr(Application.Handle)), '', SW_SHOWNORMAL);
end;
This starts the exe but it is in no way part of the add-in. It has no connection with the add-in.
Is this possible at all? I'm not asking for a worked out solution, but a push in the right direction would be very much appreciated!
Thank you. |
|
Andrei Smolin
Add-in Express team
Posts: 18794
Joined: 2006-05-11
|
Hello Dennis,
I strongly believe that it is impossible for a Windows process to show a form so that the form is modal for another process.
Consider creating a public procedure showing the form in your add-in module and invoking that procedure from the .EXE; see the sample project at http://www.add-in-express.com/files/projects_pub/add-in-with-external-app.zip.
Andrei Smolin
Add-in Express Team Leader |
|
Dennis van der Meulen
Guest
|
Hello Andrei,
I had a kind of feeling that this one would be very difficult or indeed impossible.
Thanks for the cool demo and I will give that a try!
Kind regards,
Dennis |
|
Andrei Smolin
Add-in Express team
Posts: 18794
Joined: 2006-05-11
|
You are welcome!
Andrei Smolin
Add-in Express Team Leader |
|