Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Event Binding
Message
 
 
À
14/02/2002 10:10:58
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Titre:
Divers
Thread ID:
00620031
Message ID:
00620066
Vues:
15
This message has been marked as the solution to the initial question of the thread.
>It appears that the command bars in Word are actually members of the Office Object Library. Here's my situation, I'm opening Word via automation, opening a document and creating a command bar on the fly. I intend on running certain programs based on which command bar button is clicked. My thinking is that I need to bind my vfpclass object that I create to the office.commandbars object. The problem is that you can't createobject("office.commandbars"). Am I even on the right track? Is there some other way to run Fox programs from the click of a Word command bar?

Here is an example of a class I use for MS Project. The concept is the same:
define class SesAddin as Session olepublic
oCommandbutton = .NULL.
oApplication = .NULL.

IMPLEMENTS _CommandBarButtonEvents IN {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}#2.1

procedure SetupAddin
With THIS 
	local loMSProj as MSProject.Application
	loMSProj = getobject(,'msproject.application')
	
	if type('.oApplication') <> 'O' then
		.oApplication = loMSProj
	endif
	
	if vartype(loMSProj) = 'O' then
		if type([loMSProj.CommandBars.Item("Standard").Controls.Item('Load Project')]) = 'O' then
			.oCommandbutton = loMSProj.CommandBars.Item("Standard").Controls.Item('Load Project')
		else
			.oCommandbutton = loMSProj.CommandBars.Item("Standard").Controls.Add(1)
			With .oCommandbutton
				.Caption = 'Load Project'
				.Style = msoButtonCaption
				.Tag = 'Some Info'
				.OnAction = "MyTest"
				.Visible = .T.
			Endwith
		endif
		=eventhandler(.oCommandbutton,THIS)
	endif
Endwith
endproc

procedure ResetAddin
With THIS
	.oApplication.CommandBars.Item("Standard").Controls.Item("Load Project").Delete()
	.oCommandbutton = .NULL.
	.oApplication = .NULL.
Endwith 
endproc

procedure Error
LPARAMETERS nError, cMethod, nLine
local lcerrorstr
set textmerge on
text to lcerrorstr noshow
Error: <<transform(nError)>>
Method: <<cMethod>>
Message: <<message())>>
Line No: <<transform(nLine)>>
Variable: <<transform(sys(2018))>>
Time: <<transform(datetime())>>
endtext

lcerrorstr = lcerrorstr + replicate(chr(13)+chr(10),2)

if file('c:\temp\AddinError.log') then
	strtofile(lcerrorstr,'c:\temp\AddinError.log',1)
else
	strtofile(lcerrorstr,'c:\temp\AddinError.log',0)
endif
endproc

procedure Release
release THIS
endproc

procedure _CommandBarButtonEvents_Click(Ctrl AS Office.CommandBarButton, CancelDefault AS LOGICAL @) AS VOID
declare integer MessageBox in user32 as WinMessage integer, string, string, integer
WinMessage(0,Ctrl.Caption,'Message',MB_OK)
endproc
enddefine
You can create multiple instances of this class with different code in the Setup method or you could create one instance that had many different Setup methods for each button. All the buttons would be bound to the the same object (THIS) and you could differentiate between what button was clicked by querying the Caption or Tag or any other property of the control. Ctrl is an object reference to the one that was clicked.

HTH.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform