Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoWhile Loops with XPI calls (in Outlook)? 1

Status
Not open for further replies.

Docpro777

Programmer
Joined
Jul 1, 2003
Messages
105
Location
US
This excellent code is borrowed from Mike Lewis for cycling through MS windows in VFP (which Ramani kindly discovered for me).

I'm trying to make a VFP function suspend running (i.e., in the DOWHILE LOOP) until the user closes the Outlook Appointment (Inspector) Window.

Any help is appreciated in advance.
*********************************************************
DECLARE INTEGER GetActiveWindow IN Win32API
DECLARE INTEGER GetWindow IN Win32API INTEGER hWnd, INTEGER nType
DECLARE INTEGER GetWindowText IN Win32API INTEGER hWnd, STRING @cText, INTEGER nType
DECLARE INTEGER BringWindowToTop IN Win32API INTEGER hWnd
lnHand = IsRunning("- Appointment") &&Outlook Appointment Window
DO WHILE lnHand <> 0
BringWindowToTop(lnHand)
ENDDO
*********************************************************
FUNCTION IsRunning &&Denotes if a WINDOW (title) is running &&eg. &quot;- Visit&quot; for outlook inspector
LPARAMETER tcTitle &&Parameter is all or part of the window's title.
hNext = GetActiveWindow() && current app's window
DO WHILE hNext<>0 && iterate through the open windows
cText = REPLICATE(CHR(0),80)
GetWindowText(hNext,@cText,80) && get window title
IF UPPER(ALLTRIM(tcTitle)) $ UPPER(cText) && parameter text is present in window title
RETURN hNext
ENDIF
hNext = GetWindow(hNext,2) && next window
ENDDO
RETURN 0 && required window not found
ENDFUNC
This excellent code is borrowed from Mike Lewis for cycling through MS windows in VFP (which Ramani kindly discovered for me).

I'm trying to make a VFP function suspend running (i.e., in the DOWHILE LOOP) until the user closes the Outlook Appointment (Inspector) Window.

Any help is appreciated in advance.
*********************************************************
DECLARE INTEGER GetActiveWindow IN Win32API
DECLARE INTEGER GetWindow IN Win32API INTEGER hWnd, INTEGER nType
DECLARE INTEGER GetWindowText IN Win32API INTEGER hWnd, STRING @cText, INTEGER nType
DECLARE INTEGER BringWindowToTop IN Win32API INTEGER hWnd
lnHand = IsRunning(&quot;- Appointment&quot;) &&Outlook Appointment Window
DO WHILE lnHand <> 0
BringWindowToTop(lnHand)
ENDDO
*********************************************************
FUNCTION IsRunning &&Denotes if a WINDOW (title) is running &&eg. &quot;- Visit&quot; for outlook inspector
LPARAMETER tcTitle &&Parameter is all or part of the window's title.
hNext = GetActiveWindow() && current app's window
DO WHILE hNext<>0 && iterate through the open windows
cText = REPLICATE(CHR(0),80)
GetWindowText(hNext,@cText,80) && get window title
IF UPPER(ALLTRIM(tcTitle)) $ UPPER(cText) && parameter text is present in window title
RETURN hNext
ENDIF
hNext = GetWindow(hNext,2) && next window
ENDDO
RETURN 0 && required window not found
ENDFUNC


Philip M. Traynor, DPM
 
HI

You can try and integrate this piece of code..

lnHand = IsRunning(&quot;- Appointment&quot;)
IF lnHand <> 0
BringWindowToTop(lnHand)
ELSE
** start it and take the handle in lnHand
ENDIF

DECLARE INTEGER Sleep IN WIN32API INTEGER nTimeout
DO WHILE lnHand = GetActiveWindow()
Sleep(100)
ENDDO

:-)

ramani :-)
(Subramanian.G)
 
Ramani,

I've tried this code a bit with no avail yet. The only workaround a [WAIT WINDOW &quot;Please Press Enter to Continue&quot;] to suspend VFP during the COM process Outlook.

Thanks, I'll keep working at it. Any other ideas or workarounds?

Philip M. Traynor, DPM
 
Hi Philip,

The only workaround a [WAIT WINDOW &quot;Please Press Enter to Continue&quot;] to suspend VFP during the COM process Outlook.

What you need is a sleep at that place. In the absence of exact code you are using, I am unable to suggest. How exactly you are putting that code?.

In the place of wait statement, you have to put the code..

DECLARE INTEGER Sleep IN WIN32API INTEGER nTimeout
DO WHILE ... a condition to suit your need..
Sleep(100)
ENDDO

In the above example, earlier posted... lnHand will be available, the moment it is initiated. However, the process wont be complete. That is the reason, you are not able to achieve.

Or you have to look for the wait from inside the Application Object to check if that is ready.

For example, in InternetExplorer,
oIe=CREATEOBJECT(InternetExplorer.APplication&quot;
oIe.WaitStatus gives the status of the oIe object.. so we can make a wait using the code..

DECLARE INTEGER Sleep IN WIN32API INTEGER nTimeout
DO WHILE oIE.ReadyState # 4
Sleep(100)
ENDDO

:-)

____________________________________________
Ramani - (Subramanian.G) :-)
When you ask VFP questions, please add VFP version.
 
Also have a look in this FAQ..

A sample form for outlook email handling
faq184-3808

That form is just not email alone, it has something more as well.
:-)

____________________________________________
Ramani - (Subramanian.G) :-)
When you ask VFP questions, please add VFP version.
 
Philoip,

First, thank you for your nice words about my code. I'm glad you found it useful.

Re your question, have you tried the following:

DO WHILE IsRunning(&quot;- Appointment&quot;)
ENDDO

I might have missed something, but it seems the obvious solution.

Mike


Mike Lewis
Edinburgh, Scotland
 
Mike,
I'm sorry for modified your code :-)
yes you missed something. GetActiveWindow will return NULL if the caller apps is not the current thread.


Docpro777,
Try this code. It should work now.

-------------
DECLARE INTEGER GetActiveWindow IN Win32API
DECLARE INTEGER GetWindow IN Win32API INTEGER hWnd, INTEGER nType
DECLARE INTEGER GetWindowText IN Win32API INTEGER hWnd, STRING @cText, INTEGER nType
DECLARE INTEGER BringWindowToTop IN Win32API INTEGER hWnd
DECLARE INTEGER Sleep IN WIN32API INTEGER nTimeout

Declare Long FindWindow in User32 String, String

lcTitle = &quot;- Appointment&quot;
lnHand = IsRunning(@lcTitle) && Is Outlook Appointment running
IF lnHand <> 0
BringWindowToTop(lnHand)
Do while (FindWindow(Null, lcTitle) != 0)
Sleep(100) && give an idle
enddo
endif

*********************************************************

FUNCTION IsRunning &&Denotes if a WINDOW (title) is running &&eg. &quot;- Visit&quot; for outlook inspector
LPARAMETER tcTitle &&Parameter is all or part of the window's title.
hNext = GetActiveWindow() && current app's window
DO WHILE hNext<>0 && iterate through the open windows
cText = REPLICATE(CHR(0),80)
GetWindowText(hNext,@cText,80) && get window title
IF UPPER(ALLTRIM(tcTitle)) $ UPPER(cText)
** parameter text is present in window title
If (at(chr(0), cText) > 0)
cText = left(cText, at(chr(0), cText)-1)
endif
tcTitle = cText
RETURN hNext
ENDIF
hNext = GetWindow(hNext,2) && next window
ENDDO
RETURN 0 && required window not found
ENDFUNC
---------------


Regards

-- AirCon --
 
AirCon's final modification seems to make it work. Special thanks for AirCon's profound collaboration with Ramani and Mike. The 3 have their code integrated below:

In sum, this VFP program now 'waits' until a Published Appointment Inspector (called &quot;Visit&quot;) is closed by the user... the Outlook Inspector then serves as 'front end' data entry then smooth transition to VFP manipulation.

The VFP routine filters its LastModificationTime (the datetime() of the last SAVE) to hopefully import that specific Outlook Item ... as per the pre-code below:
--------------------------------------------------------
oOutlook = CreateObject(&quot;Outlook.Application&quot;)
oNameSpace= oOutlook.GetNameSpace(&quot;MAPI&quot;)
oCalendarFolder=oNameSpace.GetDefaultFolder(9)
oItems=oCalendarFolder.Items
oItem = oOutlook.CreateItemFromTemplate(SYS(5)+SYS(2003)+&quot;\Forms\Visit.oft&quot;) &&a special appointment template
myForm = oItem.FormDescription
myform.name=&quot;Visit&quot;
myForm.PublishForm(3,oCalendarFolder) &&to be sure
oItem=oCalendarFolder.Items.Add(&quot;IPM.Appointment.visit&quot;) &&FORCE Special VISIT FORM
oInspector = oItem.GetInspector
oInspector.Activate()
*Mike's and AirCon's collaboration:
DECLARE INTEGER GetActiveWindow IN Win32API
DECLARE INTEGER GetWindow IN Win32API INTEGER hWnd, INTEGER nType
DECLARE INTEGER GetWindowText IN Win32API INTEGER hWnd, STRING @cText, INTEGER nType
DECLARE INTEGER BringWindowToTop IN Win32API INTEGER hWnd
DECLARE INTEGER Sleep IN WIN32API INTEGER nTimeout
DECLARE Long FindWindow in User32 String, String

lcTitle = &quot;- Visit&quot;
lnHand = IsRunning(@lcTitle) && Is Outlook Inspector running
IF lnHand <> 0
BringWindowToTop(lnHand)
Do while (FindWindow(Null, lcTitle) != 0)
BringWindowToTop(lnHand) &&Force it on top continuously
Sleep(100) && give an idle (as per Ramani)
WAIT WINDOW NOWAIT &quot;Record Data (in Outlook) and Close..&quot;
enddo
endif
*********************************************************

*** Try to make LASTMODIFICATIONTIME same as DATETIME() (within 2 seconds max) to filter it for progs\outlookImport...
this.Parent.Olecontrol1.left=this.Parent.Olecontrol1.left+250
this.Parent.Olecontrol1.width=this.Parent.Olecontrol1.width-250
SET SECONDS OFF
lstartdate=DATETIME() &&DATE()+1
lstart=TTOC(lstartdate) &&TTOC(DTOT(lstartdate))
lRestrict=[oCalendarItems=oCalendarFolder.items.Restrict(&quot;];
+&quot;[LastModificationTime]>='&quot;+lstart+['&quot;)] &&+&quot; AND [LastModificationTime]<'&quot;+lstart+2+&quot;'&quot;+' &quot;)'
WAIT WINDOW lRestrict
&lRestrict
FOR EACH oCalendarItem IN oCalendarItems
?'Start: '
??oCalendarItem.Start
?'LastModified: '
??oCalendarItem.LastModificationTime
ENDFOR


Philip M. Traynor, DPM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top