0

I want to enable/disable menu items at some events, what is independent from UPDATE_COMMAND_UI handlers, so, I have not a CCmdUI object, so, I want to send a message, what invokes the handler. I tried this:

    SendMessage(WM_COMMAND, CN_UPDATE_COMMAND_UI, ID_VIEW_SYNTAXHIGHLIGHT);

Is this good? If do not, what is the correct way? Thank you.

  • 1
    *"I want to enable/disable menu items at some events, what is independent from UPDATE_COMMAND_UI handlers"* - That doesn't make sense. The `UPDATE_COMMAND_UI` handlers are execute whenever the UI enters a state where it can accept user input. You can always arrange to update your UI there. – IInspectable Apr 25 '21 at 14:13
  • My English is not perfect. My IDE has a binary editor so. CScrollView uses 32 bit signed integers, so, the size of the view is limited to 2^31-1 pixels, so, the number of lines is limited. My binary editor supports 2/4/8/16/32 bytes/line modes. If I insert some bytes, bytes/number is automatically duplicated if overrun maximum number of lines, this removes the overrun, keeps number of lines handleable. So, if this is changed to 32 bytes/line, I must disable "Doubles byte/line" menu item: from OnChar. So, I need a CCmdUI object. So, I must call UPDATE_COMMAND_UI handler. – Zoltán Hegedüs Apr 25 '21 at 14:36
  • Are you using it on a Main Frame or in a modal popup dialog? Because in the second case you may need to handle the `WM_KICKIDLE` message and then the dialog will listen to the Message Pump, and inside the routine you are handling it, do something like `UpdateDialogControls` for the controls' state to get up-to-date. – sergiol Apr 26 '21 at 13:06
  • This is an IDE, an MDI MFC program, I want to use in CIDEView::OnChar. So, in the view class, in WM_CHAR message handler. – Zoltán Hegedüs Apr 26 '21 at 14:35

1 Answers1

4

No, this in not correct. You need to go to the Class View, then go to the Events tab and add an ON_UPDATE_COMMAND_UI handler.

Inside the implementation, you call pCmdUI->Enable() and/or pCmdUI->SetCheck() or pCmdUI->SetRadio(), depending on the functionality you want the UI items to have. What is so much great with this mechanism is that you don't need to call some sort of say, UpdateUIItems() function after every operation that may affect the enable/check/radio state of the UI items, instead the framework calls the handlers, while your app is entering the idle state. Of course, the code evaluating the above conditions must be as fast as possible. Do not perform lengthy operations in there. Try playing a short sound in such a handler (eg Beep(1000,25)) to see how frequently these are called. Data must be created, read or modified, in the ON_COMMAND handlers. In the ON_UPDATE_COMMAND_UI handler you must just tell the framework the state of the UI items.

Check the UI Update Mechanism. Also, my older posts here and here.

Constantine Georgiou
  • 2,412
  • 1
  • 13
  • 17
  • "You need to go to the Class View, then go to the Events tab and add an ON_UPDATE_COMMAND_UI handler. Inside the implementation, you call pCmdUI->Enable() and/or pCmdUI->SetCheck() or pCmdUI->SetRadio(), depending on the functionality you want the UI items to have." This was ready before I created this question. So, I do not need for SendMessage. – Zoltán Hegedüs Apr 25 '21 at 14:46