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
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
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
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
In my menu I use : Menu Set State HWND_FRMMENU, ByCmd IDC_FRMMENU_MNUCHANGEPASSWORD , %MF_DISABLED
The menuitem however doesn't get disabled???
:cry:
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
Thanks,
This works fine.
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
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
:D Great - it work's pretty good! Thanks a lot.
I didn't know the "chaining" of toolbar and rebar!
Rainer