Solved

How to refresh menu item state?

Posted on 2000-05-18
4
379 Views
Last Modified: 2012-06-27
Hi.
I want to get state of menu item (enabled, checked etc...) with GetMenuState() function. But when this menu item invisible, this function retrieves old value of menu state (when item was last visible). How can I refresh state of menu item without showing it.
Note: menu item message handler don't belong to my application.
0
Comment
Question by:double_axe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2820785
Many applications will reset their menu states just prior to showing their menus.  This is what the WM_INITMENU messages is for.  So changing another application's menu is pointless, the application will change it back.  Changing another application's _____ is also unwise.  _______ belongs to another application, you shouldn't be screwing with it.  
0
 
LVL 3

Author Comment

by:double_axe
ID: 2820828
I don't want to change that menu, just want to know, if it's enabled or not. So, as I understand, I can send WM_INITMENU message to refresh menu.
1. If I send WM_INITMENU to another application's window and then will not show it's submenus, will application run normally or crash?
2. What window I must send WM_INITMENU message to? To toplevel frame?
3. Can I use SendMessage() or I must use PostMessage() or PostThreadMessage()?
0
 
LVL 22

Accepted Solution

by:
nietod earned 30 total points
ID: 2820883
You can send the message to the top-level window.  That is how it is "really" performed.

You could do that, but I still don't recomend it.  The OS is supposed to send that message, not your application.  It is supposed to be sent under a very specific circumstance, this isn't it.  It will be harmless 99 out of 100 times.  but in that 100th time, there will be a problem.  For example it is reasonable for an app to assume that the menu will be displayed after that message--that is the idea.  so an application might allocate some memory or other resource on tha message intending to free it when the menu is closed.  but the menu is never closed (its never opened) so now the app has a memory leak. But its not the apps fault....  There must be 100s of other things that you can make go wrong in this way.

Note that the problems are likely to be app specific.  i.e most apps will be fine with it, but some won't.  But the ones that aren't fine with it, might not show problems right away or ender every circumstance.  That is another thing that makes this dangerous.
0
 
LVL 3

Author Comment

by:double_axe
ID: 2824100
I'll think about another way to do this. But if I don't find it, I'll have to use this one.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question