Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to open outlook new mail in foreground using activex

392 views
Skip to first unread message

Padma Priya Gopalan

unread,
Aug 7, 2001, 7:05:47 AM8/7/01
to
Hi,

I need to open outlook mail through my application. I made
an activex control in VB which has the following code:

Public Sub CreateMailObject()
On Error Resume Next
Set outlookApp = CreateObject
("Outlook.Application")
Set objMailItem = outlookApp.CreateItem(0)
End Sub

Public Sub setSubject(subj As String)
On Error Resume Next
objMailItem.Subject = subj 'subject
End Sub
Public Sub setMessage(msg As String)
On Error Resume Next
objMailItem.Body = msg
End Sub
Public Sub setRecipient(recv As String)
On Error Resume Next
objMailItem.Recipients.Add recv
End Sub
Public Sub setDisplay()
On Error Resume Next
objMailItem.display
End Sub


The client side VBScript code invokes these functions
provided by the activex object. Most of the times the
outlook mail window opens in the foreground.
However if i am in Outlook, open an email, close the email
and then select the Send icon on my application, the new
mail item opens in the background.

Could someone let me know why this is happening and how i
could enforce the mail item to open in the foreground
always.

Thanks for the help.
Regards,
Padma

Dmitry Streblechenko

unread,
Aug 7, 2001, 2:23:36 PM8/7/01
to
I don't think you can do it in the script. In VB/C++/Delphi you'd need to QI the
inspector for IOleWindow, call IOleWindow.GetWindow(), then call
SetForegroundWindow()

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Padma Priya Gopalan" <pp...@yahoo.com> wrote in message
news:f19c01c11f30$e910ad00$9ae62ecf@tkmsftngxa02...

Padma

unread,
Aug 8, 2001, 5:23:13 AM8/8/01
to
My activeX code is written in VB. I tried getting the
Inspector using getInspector and then invoking Activate
method on the inspector. However the window still doesn't
open in the foreground. any idea what is the parallel for
SetForegroundWindow in VB.

Thanks a lot for the help.

padma

>.
>

Hollis D. Paul

unread,
Aug 8, 2001, 11:28:27 AM8/8/01
to
In article <fb2401c11feb$bf5b1e80$9ae62ecf@tkmsftngxa02>, Padma wrote:
> My activeX code is written in VB. I tried getting the
> Inspector using getInspector and then invoking Activate
> method on the inspector. However the window still doesn't
> open in the foreground. any idea what is the parallel for
> SetForegroundWindow in VB.
>
> Thanks a lot for the help.
>
You are trying to be much too complicated here. In the following code,
just add the line to display the message item.

Public Sub CreateMailObject()
On Error Resume Next
Set outlookApp = CreateObject
("Outlook.Application")
Set objMailItem = outlookApp.CreateItem(0)

objMailItem.display '<<<--------------------------<<<
End Sub

Hollis D. Paul [MVP - Outlook]
Hol...@outlookbythesound.com
h...@compuserve.com
Using Virtual Access 4.52 build 277 (32-bit), Windows 2000 build 2195
http://search.support.microsoft.com/kb/c.asp?FR=0&SD=TECH&LN=EN-US

Mukilteo, WA USA


Dmitry Streblechenko

unread,
Aug 8, 2001, 1:23:24 PM8/8/01
to
Unfortunately this code will work under W2K/XP only if you are running in the
same address space as Outlook or if Outlook is already a foreground application.
Othewise you will only get a flashing button on the taskbar most of the time.
It is even more complicated than calling SetForegroundWindow(): you need to
convince Windows that your app has the right to set foreground window of another
application, I usually do it using AttachThreadInput() function.
In Delphi:

function ForceForegroundWindow(hWnd: THandle): BOOL;
var
hCurWnd: THandle;
begin
hCurWnd := GetForegroundWindow;
AttachThreadInput(
GetWindowThreadProcessId(hCurWnd, nil),
GetCurrentThreadId, True);
Result := SetForegroundWindow(hWnd);
AttachThreadInput(
GetWindowThreadProcessId(hCurWnd, nil),
GetCurrentThreadId, False);
end;

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Hollis D. Paul" <Hol...@outlookbythesound.com> wrote in message

Dmitry Streblechenko

unread,
Aug 8, 2001, 1:25:04 PM8/8/01
to
"Padma" <pp...@yahoo.com> wrote in message
news:fb2401c11feb$bf5b1e80$9ae62ecf@tkmsftngxa02...

> My activeX code is written in VB. I tried getting the
> Inspector using getInspector and then invoking Activate
> method on the inspector. However the window still doesn't
> open in the foreground. any idea what is the parallel for
> SetForegroundWindow in VB.

There is no alternative: you need to get down to the Windows API level to set a
foreground window.

Padma Priya Gopalan

unread,
Aug 9, 2001, 2:32:53 AM8/9/01
to
yeah, you are right. I get a flashing button on the
taskbar most of the times. This was my problem. Looks like
it involves too much of low level programming if i need to
get the new mail item in the foreground.
thanks a lot for the help.
>.
>

Hollis D. Paul

unread,
Aug 9, 2001, 9:09:37 AM8/9/01
to
In article <OXIvI7CIBHA.1868@tkmsftngp03>, Dmitry Streblechenko wrote:
> Unfortunately this code will work under W2K/XP only if you are running in the
> same address space as Outlook or if Outlook is already a foreground application.
>
I do seem to have conveniently forgotten that he was doing it from VB. Thanks for
the correction, Dmitry.
0 new messages