Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Enabling Menu Items

Enabling Menu Items

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AnkushChopra
    wrote on last edited by
    #1

    How to enable a menu item dynamically. I have tried EnableMenuItem but with no success.

    L P T 3 Replies Last reply
    0
    • A AnkushChopra

      How to enable a menu item dynamically. I have tried EnableMenuItem but with no success.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Use a flag, when you press a button on a dialog or something, set your flag to TRUE and in WM_INITMENU you check whether your flag is TRUE or FALSE and then use EnableMenuItem() to disable/enable/etc your item. Is everything clear? Rickard Andersson8 Here is my card, contact me later! UIN: 50302279 E-Mail: nikado@pc.nu Interests: C++, ADO, SQL, Winsock, 0s and 1s

      A 1 Reply Last reply
      0
      • A AnkushChopra

        How to enable a menu item dynamically. I have tried EnableMenuItem but with no success.

        P Offline
        P Offline
        Phil Hamer
        wrote on last edited by
        #3

        You could use the ON_UPDATE_COMMAND_UI messages for your menu IDs if you're using MFC.

        A 1 Reply Last reply
        0
        • A AnkushChopra

          How to enable a menu item dynamically. I have tried EnableMenuItem but with no success.

          T Offline
          T Offline
          Toni78
          wrote on last edited by
          #4

          An application must use the MF_BYPOSITION flag to specify the correct menu handle. If the menu handle to the menu bar is specified, the top-level menu item (an item in the menu bar) is affected. To set the state of an item in a drop-down menu or submenu by position, an application must specify the handle to the drop-down menu or submenu. When an application specifies the MF_BYCOMMAND flag, Windows checks all items that open submenus in the menu identified by the specified menu handle. Therefore, unless duplicate menu items are present, specifying the menu handle to the menu bar is sufficient. // Afterall I realized that even my comment lines have bugs

          T 1 Reply Last reply
          0
          • T Toni78

            An application must use the MF_BYPOSITION flag to specify the correct menu handle. If the menu handle to the menu bar is specified, the top-level menu item (an item in the menu bar) is affected. To set the state of an item in a drop-down menu or submenu by position, an application must specify the handle to the drop-down menu or submenu. When an application specifies the MF_BYCOMMAND flag, Windows checks all items that open submenus in the menu identified by the specified menu handle. Therefore, unless duplicate menu items are present, specifying the menu handle to the menu bar is sufficient. // Afterall I realized that even my comment lines have bugs

            T Offline
            T Offline
            Toni78
            wrote on last edited by
            #5

            Sorry but I forgot to mention that I got that from the API reference so you can refer to that for more information. I have used this function before, and I never had a problem with it. // Afterall I realized that even my comment lines have bugs

            T 1 Reply Last reply
            0
            • T Toni78

              Sorry but I forgot to mention that I got that from the API reference so you can refer to that for more information. I have used this function before, and I never had a problem with it. // Afterall I realized that even my comment lines have bugs

              T Offline
              T Offline
              Toni78
              wrote on last edited by
              #6

              I didn't realize that you were asking about MFC. My approach won't work with MFC. Sorry about that. // Afterall I realized that even my comment lines have bugs

              1 Reply Last reply
              0
              • L Lost User

                Use a flag, when you press a button on a dialog or something, set your flag to TRUE and in WM_INITMENU you check whether your flag is TRUE or FALSE and then use EnableMenuItem() to disable/enable/etc your item. Is everything clear? Rickard Andersson8 Here is my card, contact me later! UIN: 50302279 E-Mail: nikado@pc.nu Interests: C++, ADO, SQL, Winsock, 0s and 1s

                A Offline
                A Offline
                AnkushChopra
                wrote on last edited by
                #7

                Thanks for your help. I used EnableMenuItem(0with an if statement and it worked.

                1 Reply Last reply
                0
                • P Phil Hamer

                  You could use the ON_UPDATE_COMMAND_UI messages for your menu IDs if you're using MFC.

                  A Offline
                  A Offline
                  AnkushChopra
                  wrote on last edited by
                  #8

                  Thanks for the help!!

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups