Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a toolbar class on a form class

Status
Not open for further replies.

Jomercat

Programmer
Joined
Sep 1, 2004
Messages
100
Location
US
Hi all,

I am starting to work with classes in Fox Pro 9.0 and I cannot figure out how to add a tool bar class onto a form class.

This is the code I am using but it does not work.

LOCAL goMainForm, goToolbar

goMainForm = NEWOBJECT('frmmain', 'CLS_main.vcx')

goMainForm.visible=.T.

goToolbar = NEWOBJECT('tlbmain','CLS_main.vcx', '',goMainForm)

goToolbar.Dock(0)
goToolbar.visible=.T.

Any ideas of what I am doing wrong?

Thanks in advance.

Jose.
 
Jose,

You can't add a toolbar to a form. Toolbars exist independently of other forms. Just do a CREATEOBJECT() or NEWOBJECT() on your toolbar class, set its Visible to .T., and you're there.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Thanks MikeLewis for your reply!!!

What I meant to say is that I already created the toolbar as a class and I want to include it with the form, which is also a class, when it is activated.

By looking at the FP 9.0 help the XXXXX.Dock method positions a ToolBar or Form object along a border of the main Visual FoxPro window or positions a Form object within Visual FoxPro IDE windows or with other forms. So I want to position the toolbar on my main form class.

Thanks.

Jose.
 
Hi, not real sure, but can't you create the toolbar based upon a custom-property of your form?
Than create it in the init method of yr form?
-Bart
 
Jomercat said:
So I want to position the toolbar on my main form class.
That will only work if the form is top-level.


As Nifrabar suggests, you can add a new property to the top-level form, .oToolbar, value = .NULL., and place the following code in the .Activate(), not the .Init(), event of the form.
Code:
[COLOR=blue]WITH THISFORM
[tab]IF ISNULL(.oToolbar)
[tab][tab].oToolbar = CREATEOBJECT([tbrMain])
[tab][tab].oToolbar.Dock(0,0,0)
[tab][tab].oToolbar.Show()
[tab]ENDI
ENDW[/color]

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.net
PDFcommandertm.co.uk
 
Jose,

Are you are saying that you want to place the toolbar inside the form -- to dock at the top edge of the form, perhaps? If so, that's not really possible. But you can achieve the same effect by placing the buttons and other controls from the toolbar directly on the form surface. In other words, don't bother with the toolbar. Just place the buttons in the form.

If you are saying that you want the toolbar to be outside the form, but you want it to appear and disappear as the form is activated or de-activated, the code that Chris gave you is along the right lines. You don't really need to create a form property to hold a reference to the toolbar. Just toggle the visibility of the toolbar in the form's Activate and Deactivate.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Mike said:
If so, that's not really possible.
Have to disagree with you, Mike, it is possible providing the form is top-level.


If you try the code posted you will see how it works.

If you also need a menu to be contained within a top-level with the toolbar docked below it the conventional manner, you can use the following code in the .Init() event of the form, making sure the menu has 'Top-Level Form' checked in the General Options dialog.
Code:
[COLOR=blue]LOCAL lcGetMenuName

lcGetMenuName = []
DO mymenu.mpr WITH THIS, lcGetMenuName[/color]

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.net
PDFcommandertm.co.uk
 
MikeLewis said:
so, that's not really possible.

I agree with Chris, this has been brought up about a year ago.
Here is a sample
Code:
oform = CREATEOBJECT('frmtl')
oform.show(1)
READ EVENTS
 
DEFINE CLASS xtoolbar AS toolbar
     Caption = "Toolbar"
     Height = 28
     Left = 0
     Top = 0
     Width = 55
     ShowWindow = 1
     Name = "mytoolbar"
     ADD OBJECT command2 AS commandbutton WITH ;
          Top = 3, ;
          Left = 5, ;
          Height = 22, ;
          Width = 23, ;
          Caption = "", ;
          Name = "Command2"
     ADD OBJECT command1 AS commandbutton WITH ;
          Top = 3, ;
          Left = 27, ;
          Height = 22, ;
          Width = 23, ;
          Caption = "", ;
          Name = "Command1"
ENDDEFINE
DEFINE CLASS frmTL AS Form
     ShowWindow = 2               
     PROCEDURE Activate
          IF TYPE("THIS.oToolbar.Name") <> "C"
               THIS.AddProperty('oToolbar', .NULL.)
               THIS.oToolbar = CREATEOBJECT('xToolBar')
               this.oToolbar.dock(0)
               THIS.oToolbar.Show()
          ENDIF

     ENDPROC
ENDDEFINE



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Au Contraire,

Try this code (this requires VFP7, Though I have a more complicated version that works with VFP6):
Code:
RELEASE oForm
PUBLIC oForm
oform = CREATEOBJECT('frmtl')
oform.show(1)
 
DEFINE CLASS xtoolbar AS toolbar
     Caption = "Toolbar"
     Height = 28
     Left = 0
     Top = 0
     Width = 55
     ShowWindow = 1
     Name = "mytoolbar"
     ADD OBJECT command2 AS commandbutton WITH ;
          Top = 3, ;
          Left = 5, ;
          Height = 22, ;
          Width = 23, ;
          Caption = "", ;
          Name = "Command2"
     ADD OBJECT command1 AS commandbutton WITH ;
          Top = 3, ;
          Left = 27, ;
          Height = 22, ;
          Width = 23, ;
          Caption = "", ;
          Name = "Command1"
ENDDEFINE
DEFINE CLASS frmTL AS Form
     ShowWindow = 2               
     PROCEDURE Activate
          IF TYPE("THIS.oToolbar.Name") <> "C"
               THIS.AddProperty('oToolbar', .NULL.)
               THIS.oToolbar = CREATEOBJECT('xToolBar')
               this.oToolbar.dock(0)
               THIS.oToolbar.Show()
               THIS.TakeWindow( THIS.hwnd, _VFP.hWnd )
          ENDIF

     ENDPROC
     PROCEDURE TakeWindow
    ***************************************************************************
    * Program: TakeWindow.PRG                                                 *
    * Author : William GC Steinford                                           *
    * Simplified to require HWND to be passed
    LPARAMETERS pnWindowTitle, pnParentWindow
    LOCAL lnWHND, lnVFP, lnRes, lnCNT, lnWinCnt
    
    DECLARE INTEGER SetParent in Win32API as apiSetParent ;
      INTEGER hWndChild, INTEGER hWndNewParent
      
    lnRes = apiSetParent( pnWindowTitle, pnParentWindow )
    RETURN lnRes
  ENDPROC
ENDDEFINE

( I know it's a Hack, but it works! )

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top