Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Yousfi Benameur
  Where is Yousfi Benameur?
 El Bayadh
 Algeria
 Yousfi Benameur
 To: farooq ebrahim
  Where is farooq ebrahim?
 karachi
 Pakistan
 farooq ebrahim
 Tags
Subject: RE: toolbar
Thread ID: 268473 Message ID: 268579 # Views: 69 # Ratings: 1
Version: Visual FoxPro 9 SP2 Category: Forms
Date: Tuesday, July 13, 2010 12:28:04 PM         
   


> Dear All
>
> How to create and use toolbar on form
>
> Thanks
>
> Farooq Ebrahim

To complete all the informations,this is a small tutorial how to use a toolbar on an SDI form.
Run the code below (select all,copy paste on command window,select all and rightclick/execute selection (or copy it to a prg file).
*!*-- Begin Code
*!*--Author Yousfi Benameur El Bayadh Algeria
*!*--Time stamp mardi 13 juillet 2010; 11:04:11
*!*--Subject :Playing with a Toolbar on an SDI  Form
*!*--Version VFP9SP2

yform=createObject("asup")
yform.show
read events
return
*
DEFINE CLASS asup AS form
	DataSession = 2
	Height = 371
	Width = 599
	ShowWindow = 2
	DoCreate = .T.
	ShowTips = .T.
	AutoCenter = .T.
	Caption = "Playing with a Toolbar on an SDI  Form"
	MaxButton = .F.
	AlwaysOnTop = .T.
	Name = "FORM1"
	otoolbar = .F.
	DIMENSION owindows[1]

	ADD OBJECT timer1 AS timer WITH ;
		Top = 24, ;
		Left = 348, ;
		Height = 23, ;
		Width = 23, ;
		Enabled = .F., ;
		Interval = 100, ;
		Name = "Timer1"

	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 300, ;
		Left = 264, ;
		Height = 27, ;
		Width = 132, ;
		Caption = "Call  default Toolbar", ;
		Name = "Command1"

	ADD OBJECT label1 AS label WITH ;
		AutoSize = .T., ;
		FontSize = 12, ;
		WordWrap = .T., ;
		Caption = "Drag the toolbar to top,left,right,bottom or out  of the form and re call it.This works only for a top level form.(showWindow=2)-or use the combo below.", ;
		Height = 56, ;
		Left = 120, ;
		Top = 215, ;
		Width = 300, ;
		ForeColor = RGB(0,0,255), ;
		Name = "Label1"

	ADD OBJECT combo1 AS combobox WITH ;
		Height = 25, ;
		Left = 96, ;
		Top = 300, ;
		Width = 85, ;
		Name = "Combo1"

	PROCEDURE ydock
		lparameters ndock

		IF TYPE("thisform.oToolbar")="O" AND !ISNULL(thisform.oToolbar)
		thisform.otoolbar.release
		thisform.otoolbar=null 

		set proc to (afile)     addi 
		  	Thisform.oToolbar =CreateOBJECT('myToolbar',thisform)
		  	thisform.otoolbar.dock(ndock)
			Thisform.oToolbar.Show
		release proc (afile)

		else
		
		thisform.otoolbar.dock(ndock)
		ENDIF
	ENDPROC

	PROCEDURE Init
			IF TYPE("thisform.oToolbar")="O" AND !ISNULL(thisform.oToolbar)
			RETURN .f.
		    ENDIF
		  	this.timer1.enabled=.t.
	ENDPROC

	PROCEDURE Load
	DECLARE integer Beep IN WIN32API integer Freq, integer DurationMs
		oshell=createObject("shell.application")
		oshell.toggleDesktop

		publi afile
		afile=addbs(getenv('temp'))+sys(2015)+"mytoolbar.prg"

		set safe off
		set textmerge on to (afile) noshow
		text
		
		DEFINE CLASS myToolbar AS toolbar
			Caption = "Toolbar1"
			Height = 32
			Left = 46
			Top = 10
			Width = 103
			ShowWindow = 1
			Name = "myToolbar"
			oformref = .F.

			ADD OBJECT cmd1 AS commandbutton WITH ;
				Top = 6, ;
				Left = 6, ;
				Height = 23, ;
				Width = 24, ;
				Caption = "R", ;
				Default = .F., ;
				ForeColor = RGB(0,255,0), ;
				mousepointer=15,;
				Name = "cmd1"

			ADD OBJECT cmd2 AS commandbutton WITH ;
				Top = 6, ;
				Left = 29, ;
				Height = 23, ;
				Width = 24, ;
				Caption = "G", ;
				Default = .F., ;
				ForeColor = RGB(0,0,255), ;
				mousepointer=15,;
				Name = "cmd2"

			ADD OBJECT cmd3 AS commandbutton WITH ;
				Top = 6, ;
				Left = 52, ;
				Height = 23, ;
				Width = 24, ;
				Caption = "B", ;
				Default = .F., ;
				ForeColor = RGB(255,255,0), ;
				mousepointer=15,;
				Name = "cmd3"

			ADD OBJECT img4 AS image WITH ;
				Top = 6, ;
				Left = 75, ;
				Height = 23, ;
				Width = 24, ;
				picture=home()+"\GRAPHICS\ICONS\WIN95\OPENFOLD.ICO", ;
				stretch=2,;
				mousepointer=15,;
				Name = "img4"

			PROCEDURE Init
				#DEFINE ERR_NOFORMPARM_LOC	"You must pass a form reference to create this toolbar."
				PARAMETER oForm
				IF TYPE("m.oForm")#"O" OR ISNULL(m.oForm) OR UPPER(oForm.BaseClass) # "FORM" 
					MESSAGEBOX(ERR_NOFORMPARM_LOC)
					RETURN .F.
				ENDIF

				THIS.oFormRef = oForm
			ENDPROC

			PROCEDURE cmd1.Click
				THISFORM.oFormRef.backcolor =255
for f=200 to 3000 step 50
Beep(f,50)
endfor

for f=3000 to 200 step -50
Beep(f,50)
endfor
			ENDPROC

			PROCEDURE cmd2.Click
				THISFORM.oFormRef.backcolor = RGB(0,255,0)
			ENDPROC

			PROCEDURE cmd3.Click
				THISFORM.oFormRef.backcolor = RGB(0,0,255)
					ENDPROC

			PROCEDURE img4.Click
		THISFORM.oFormRef.backcolor = RGB(255,255,255)
			ENDPROC

		ENDDEFINE
		*
		endtext
		set textmerge to
		set safe on
	ENDPROC


	PROCEDURE timer1.Timer
		IF TYPE("thisform.oToolbar")="O" AND !ISNULL(thisform.oToolbar)
		thisform.otoolbar.release
		thisform.otoolbar=null
		 ENDIF

		set proc to (afile)      addi
		  	Thisform.oToolbar =CreateOBJECT('myToolbar',thisform)
		  	thisform.otoolbar.dock(0)
			Thisform.oToolbar.Show
		     release proc (afile)
			this.enabled=.f.

	ENDPROC

	PROCEDURE command1.Click
		IF TYPE("thisform.oToolbar")="O" AND !ISNULL(thisform.oToolbar)
		thisform.oToolbar.dock(0)
		else
		  	thisform.timer1.enabled=.t.
		    ENDIF
	  
		 
	ENDPROC


	PROCEDURE combo1.Click
		do case

		case this.value=1
		thisform.ydock(0)

		case this.value=2
		thisform.ydock(2)
		case this.value=3

		thisform.ydock(1)
		case this.value=4

		thisform.ydock(3)

		case this.value=5
		thisform.ydock(-1)

		endcase
	ENDPROC


	PROCEDURE combo1.AddItem
		LPARAMETERS cItem
	ENDPROC


	PROCEDURE combo1.Init
		this. additem("1.dock at form top")
		this. additem("2.dock at form right")
		this. additem("3.dock at form left")
		this. additem("4.dock at form bottom")
		this. additem("5.free toolbar")

		this.listindex=1
		this.value=1
		this.style=2
	ENDPROC
	
    PROCEDURE DESTROY
    CLEA EVENTS
    ENDPROC

ENDDEFINE
*
*!*-- End Code

this is a photo.



Regards
Yousfi Benameur

ENTIRE THREAD

toolbar Posted by farooq ebrahim @ 7/12/2010 3:25:12 PM
RE: toolbar Posted by piyuhsh vaishnavswami @ 7/12/2010 3:35:10 PM
RE: toolbar Posted by Martin Krivka @ 7/12/2010 3:36:35 PM
RE: toolbar Posted by Yousfi Benameur @ 7/13/2010 12:28:04 PM
RE: toolbar Posted by ho me @ 7/14/2010 6:10:12 PM
RE: toolbar Posted by Danson Danson @ 7/15/2010 2:28:57 PM