|
Carl Williams
Posts: 8
Joined: 2007-04-09
|
I am trying to position outlook on top of my app in a specific location
I send a message to my Addin dll which use the below code
procedure TAddInModule.ProcessPosition(ileft,itop,iwidth,ihgt: integer);
var
Wnd: HWND;
IWindow: IOleWindow;
HeightVal, WidthVal: integer;
begin
{these four lines work fine bu I need to get outlook to the front}
Self.OutlookApp.Application.ActiveExplorer.Top := itop;
Self.OutlookApp.Application.ActiveExplorer.Left := ileft;
Self.OutlookApp.Application.ActiveExplorer.Height := ihgt;
Self.OutlookApp.Application.ActiveExplorer.Width := iwidth;
{below code does nothing, I think I have the wrong windows handle}
Self.OutlookApp.ActiveExplorer.QueryInterface(IOleWindow, IWindow);
if Assigned(IWindow) then begin
IWindow.GetWindow(Wnd);
IWindow := nil;
end;
HeightVal := 600;
WidthVal := 1000;
// Windows.BringWindowToTop(Wnd);
Windows.SetWindowPos(Wnd,Wnd,ileft,itop,iwidth,ihgt,0);
end; |
|
Posted 06 Apr, 2018 09:02:20
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18825
Joined: 2006-05-11
|
Hello Carl,
You get the HWND of an Outlook window using TAddInModule.GetOutlookWindowHandle().
Andrei Smolin
Add-in Express Team Leader |
|
Posted 09 Apr, 2018 03:33:55
|
|
Top
|
|
Carl Williams
Posts: 8
Joined: 2007-04-09
|
Thank you for the quick response Andrei.
that method requires an Idispatch interface be passed as a parameter.
which interface do i need to pass
Thanks Carl |
|
Posted 09 Apr, 2018 08:55:38
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18825
Joined: 2006-05-11
|
You need to pass an IDispatch representing an Explorer or Inspector object.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 09 Apr, 2018 09:18:34
|
|
Top
|
|
Carl Williams
Posts: 8
Joined: 2007-04-09
|
That is what i thought.
when i use
Wnd := Self.GetOutlookWindowHandle(Self.OutlookApp.ActiveExplorer);
wnd has a windows handle
but the below code does not move outlook
ileft:= 10;
itop:= 10;
iwidth:= 500;
ihgt:= 500;
Windows.SetWindowPos(Wnd,Wnd,ileft,itop,iwidth,ihgt,0);
is there a better way to position outlokk and place it on top of my app communicating with the addin dll |
|
Posted 09 Apr, 2018 11:18:34
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18825
Joined: 2006-05-11
|
Hello Carl,
Carl Williams writes:
Windows.SetWindowPos(Wnd,Wnd,ileft,itop,iwidth,ihgt,0);
This seemingly is a mistake: you put a window after itself? If SetWindowPos doesn't reposition the Outlook window in the Z direction, try to use SetForegroundWindow.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 10 Apr, 2018 05:48:00
|
|
Top
|
|
Carl Williams
Posts: 8
Joined: 2007-04-09
|
the purpose of this code is to allow another of my applications to tell outlook to position it self at a certain location on top of part of the requesting application. My addin dll is trying to process that request
My other app send a message with the top left height and width of the location desired and this code inside outlook was supposed to do the positioning. Ny thought was I could tell Outlook with coded in my addin to do the desired positioning.
statements like
Self.OutlookApp.Application.ActiveExplorer.Top := itop;
Self.OutlookApp.Application.ActiveExplorer.Left := ileft;
move outlook main windows
however the handle from Wnd := Self.GetOutlookWindowHandle(Self.OutlookApp.ActiveExplorer);
when used in Windows.SetWindowPos(Wnd,Wnd,ileft,itop,iwidth,ihgt,0);
does not put on top or move Outlook at all. |
|
Posted 10 Apr, 2018 12:59:38
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18825
Joined: 2006-05-11
|
Hello Carl,
Carl Williams writes:
when used in Windows.SetWindowPos(Wnd,Wnd,ileft,itop,iwidth,ihgt,0);
I warned you about the SetWindowPos(Wnd,Wnd part.
Here's a C# code fragment to give you an idea; you'll need to use this approach in your code. The fragment below is executed in a Form; module is a reference to the add-in module; Marshal.ReleaseComObject(expl) stands for setting a variable referencing an Explorer object to nil.
[DllImport("user32.dll", SetLastError = true)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowPosFlags uFlags);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SetActiveWindow(IntPtr hWnd);
[Flags]
public enum SetWindowPosFlags : uint
{
SWP_ASYNCWINDOWPOS = 0x4000,
SWP_DEFERERASE = 0x2000,
SWP_DRAWFRAME = 0x0020,
SWP_FRAMECHANGED = 0x0020,
SWP_HIDEWINDOW = 0x0080,
SWP_NOACTIVATE = 0x0010,
SWP_NOCOPYBITS = 0x0100,
SWP_NOMOVE = 0x0002,
SWP_NOOWNERZORDER = 0x0200,
SWP_NOREDRAW = 0x0008,
SWP_NOREPOSITION = 0x0200,
SWP_NOSENDCHANGING = 0x0400,
SWP_NOSIZE = 0x0001,
SWP_NOZORDER = 0x0004,
SWP_SHOWWINDOW = 0x0040,
}
private void button1_Click(object sender, EventArgs e)
{
var expl = module.OutlookApp.ActiveExplorer();
if (expl != null)
{
IntPtr mainWindow = module.GetOutlookWindowHandle(expl);
if (mainWindow != IntPtr.Zero)
{
SetActiveWindow(mainWindow);
SetWindowPos(mainWindow, IntPtr.Zero, Left + 100, Top + 100, 0, 0, SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_NOSIZE);
}
Marshal.ReleaseComObject(expl);
}
}
Andrei Smolin
Add-in Express Team Leader |
|
Posted 11 Apr, 2018 06:20:18
|
|
Top
|
|