Starting Outlook from within VB5 
Author Message
 Starting Outlook from within VB5

I have written a VB5 app that scans my MSExchange mailbox and pops up the
Microsoft agent to tell me when new mail arrives.  I have added a popup menu
to the agent with an option to Read Mail.  What I want this to do is start
up Outlook if it is not running, or switch to Outlook if it is already
running, but not the active application.

My platform is NT 4 workstation sp4, Outlook 98, VB5

The code I use is as follows:

Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As
Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal
nCmdShow As Long) As Long

Private Const SW_SHOW = 9
Private Const SW_SHOWNORMAL = 1
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMAXIMIZED = 3

Public Function ActivateOutlook() As Long

  Dim hwnd As Long, lShell As Long, sOutlook as String
  lShell = AppActivateClass("rctrl_renwnd32")
  If Not lShell Then
    iShell = GetKeyValue(HKEY_LOCAL_MACHINE,
"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE", "",
sOutlook)
  lShell = Shell(sOutlook, vbMaximizedFocus)
  ActivateOutlook = lShell
End Function

Private Function AppActivateClass(lpClassName As String) As Boolean
Dim hwnd As Long               ' The application's window handle.
Dim iRetval As Integer         ' Temp variable.
AppActivateClass = False       ' Assume Failure.
hwnd = FindWindow(lpClassName, vbNullString)    ' Get the Window Handle for
                                                ' the className.
If hwnd <> 0 Then                               ' The class was found.
  iRetval = ShowWindow(hwnd, SW_SHOW)
  AppActivateClass = True                     ' Return True if Application
                                                ' Running.
End If
End Function

If Outlook  is not running, the Shell function starts it properly.  If
Outlook is already running but minimised, it sometimes works, but more often
than not I either get a completely gray screen that I have to Alt+Tab out
of, or a grey button-like object in the top left corner of the screen, and a
blank button on the task bar.

Does anyone know why this is happening?



Tue, 19 Mar 2002 03:00:00 GMT  
 Starting Outlook from within VB5
Hi Chris,

following is the code I used for an eMail checker.
The function RegistryGetKeyValue() should be exchanged by your function to
read registry entries.

Public Sub StartDefaultClient()
    Dim MailClient  As String

    MailClient = RegistryGetKeyValue(rrkHKeyLocalMachine,
"SOFTWARE\Clients\Mail", "")
    If MailClient = "" Then
        Call MsgBox(cstrErrorGetDefClient, vbInformation Or vbOKOnly,
App.Title)
    Else
        MailClient = RegistryGetKeyValue(rrkHKeyLocalMachine,
"SOFTWARE\Clients\Mail\" & MailClient & "\shell\open\command", "")
        Call Shell(MailClient, vbNormalFocus)
    End If
End Sub

--
Hope this helps ...

Rene Whitworth
Whitworth Software Solutions - Germany
http://www.w-s-s.de
Please reply to the newsgroup :-)



Quote:
> I have written a VB5 app that scans my MSExchange mailbox and pops up the
> Microsoft agent to tell me when new mail arrives.  I have added a popup
menu
> to the agent with an option to Read Mail.  What I want this to do is start
> up Outlook if it is not running, or switch to Outlook if it is already
> running, but not the active application.

> My platform is NT 4 workstation sp4, Outlook 98, VB5

> The code I use is as follows:

> Option Explicit

> Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal
> lpClassName As String, ByVal lpWindowName As String) As Long
> Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As
> Long) As Long
> Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long,
ByVal
> nCmdShow As Long) As Long

> Private Const SW_SHOW = 9
> Private Const SW_SHOWNORMAL = 1
> Private Const SW_SHOWMINIMIZED = 2
> Private Const SW_SHOWMAXIMIZED = 3

> Public Function ActivateOutlook() As Long

>   Dim hwnd As Long, lShell As Long, sOutlook as String
>   lShell = AppActivateClass("rctrl_renwnd32")
>   If Not lShell Then
>     iShell = GetKeyValue(HKEY_LOCAL_MACHINE,
> "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE", "",
> sOutlook)
>   lShell = Shell(sOutlook, vbMaximizedFocus)
>   ActivateOutlook = lShell
> End Function

> Private Function AppActivateClass(lpClassName As String) As Boolean
> Dim hwnd As Long               ' The application's window handle.
> Dim iRetval As Integer         ' Temp variable.
> AppActivateClass = False       ' Assume Failure.
> hwnd = FindWindow(lpClassName, vbNullString)    ' Get the Window Handle
for
>                                                 ' the className.
> If hwnd <> 0 Then                               ' The class was found.
>   iRetval = ShowWindow(hwnd, SW_SHOW)
>   AppActivateClass = True                     ' Return True if Application
>                                                 ' Running.
> End If
> End Function

> If Outlook  is not running, the Shell function starts it properly.  If
> Outlook is already running but minimised, it sometimes works, but more
often
> than not I either get a completely gray screen that I have to Alt+Tab out
> of, or a grey button-like object in the top left corner of the screen, and
a
> blank button on the task bar.

> Does anyone know why this is happening?



Tue, 19 Mar 2002 03:00:00 GMT  
 Starting Outlook from within VB5
Rene,

The shell command will start up a new instance of the mail client each
time - what I wanted to do was to start a new instance if it was not already
loaded, but to switch to an existing copy if the mail app was already
running.

Quote:

>Hi Chris,

>following is the code I used for an eMail checker.
>The function RegistryGetKeyValue() should be exchanged by your function to
>read registry entries.

>Public Sub StartDefaultClient()
>    Dim MailClient  As String

>    MailClient = RegistryGetKeyValue(rrkHKeyLocalMachine,
>"SOFTWARE\Clients\Mail", "")
>    If MailClient = "" Then
>        Call MsgBox(cstrErrorGetDefClient, vbInformation Or vbOKOnly,
>App.Title)
>    Else
>        MailClient = RegistryGetKeyValue(rrkHKeyLocalMachine,
>"SOFTWARE\Clients\Mail\" & MailClient & "\shell\open\command", "")
>        Call Shell(MailClient, vbNormalFocus)
>    End If
>End Sub

>--
>Hope this helps ...

>Rene Whitworth
>Whitworth Software Solutions - Germany
>http://www.w-s-s.de
>Please reply to the newsgroup :-)



Fri, 22 Mar 2002 03:00:00 GMT  
 Starting Outlook from within VB5
Chris,

on my system I use Outlook Express and the function I posted redirects the
open instance of it to the inbox.
If this doesn't work on Outlook, I'm sorry :-(
You might try something like OLE or DDE.
MS should have some documentation on it in the KB on this.

--
Hope this helps ...

Rene Whitworth
Whitworth Software Solutions - Germany
http://www.w-s-s.de
Please reply to the newsgroup :-)



Quote:
> Rene,

> The shell command will start up a new instance of the mail client each
> time - what I wanted to do was to start a new instance if it was not
already
> loaded, but to switch to an existing copy if the mail app was already
> running.


> >Hi Chris,

> >following is the code I used for an eMail checker.
> >The function RegistryGetKeyValue() should be exchanged by your function
to
> >read registry entries.

> >Public Sub StartDefaultClient()
> >    Dim MailClient  As String

> >    MailClient = RegistryGetKeyValue(rrkHKeyLocalMachine,
> >"SOFTWARE\Clients\Mail", "")
> >    If MailClient = "" Then
> >        Call MsgBox(cstrErrorGetDefClient, vbInformation Or vbOKOnly,
> >App.Title)
> >    Else
> >        MailClient = RegistryGetKeyValue(rrkHKeyLocalMachine,
> >"SOFTWARE\Clients\Mail\" & MailClient & "\shell\open\command", "")
> >        Call Shell(MailClient, vbNormalFocus)
> >    End If
> >End Sub

> >--
> >Hope this helps ...

> >Rene Whitworth
> >Whitworth Software Solutions - Germany
> >http://www.w-s-s.de
> >Please reply to the newsgroup :-)



Sat, 23 Mar 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Starting an MS-DOS prompt from within VB5 App

2. starting DUN within VB5

3. Problem starting Acces 97 after having started Outlook 2000

4. Start a macro automaticly when starting outlook

5. Print out MS Outlook calendars via VBA WITHIN MS Outlook

6. Referencing the Outlook Application from a Web Page running within Outlook

7. Accessing Outlook Adressbook without starting Outlook

8. enable macros in outlook when outlook starts

9. Compiling a VB5 DLL from within VB5

10. Starting an application from within Access.

11. Starting Word from within Access2K

12. Start Macro within opening eMail

 

 
Powered by phpBB® Forum Software