Set Focus On a application

Set Focus On a application

Postby Jack » Thu Jun 05, 2008 4:17 pm

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
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am

Postby driessen » Wed Jun 11, 2008 9:05 am

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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby Antonio Linares » Wed Jun 11, 2008 2:24 pm

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
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby driessen » Wed Jun 11, 2008 3:58 pm

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  Expand view
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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby Antonio Linares » Thu Jun 12, 2008 6:58 am

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  Expand view
#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: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Thu Jun 12, 2008 7:07 am

Michel,

This code creates a new appointment in the calendar:
Code: Select all  Expand view
#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
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby driessen » Thu Jun 12, 2008 12:28 pm

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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby Jack » Thu Jun 12, 2008 8:10 pm

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 .
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 72 guests