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/Disabling Menu Items

Enabling/Disabling Menu Items

Scheduled Pinned Locked Moved C / C++ / MFC
questionwindows-adminhelptutorialannouncement
6 Posts 3 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.
  • F Offline
    F Offline
    Frank Deo
    wrote on last edited by
    #1

    Hello all, I know I've done this before, but my code notes don't reflect it, and I can't for the life of me remember how to do it. It's probably easy, but the easy solutions always illude me. :) My app needs to either process data, or not process data at startup depending on a registry setting. The user is also able to stop or start the process via a menu item. If the process is started at startup, then the stop menu item needs to be enabled and the start menu item needs to be disabled. If the process is stopped at startup, then the opposite must occur in the menu's. The registry setting is read at startup. Here's my questions: 1. Where does the registry read function go? OnCreateClient, or PreCreateWindow? 2. In the Update functions for each menu ie start process and stop process, how do I enable one and disable the other, and vice versa. Thanks! Frank "Keyboard Error - Press F1 to Continue"

    C T 2 Replies Last reply
    0
    • F Frank Deo

      Hello all, I know I've done this before, but my code notes don't reflect it, and I can't for the life of me remember how to do it. It's probably easy, but the easy solutions always illude me. :) My app needs to either process data, or not process data at startup depending on a registry setting. The user is also able to stop or start the process via a menu item. If the process is started at startup, then the stop menu item needs to be enabled and the start menu item needs to be disabled. If the process is stopped at startup, then the opposite must occur in the menu's. The registry setting is read at startup. Here's my questions: 1. Where does the registry read function go? OnCreateClient, or PreCreateWindow? 2. In the Update functions for each menu ie start process and stop process, how do I enable one and disable the other, and vice versa. Thanks! Frank "Keyboard Error - Press F1 to Continue"

      C Offline
      C Offline
      Chris Maunder
      wrote on last edited by
      #2

      Process startup info on InitInstance. Enable/Disable menu items using the ON_UPDATE_COMMAND_UI macro cheers, Chris Maunder

      F 1 Reply Last reply
      0
      • F Frank Deo

        Hello all, I know I've done this before, but my code notes don't reflect it, and I can't for the life of me remember how to do it. It's probably easy, but the easy solutions always illude me. :) My app needs to either process data, or not process data at startup depending on a registry setting. The user is also able to stop or start the process via a menu item. If the process is started at startup, then the stop menu item needs to be enabled and the start menu item needs to be disabled. If the process is stopped at startup, then the opposite must occur in the menu's. The registry setting is read at startup. Here's my questions: 1. Where does the registry read function go? OnCreateClient, or PreCreateWindow? 2. In the Update functions for each menu ie start process and stop process, how do I enable one and disable the other, and vice versa. Thanks! Frank "Keyboard Error - Press F1 to Continue"

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

        Frank Deo wrote: 1. Where does the registry read function go? OnCreateClient, or PreCreateWindow? It depends on what kind of data you are reading (i.e. will it affect the window that you are about to display?) The place where I usually initialize data is on the function that handles WM_CREATE, but you have other options such as InitInstance, OnInitialUpdate, (if dialog base OnInitDialog), etc. Frank Deo wrote: 2. In the Update functions for each menu ie start process and stop process, how do I enable one and disable the other, and vice versa. To enable or disable menu items you can have a look at ON_UPDATE_COMMAND_UI or ON_UPDATE_COMMAND_UI_RANGE. Also the CCmdUI class. You can also have a look at EnableMenuItem(). pCmdUI->Enable( TRUE ); // FALSE to disable // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

        F 1 Reply Last reply
        0
        • C Chris Maunder

          Process startup info on InitInstance. Enable/Disable menu items using the ON_UPDATE_COMMAND_UI macro cheers, Chris Maunder

          F Offline
          F Offline
          Frank Deo
          wrote on last edited by
          #4

          Thanks Chris, I got it. :) Frank "Keyboard Error - Press F1 to Continue"

          1 Reply Last reply
          0
          • T Toni78

            Frank Deo wrote: 1. Where does the registry read function go? OnCreateClient, or PreCreateWindow? It depends on what kind of data you are reading (i.e. will it affect the window that you are about to display?) The place where I usually initialize data is on the function that handles WM_CREATE, but you have other options such as InitInstance, OnInitialUpdate, (if dialog base OnInitDialog), etc. Frank Deo wrote: 2. In the Update functions for each menu ie start process and stop process, how do I enable one and disable the other, and vice versa. To enable or disable menu items you can have a look at ON_UPDATE_COMMAND_UI or ON_UPDATE_COMMAND_UI_RANGE. Also the CCmdUI class. You can also have a look at EnableMenuItem(). pCmdUI->Enable( TRUE ); // FALSE to disable // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

            F Offline
            F Offline
            Frank Deo
            wrote on last edited by
            #5

            Thanks Toni, between EnableMenuItem and pCmdUI->Enable() I figured it out. :) Frank "Keyboard Error - Press F1 to Continue"

            T 1 Reply Last reply
            0
            • F Frank Deo

              Thanks Toni, between EnableMenuItem and pCmdUI->Enable() I figured it out. :) Frank "Keyboard Error - Press F1 to Continue"

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

              You are welcome. :) // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

              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