Button with menu

This forum is for eXpress++ general support.
Post Reply
Message
Author
skiman
Posts: 1183
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Button with menu

#1 Post by skiman »

Hi,

I'm adding a menu to our printbutton. In this menu there are extra options to export the data. Since there are a lot of buttons in our application I would like to do the following.

Create a function which return an 'omenu'. See the code below.

Code: Select all

Function buttonprintmenu(oBrowse,_cTitel)
**************************************
Local  getlist := {} , oDlg , getoptions := {}
Local oPrintMenu

	DCSUBMENU oPrintMenu PROMPT 'Menu'
		DCMENUITEM 'Export to Screenreport' PARENT oPrintMenu ;
			ACTION {||ABO_printbrowse(oBrowse,.T.,.F.,_cTitel,'')} 

		DCMENUITEM 'Export to XLS' PARENT oPrintMenu ;
			ACTION {||ABO_printbrowse(oBrowse,.T.,.T.,_cTitel,'X')}  
			
		DCMENUITEM 'Export to PDF' PARENT oPrintMenu ;
			ACTION {||ABO_printbrowse(oBrowse,.T.,.T.,_cTitel,'P')}
			
	dcgetoptions NOTITLEBAR BORDER XBPDLG_DLGBORDER NOESCAPEKEY ;
             NOEDITNAVKEYS {|| .T. } FITPAD 1
		 
	dcread gui exit PARENT @oDlg FIT options getoptions
return oPrintMenu

With this function it is rather easy to modify the print buttons by adding the following code to the button as below:

Code: Select all

...
MENUACTION {|a,b,o,oPrintMenu|oPrintMenu:=buttonprintmenu(@oBrowse,''),oPrintMenu:PopUp( o:setParent(), o:currentPos(), 2 , ;
       XBPMENU_PU_DEFAULT + XBPMENU_PU_MOUSE_RBDOWN  ) } ;
This is working fine.

My question about this is how about the dialog oDlg that is created in the buttonprintmenu function. When will this oDlg get destroyed, or how do I destroy this? Will this give a problem if a user has executed this a lot of times during the day.
Best regards,

Chris.
www.aboservice.be

skiman
Posts: 1183
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Button with menu

#2 Post by skiman »

Hi,

The dialog is created each time, and stays open in the background. So the above solution isn't working correctly.

How can i prevent that the dialog is created/shown on the screen?
Best regards,

Chris.
www.aboservice.be

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Button with menu

#3 Post by rdonnay »

How can i prevent that the dialog is created/shown on the screen?
Chris -

If the PARENT clause of DCREAD GUI points to an "already created" object, then there will be no Dialog window created. When creating menus on the fly as you are doing, just simply use the oBrowse object as the parent.

Change this:

dcread gui exit PARENT @oDlg FIT options getoptions

To this:

dcread gui exit PARENT oBrowse FIT options getoptions

A 2nd option is to add the DCSUBMENU and DCMENUITEM commands to the Getlist that contains the button.
Take a look at the way menus are created in SqlQuery.Prg (attached).
Attachments
sqlquery.zip
(98.33 KiB) Downloaded 574 times
The eXpress train is coming - and it has more cars.

skiman
Posts: 1183
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Button with menu

#4 Post by skiman »

Hi Roger,

Thanks, changing it to the following works. With the FIT argument, it gives an error.

Code: Select all

dcread gui exit PARENT oBrowse 
Best regards,

Chris.
www.aboservice.be

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Button with menu

#5 Post by rdonnay »

With the FIT argument, it gives an error.
You are right. It would do that. FIT is designed to fit the dialog window to the objects, but if there is no dialog window it would error. I could fix that in the code but a simpler workaround is not to use the FIT clause.
The eXpress train is coming - and it has more cars.

skiman
Posts: 1183
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Button with menu

#6 Post by skiman »

Hi,
I could fix that in the code but a simpler workaround is not to use the FIT clause.
It's not a workaround, it is just the perfect solution. :-) This way adding a menu to a lot of buttons is really an easy task.
Best regards,

Chris.
www.aboservice.be

Post Reply