how to open outlook new mail in foreground using activex 
Author Message
 how to open outlook new mail in foreground using activex

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



Sat, 24 Jan 2004 19:05:47 GMT  
 how to open outlook new mail in foreground using activex
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



Quote:
> 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



Sun, 25 Jan 2004 02:23:36 GMT  
 how to open outlook new mail in foreground using activex
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

Quote:
>-----Original Message-----
>I don't think you can do it in the script. In

VB/C++/Delphi you'd need to QI the
Quote:
>inspector for IOleWindow, call IOleWindow.GetWindow(),
then call
>SetForegroundWindow()

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



>> 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

>.



Sun, 25 Jan 2004 17:23:13 GMT  
 how to open outlook new mail in foreground using activex
Quote:

> 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]


 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



Sun, 25 Jan 2004 16:28:27 GMT  
 how to open outlook new mail in foreground using activex
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


Quote:
> 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]


>  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



Mon, 26 Jan 2004 01:23:24 GMT  
 how to open outlook new mail in foreground using activex

Quote:
> 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.

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



Mon, 26 Jan 2004 01:25:04 GMT  
 how to open outlook new mail in foreground using activex
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.
Quote:
>-----Original Message-----
>Unfortunately this code will work under W2K/XP only if

you are running in the
Quote:
>same address space as Outlook or if Outlook is already a

foreground application.
Quote:
>Othewise you will only get a flashing button on the

taskbar most of the time.
Quote:
>It is even more complicated than calling

SetForegroundWindow(): you need to
Quote:
>convince Windows that your app has the right to set

foreground window of another
Quote:
>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


message
>> 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]


>>  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

- Show quoted text -

Quote:

>>  Mukilteo, WA  USA

>.



Mon, 26 Jan 2004 14:32:53 GMT  
 how to open outlook new mail in foreground using activex
Quote:

> 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.

 Hollis D. Paul [MVP - Outlook]


 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



Mon, 26 Jan 2004 14:09:37 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Notification when a new e-mail is sent to any e-mail Outlook folder

2. Access report to Outlook/ Open Outlook and mail report

3. Access report to Outlook/ Open Outlook and mail report

4. Sending mail without using MS Outlook or other mail client

5. Creating mail accounts for Outlook/Outlook Express using VB

6. Having vb program create new distribution list in Outlook to send mail to

7. Outlook 98 Automation - Getting NEW mail

8. Calling new e-mail dialog from Outlook

9. I don′t get Mapi and Outlook Express to receive new mail

10. How to create new outlook mail through VB 6

11. How to Compose new Outlook mail from VB5 ?

12. Outlook System Tray New Mail Notification

 

 
Powered by phpBB® Forum Software