Solved

How to refresh menu item state?

Posted on 2000-05-18
4
375 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
  • 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

809 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