Set Focus On a application

Post Reply
Jack
Posts: 249
Joined: Wed Jul 11, 2007 11:06 am

Set Focus On a application

Post 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
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Post by driessen »

Jack,

I'd like to know that too.

(Just to bring this topic to the top)

Regards.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Post 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.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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   
Last edited by Antonio Linares on Thu Jun 12, 2008 7:09 am, edited 1 time in total.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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   
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Post 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,
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
Jack
Posts: 249
Joined: Wed Jul 11, 2007 11:06 am

Post 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 .
Post Reply