| View previous topic :: View next topic |
| Author |
Message |
The0neThe0nly Expert Cheater
Reputation: 0
Joined: 08 Dec 2009 Posts: 119 Location: In a box
|
Posted: Wed Apr 25, 2012 8:26 pm Post subject: Help with GetMenu |
|
|
I want to use GetMenu to get the handle to a menu.
I want the handle to be shown in a message box.
I'm still learning C++ and I have everything running except I do not know how to get the getmenu's return value into my message box. How do I do this?
| Code: |
GetMenu(hookWindow); // HookWindow is the HWND for a RichEdit
// I'm not sure if I am using GetMenu correctly. Please correct me if I am wrong.
MessageBoxA(NULL, "Menu", "The GetMenu's return value goes here",0); // This message box already shows, I just need the return value to be in the text
|
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Thu Apr 26, 2012 1:32 am Post subject: |
|
|
GetMenu:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms647640%28v=vs.85%29.aspx
The return is HMENU which is just a handle to the menu. A handle isn't really important data to show in a messagebox since it is not going to be the same always. At most, you would want to check if the return was null.
| Code: |
HMENU hMenu = GetMenu( hookWindow );
if( hMenu == NULL )
{
// The handle has no menu..
}
else
{
// A valid handle was returned.
}
|
_________________
- Retired. |
|
| Back to top |
|
 |
661089799107 Expert Cheater
Reputation: 3
Joined: 25 Jan 2009 Posts: 186
|
Posted: Thu Apr 26, 2012 10:59 am Post subject: |
|
|
| Code: |
template <typename T>
std::string toString(T in)
{
std::stringstream ss;
ss << in;
return ss.str();
}
|
| Code: |
MessageBoxA(0, "Menu", toString<HMENU>(GetMenu(hookWindow)).c_str(), 0);
|
Last edited by 661089799107 on Thu Apr 26, 2012 9:33 pm; edited 1 time in total |
|
| Back to top |
|
 |
The0neThe0nly Expert Cheater
Reputation: 0
Joined: 08 Dec 2009 Posts: 119 Location: In a box
|
Posted: Thu Apr 26, 2012 8:25 pm Post subject: |
|
|
| Bill87 wrote: | | Code: |
template <typename T>
std::string toString(T in)
{
std::stringstream ss;
ss << in;
return ss.str();
}
|
| Code: |
MessageBoxA(0 "Menu", toString<HMENU>(GetMenu(hookWindow)).c_str(), 0);
|
|
It gave an error.
| Code: | | error C2297: '<<' : illegal, right operand has type 'HMENU ' |
|
|
| Back to top |
|
 |
661089799107 Expert Cheater
Reputation: 3
Joined: 25 Jan 2009 Posts: 186
|
Posted: Thu Apr 26, 2012 9:30 pm Post subject: |
|
|
Make sure you are including everything you need.
| Code: |
#include <Windows.h>
#include <string>
#include <sstream>
|
|
|
| Back to top |
|
 |
|