Currently I am working on VB.Net Add-in for MS Outlook 2010 that allows to copy Outlook mail item to Lotus Notes mail database. I am almost completed it and though I met many interesting challenges on my way one of the most interesting was about focusing of Lotus Notes window.
Solution architecture was following: Outlook Add-in (a button in Outlook explorer/inspector ribbon) gets ID of selected/opened Mail item, creates OLE object of Lotus Notes, passes that ID to notes.ini and finally calls a NotesAgent that does the rest of a job using lotusscript.
The NotesAgent asked user several questions during its work so I had to switch focus to Lotus Notes window at some point. Native ActivateApp() function didn't work neither in Add-in VB.Net nor in NotesAgent lotusscript. After Googling a little I found a couple of suggestions based on Windows API:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdSHow As Long) As Long
hWin = FindWindow("NOTES", &H0) 'I used lpClassName = "NOTES" because it looked logically and
' because all examples in Google did the same.
Call ShowWindow(hWin, 3)
I utilized this workaround in my NotesAgent and on first sight it worked well.
However later I noticed that it opened a second IBM Lotus Notes window that looked like a basic version of Lotus Notes though I used standard (Eclipse-based) IBM Lotus Notes 8.5.3.
I knew that Eclipsed-based version of Lotus Notes process (notes2.exe) had been invoked by nlnotes.exe and I also knew that if you run nlnotes.exe manually you would get basic version of IBM Lotus Notes.
Though documentation said that nlnotes.exe should be unloaded after running notes2.exe I would say that it stuck somewhere around. I wouldn't like guessing too much, probably C++ guys could explain that better.
So, I downloaded a tool that let me see currently opened windows properties (I used WinListener) and then I finally realized that I had to use className "SWT_Window0" to rich a window of my standard IBM Lotus Notes.
SWT_Window0 - magnificent class name for a window of IBM Lotus Notes standard version.
Finally I slightly update my code and got this worked
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdSHow As Long) As Long
Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
hWin = FindWindow("SWT_Window0", &H0)
If hWin = 0 then
hWin = FindWindow("NOTES", &H0)
End if
If hWin = 0 then
hWin = FindWindow("NOTES", &H0)
End if
If hWin > 0 Then
Call ShowWindow(hWin, 3)
Call SetForegroundWindow(hWin)
End if
Fantastic, exactly what I am looking for. Thank you so much!
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDelete