-
September 14th, 2009, 11:02 PM
#1
HMENU Hotkeys & Icons
Hi all,
I have two problems, the first being the most important:
1.
I have a Win32 (Non-MFC) app with a window and a win32 menu on it (HMENU), and I've been searching all day for a way to display shortcuts (like "Ctrl+C") on the menu items. I know there's the RegisterHotkey function but that doesn't make the shortcut to display on the menu item. There MUST be a way to do this without owner drawing the menu! Does anybody know how to achieve this?
2.
How can I display 32-bit icons in the menu items? I know how to use SetMenuItemInfo, but the problem comes when loading the bitmap. LoadBitmap works only with 24-bit bitmaps or less. LoadImage doesn't work either. I can use LoadIcon, but it is not compatible with HBITMAP, required by the MENUITEMINFO structure. Maybe a clue on how to transform a 32-bit PNG resource to an HBITMAP?
Thanks in advance
-
September 15th, 2009, 02:46 AM
#2
Re: HMENU Hotkeys & Icons
1. Format the shortcut in the option of your menu, so that it is placed to the right side by inserting a tab character, "\t", just before the shortcut, e.g.
Code:
AppendMenu(hMenu, MF_STRING | MF_ENABLED, (UINT) (215), "&Copy\tCtrl+C");
The ampersand character is another way to have a shortcut, but it works for one character only, e.g. "C" not "Ctrl+C".
Then, in your code, you will have to manage Ctrl+C, e.g.
Code:
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* Handle the messages */
{
...
case WM_CHAR:
switch (wParam) {
case (WPARAM) (3): // ctrl C
PostMessage(hwnd, WM_COMMAND, 215, 0L); // redirect to my copy option
break;
case (WPARAM) (22): // ctrl V
...
break;
case (WPARAM) (24): // ctrl X
...
break;
case (WPARAM) (26): // ctrl Z
...
break;
}
break;
case WM_COMMAND:
switch(wParam) {
case 215: // Copy to clipboard
...
break;
...
}
Last edited by olivthill2; September 15th, 2009 at 03:27 AM.
-
September 15th, 2009, 03:05 AM
#3
Re: HMENU Hotkeys & Icons
Thanks olivthill2, that worked like a charm!
Now if someone could help me with problem #2...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|