Solved

How to refresh menu item state?

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now