Page 1 of 1

Set Focus On a application

Posted: Thu Jun 05, 2008 4:17 pm
by Jack
I a program, i call Word or Excel with OLE.
How can i put the focus on the word or excel application , how
to put it on the top ?

Thanks

Posted: Wed Jun 11, 2008 9:05 am
by driessen
Jack,

I'd like to know that too.

(Just to bring this topic to the top)

Regards.

Posted: Wed Jun 11, 2008 2:24 pm
by Antonio Linares
Jack, Michel,

Basically you find the window using FindWindow() and then you can use SetFocus(), BringWindowToTop() or SetForegroundWindow() to give it the focus.

Posted: Wed Jun 11, 2008 3:58 pm
by driessen
Antonio,

Thanks for your answer.

My problem tough is :

Suppose I have opened a Word-session manually and suppose I open a second Word-session through OLE in my FWH-application, how can I bring to top the right Word-session, i.e. the one which is opened by OLE ?

Until now I always have used this code :

Code: Select all

BringWindowToTop(FindWindow("OpusApp",NIL))
The problem is that sometimes my manually opened Word-session is brought to top.

How can I solve this problem ?

My second question : how does this work with Excel or Outlook ?

Thanks.

Regards.

Posted: Thu Jun 12, 2008 6:58 am
by Antonio Linares
Michel,

Here you have a sample to manage Outlook from FWH. It steps through all events in the calendar. It will not create a Window:

Code: Select all

#define outlookFolderCalendar 9

function Main()

  local oOutlook   := CreateObject( "Outlook.Application" ) 
  local oNameSpace := oOutlook:GetNameSpace( "MAPI" ) 
  local oCalendar  := oNameSpace:GetDefaultFolder( outlookFolderCalendar ) 
  local nItems     := oCalendar:Items:Count, n

  for n = 1 to nItems
     MsgInfo( oCalendar:Items[ n ]:Start )
     MsgInfo( oCalendar:Items[ n ]:End )
     MsgInfo( oCalendar:Items[ n ]:Subject )
     MsgInfo( oCalendar:Items[ n ]:Body )
  next   

  oCalendar := nil
  oNameSpace := nil
  oOutlook := nil

return nil   

Posted: Thu Jun 12, 2008 7:07 am
by Antonio Linares
Michel,

This code creates a new appointment in the calendar:

Code: Select all

#define outlookFolderCalendar 9

function Main()

  local oOutlook   := CreateObject( "Outlook.Application" ) 
  local oNameSpace := oOutlook:GetNameSpace( "MAPI" ) 
  local oCalendar  := oNameSpace:GetDefaultFolder( outlookFolderCalendar ) 
  local oItem      := oOutLook:CreateItem( 1 )

  oItem:Start = Date()
  oItem:End = Date()
  oItem:Subject = "A test"
  oItem:Save()   
  MsgInfo( "check Outlook calendar for today" )

  oCalendar = nil
  oNameSpace = nil
  oOutlook = nil
  oItem = nil

return nil   

Posted: Thu Jun 12, 2008 12:28 pm
by driessen
Antonio,

Since I am visiting costumers for almost the whole day today, I'll come back to it tonight or tomorrow.

Thanks a lot.

Regards,

Posted: Thu Jun 12, 2008 8:10 pm
by Jack
Thanks for this answer .
Could you give a sample .
The name of the word document opened with ole is "facture.doc" ,
it is locate in "c:\data" folder .
I want to put the word document on top and set the focus on word .

Thanks .