Announcement

Collapse
No announcement yet.

Problem with Menu Set

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lance Edmonds
    replied
    Unfortunately that is a known bug in DDT - the BYCMD clause is not accepted by the compiler. R&D have told me that this will be fixed in the next update to the compiler.

    The workaround is to call the EnableMenuItem() API instead. Semens example shows this but with a lot of additional stuff to manipulate the menu (bold, right-aligned, etc).

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Semen Matusovski
    replied
    Lance --
    Errata ?

    Charles --
    In many cases, even with DDT, you can use API functions.
    EnableMenuItem hMenuFile, 3, %MF_BYCOMMAND Or %MF_GRAYED
    instead of MENU SET STATE hMenuFile, ByCmd 3, %MF_GRAYED
    EnableMenuItem hMenuFile, 3, %MF_BYCOMMAND Or %MF_ENABLED
    instead of MENU SET STATE hMenuFile, ByCmd 3, %MF_ENABLED

    In FAQ you can find Win32 API literature.
    I'm very recommend Rector/NewComer' book.

    Should also notice that there is very useful engine - "search".
    You can find many interesting samples, first of all, on Source code forum.

    PS. I decided to demonstrate this technique on my sample, posted on "Source code".
    Buttons "Enabled"/"Disabled" - for menu item Horizontal (Window - Horizontal/Vertical)
    Code:
      
       #Compile Exe
       #Register None
       #Dim All
       #Include "WIN32API.INC"
    
       Global hMenu As Long
       CallBack Function EnCB
          EnableMenuItem hMenu, 1005, %MF_BYCOMMAND Or %MF_ENABLED
       End Function
    
       CallBack Function DsCb
          EnableMenuItem hMenu, 1005, %MF_BYCOMMAND Or %MF_GRAYED
       End Function
    
       '****************************************************************
       ' NumRs - order no. (positive - Right-justify; negative - Bold)
       Sub MenuCorrect (hMenu As Long, NumRs As Long)
          %MAXLENGTHOFMENUTEXT = 40
          Dim mnuItemInfo As MENUITEMINFO
          Dim BuffStr As Asciiz * (%MAXLENGTHOFMENUTEXT * 2 + 1)
          mnuItemInfo.cbSize = Len(mnuItemInfo)
          mnuItemInfo.dwTypeData = VarPtr(BuffStr)
          mnuItemInfo.cch = %MAXLENGTHOFMENUTEXT * 2
          mnuItemInfo.fMask = %MIIM_ID Or %MIIM_DATA Or %MIIM_TYPE Or %MIIM_SUBMENU Or %MIIM_STATE
          GetMenuItemInfo hMenu, Abs(NumRs) - 1, %True, mnuItemInfo
          If NumRs < 0 Then mnuItemInfo.fState = mnuItemInfo.fState Or &H1000 Else _
             mnuItemInfo.fType = mnuItemInfo.fType Or %MF_HELP
          SetMenuItemInfo hMenu, Abs(NumRs) - 1, %True, mnuItemInfo
       End Sub
       '****************************************************************
       CallBack Function DlgProc()
          If CbMsg = %WM_COMMAND Then
             If CbCtl => 1001 And CbCtl <= 1100 Then
                MsgBox "WM_COMMAND received from a menu item!"
             End If
          End If
       End Function
       
       Function PbMain () As Long
          Local hDlg As Long
          Local result As Long
          Local hPopup As Long
          Menu New Bar To hMenu
          Menu New Popup To hPopup
          Menu Add String, hPopup, "&Open", 1001, %MF_ENABLED
          Menu Add String, hPopup, "&Exit", 1002, %MF_ENABLED
          Menu Add Popup, hMenu, "&File", hPopup, %MF_ENABLED
          Menu New Popup To hPopup
          Menu Add String, hPopup, "C&ut", 1003, %MF_ENABLED
          Menu Add String, hPopup, "&Copy", 1004, %MF_ENABLED
          '***********************************
          MenuCorrect hPopup, -1
          '***********************************
          Menu Add Popup, hMenu, "&Edit", hPopup, %MF_ENABLED
          '***********************************
          MenuCorrect hMenu, -2
          '***********************************
          Menu New Popup To hPopup
          Menu Add String, hPopup, "&Horizontal", 1005, %MF_ENABLED
          Menu Add String, hPopup, "&Vertical", 1006, %MF_ENABLED
          '***********************************
          MenuCorrect hPopup, -2
          '***********************************
          Menu Add Popup, hMenu, "&Window", hPopup, &H0
          Menu New Popup To hPopup
          Menu Add String, hPopup, "&Help", 1005, %MF_ENABLED
          Menu Add String, hPopup, "&About", 1006, %MF_ENABLED
          Menu Add Popup, hMenu, "&Help", hPopup, %MF_ENABLED
          ' ** Create a new dialog template
          Dialog New 0, " What is your name?", ,, 160, 80, %WS_SYSMENU To hDlg
          ' ** Add controls to it
          Control Add TextBox, hDlg, 101, "", 14, 12, 134, 12, 0
          Control Add Button, hDlg, %IDOK, "Enable", 34, 32, 40, 14, %BS_DEFAULT, Call EnCB
          Control Add Button, hDlg, %IDCANCEL, "Disable", 84, 32, 40, 14, 0, Call DsCB
          '***********************************
          MenuCorrect hMenu, 3
          '***********************************
          Menu Attach hMenu, hDlg
          ' ** Display the dialog
          Dialog Show Modal hDlg, Call DlgProc To result
       End Function
    [This message has been edited by Semen Matusovski (edited March 27, 2000).]

    Leave a comment:


  • Charles Davis
    Guest started a topic Problem with Menu Set

    Problem with Menu Set

    I'm trying to change the state of a menu item from grayed to enabled with the following statement:

    MENU SET STATE hMenuFile, BYCMD 403, %MF_ENABLED

    If I put the BYCMD in, I get a syntax error, if I leave it out:

    MENU SET STATE hMenuFile, 3, %MF_ENABLED

    it compiles, but doesn't seem to do anything. I'm trying to enable the third item on the File menu, which has an id of 403. I'm doing this in the callback procedure for another menu item. hMenuFile is the handle of a popup which is attached to the main menu bar.
Working...
X