PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Anonymous on September 12, 2005, 09:45:17 AM

Title: diable / enable menu items
Post by: Anonymous on September 12, 2005, 09:45:17 AM
hello friends of firefly

can someone tell a possibility to me, to enable or disable menu items during the runtime of the programm. Using the Control disable/enable  function i have no success.

thank you for help
Helwig Fülling
Title: diable / enable menu items
Post by: Anonymous on September 12, 2005, 01:56:27 PM
with PB7.x or PB8.0, you can use:

Menu Set State hMenu, ByCmd %IDM_DATEN_EINLESEN , %MF_ENABLED

Menu Set State hMenu, ByCmd %IDM_DATEN_EINLESEN , %MF_DISABLED
Menu Set State hMenu, ByCmd %IDM_DATEN_EINLESEN , %MF_GRAYED

Rudolf Fürstauer
Title: diable / enable menu items
Post by: Anonymous on September 13, 2005, 02:35:04 PM
Thank you Rudolf

it works very well   :D

do you have a solution to disable/enable single buttons inside a toolbar ?  where can i find the handle and the control ID of a single button ?

with best regards
Helwig Fülling
Title: diable / enable menu items
Post by: Anonymous on September 13, 2005, 04:57:42 PM
Everything is possible (nearly)
Static lTbState As Long
Global hToolBar as dword
'----------------------

   'first you need the handle of the Toolbar
Control Handle CbHndl, %ID_TOOLBAR To hToolBar

   'get actual state
lTbState = SendMessage(hToolBar, %TB_GETSTATE, %ID_Next, 0)

   'set disable
SendMessage hToolBar, %TB_SETSTATE, %ID_Next, %TBSTATE_DISABLED

   'set button enable
SendMessage hToolBar, %TB_SETSTATE, %ID_Next, lTbState Or %TBSTATE_ENABLED


You can use this constant from CommCtrl.inc:
%TBSTATE_CHECKED        = &H0001    'The BUTTON has the TBSTYLE_CHECK style AND is being clicked.
%TBSTATE_PRESSED        = &H0002    'The BUTTON's text is cut off and an ellipsis is displayed.
%TBSTATE_ENABLED        = &H0004    'The BUTTON accepts USER INPUT. A BUTTON that doesn't have this state is grayed.
%TBSTATE_HIDDEN         = &H0008    'The BUTTON is NOT visible AND cannot RECEIVE USER INPUT.
%TBSTATE_INDETERMINATE  = &H0010    'The BUTTON is grayed.
%TBSTATE_WRAP           = &H0020    'The BUTTON is marked. The interpretation OF a marked item is dependent upon the application.
%TBSTATE_ELLIPSES       = &H0040    'The BUTTON is being clicked.
%TBSTATE_MARKED         = &H0080    'The BUTTON is followed by a LINE BREAK

and you must add in CommCtrl.inc or in your application:
%TBSTATE_DISABLED       = &H0000
because it's not declared.

Rudolf Fürstauer
Title: Enable/Disable menu items
Post by: Anonymous on January 23, 2006, 06:53:56 PM
In my menu I use : Menu Set State HWND_FRMMENU, ByCmd IDC_FRMMENU_MNUCHANGEPASSWORD , %MF_DISABLED

The menuitem however doesn't get disabled???

:cry:
Title: diable / enable menu items
Post by: TechSupport on January 23, 2006, 09:42:24 PM
Is HWND_FRMMENU the handle for the top menu? Looks like it is the handle of the Form itself. Maybe it is something like HWND_FRMMENU_TOPMENU

Also, if you want to gray the option then also use the %MF_GRAYED option.

Here is another way to do it using Win API:


EnableMenuItem HWND_FRMMENU_TOPMENU, IDC_FRMMENU_MNUCHANGEPASSWORD, %MF_BYCOMMAND Or %MF_DISABLED Or %MF_GRAYED
Title: diable / enable menu items
Post by: Anonymous on February 01, 2006, 03:26:05 PM
Thanks,

This works fine.
Title: and what is about rebars?
Post by: Rainer Wiedemann on January 30, 2007, 12:54:20 PM
Hi,
I tried the code of Rudolf Fürstauer and it works fine, when I use only toolbar. But when I make a rebar, I'm not able to disable a button of the rebar. I use the handle of the rebar and the buttonidentifyer of the toolbar (I can't find any for the buttons of the rebar), but it doesn't work.
What must I do?
Thanks.
Rainer
Title: diable / enable menu items
Post by: TechSupport on January 30, 2007, 06:13:32 PM
Try the following type of code:

Local hRebar   As Dword
Local hToolBar As Dword

hRebar   = GetDlgItem( hWndForm, IDC_FORM1_REBAR )
hToolBar = GetDlgItem( hRebar, IDC_FORM1_TOOLBAR1 )

' Disable the "Save" toolbar button
' %TBSTATE_DISABLED = &H0000
SendMessage hToolBar, %TB_SETSTATE, IDC_FORM1_TOOLBAR1_SAVE, &H0000
Title: Success!!
Post by: Rainer Wiedemann on January 31, 2007, 11:16:28 AM
:D Great - it work's pretty good! Thanks a lot.
I didn't know the "chaining" of toolbar and rebar!
Rainer