PDA

Click to See Complete Forum and Search --> : Making sure an OUTLOOK window is on top...


BenFinkel
Mar 20th, 2002, 10:24 AM
I have a program that automates MS Outlook and I want to make sure that outlook is on Top and active when the code runs.

The problem is that the code sends an email automatically, and if Outlook is already open but minimized, a security form pops-up in the background, and the user has no idea.

Before I create and send the email, I want to pop MS Outlook to the front so that they can see the security dialog without having to click the start bar.

Here is the beginning of the code:

Dim appOutlook As Outlook.Application
Dim miMail As Outlook.MailItem
Dim rsIntroEmailInfo As DAO.Recordset
Dim strFileName As String

Dim lngTemp As Long

Set appOutlook = New Outlook.Application

'Make sure Outlook is shown and maximized

Set miMail = appOutlook.CreateItem(olMailItem)


I was thinking I could use the SHOWWINDOW api call, but I cannot figure out how to get a handle (hWnd) to Outlook (the application object does not expose hWnd).

So, does anyone know how I could either
A)Make outlook active and maximized
or
B)Get a hWnd to an Outlook.Application object

?

Thanks guys!!

--Ben

BenFinkel
Mar 20th, 2002, 11:08 AM
I like to keep everyone updated, this is what I ended up doing:



Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Declare Function EnumWindows Lib "user32" (ByVal lpFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long

Public lngOutlookHWnd As Long

Public Function EnumWindProc(ByVal hWnd As Long, ByVal lParam As Long) As Long

Dim strTitle As String
Dim lngTemp As Long

strTitle = String(255, 0)
lngTemp = GetWindowText(hWnd, strTitle, 255)

If Left(strTitle, lngTemp) = "Microsoft Outlook" Then
lngOutlookHWnd = hWnd
EnumWindProc = 0
Exit Function
End If

EnumWindProc = 1

End Function
Public Function GetOutlookHWnd() As Long

EnumWindows AddressOf EnumWindProc, 0

End Function

Public Function EmailIntro(lngContactID As Long)

On Error GoTo Error_EmailIntro

Dim appOutlook As Outlook.Application
Dim miMail As Outlook.MailItem
Dim rsIntroEmailInfo As DAO.Recordset
Dim strFileName As String

Dim lngTemp As Long

Set appOutlook = New Outlook.Application

'Make sure Outlook is shown and maximized
GetOutlookHWnd
ShowWindow lngOutlookHWnd, SW_SHOWMAXIMIZED

Set miMail = appOutlook.CreateItem(olMailItem)
...
ETC




Basically, I enumerate the windows to find the window with the text "Microsoft Outlook" then I set that particular windows hWnd to a global variable, which I pass to the ShowWindow function.

Thanks anyways guys!