|
Oliver Giesen
Posts: 77
Joined: 2006-08-07
|
[using Turbo Delphi 2006 Pro, ADX 3.6 Pro, Outlook 2003]
Hi all!
Is there a proven (or even recommended) approach to opening modal dialogs from within Outlook addins that still works when the user has the WordMail option activated (or, I expect, is using Outlook 2007)?
Nothing I tried so far is 100% satisfactory. I saw that many of the ADX demos temporarily set Application.Handle := GetActiveWindow before calling ShowModal on anything but this doesn't appear to work when the parent window is an Outlook inspector with IsWordMail = True. I tried using GetForegroundWindow instead but no luck. My modal window still appears somewhere behind the actual inspector.
I previously tried various combinations of FormStyle = fsStayOnTop and CreateParented and overriding CreateParams to muck with the WinAPI directly but the best I was able to achieve so far was that my window appeared on top of ALL other windows. 90% of the time users probably won't notice but it's still quite an ugly hack.
There must be a better way, isn't there?
Oliver |
|
|
Dmitry Kostochko
Add-in Express team
Posts: 2887
Joined: 2004-04-05
|
Hi Oliver,
You can use the GetForegroundWindow function. As far as I remember it always works properly.
uses Windows, Forms, Dialogs, Unit1;
procedure TAddInModule.adxCOMAddInModuleAddInInitialize(Sender: TObject);
begin
FastCommandBarSearch := True;
Application.Handle := GetActiveWindow();
end;
procedure TAddInModule.adxCOMAddInModuleAddInFinalize(Sender: TObject);
begin
Application.Handle := 0;
end;
procedure TAddInModule.adxOlInspectorCommandBar1Controls0Click(Sender: TObject);
var
SavedHandle: HWND;
begin
SavedHandle := Application.Handle;
Application.Handle := GetForegroundWindow();
try
Form1 := TForm1.Create(nil);
try
Form1.ShowModal();
finally
FreeAndNil(Form1);
end;
finally
Application.Handle := SavedHandle;
end;
end;
|
|
|
Oliver Giesen
Posts: 77
Joined: 2006-08-07
|
Hmm, OK, I built a simple test addin and there your example does indeed work as I would want it to. I still haven't managed to achieve the same for my own addin though... (this addin was not started from scratch as an ADX addin - I only recently migrated it to ADX from a homegrown backend framework - it's rather huge and complex already)
Still investigating...
Thanks anyway. If I should find anything that might be worthwhile for others I'll post it back here.
Oliver |
|
|
Oliver Giesen
Posts: 77
Joined: 2006-08-07
|
Right. Got it now! :)
My mistake was that I was trying to be too clever and had moved the handle backup code into an overridden version of the child form's ShowModal method. Obviously setting Application.Handle after the child form had already been created led to some erratic behaviour... ;)
Now there's only one thing left to fix that I was able to reproduce with your sample code as well:
When WordMail is activated it is possible to minimize the inspector window (with the attached modal child form) via the task bar button which is not nice at all as the Outlook window that remains is locked and you have to restore the inspector window and close the modal form before you can get back to it. This doesn't happen when WordMail is turned off.
Sure, nothing major, but ugly none the less. Any ideas?
Thanks a lot for the assistance!
Cheers,
Oliver |
|
|
Dmitry Kostochko
Add-in Express team
Posts: 2887
Joined: 2004-04-05
|
Hi Oliver,
Thank you for the notification.
Sure, nothing major, but ugly none the less. Any ideas?
I am afraid nothing can be done about it.
|
|