|
-
September 24th, 1999, 03:47 AM
#1
Creating a MenuHandle
Hi all,
I would like to set a checked mark to the menuitem that was selected by the user.
The CheckMenuItem seems to be the correct function,CheckMenuItem(HMENU hmenu, UINT
uIDCheckItem, UINT uCheck), but how do I create handle to a menu that is defined in the resources?
Or what else is needed to get the checked mark showing up?
Thanks for your help.
Martin
-
September 24th, 1999, 04:44 AM
#2
Re: Creating a MenuHandle
getmenu will return a pointer to a CMenu.
CMenu has a CheckMenuItem member function.
mtighe,
[email protected]
-
September 24th, 1999, 04:48 AM
#3
Re: Creating a MenuHandle
Also,
if the menu is not created yet you can use
LoadMenu, setmenucheck and then setmenu.
mtighe,
[email protected]
-
September 24th, 1999, 06:09 AM
#4
Re: Creating a MenuHandle
Hi,
Could you please help me with this code? It doesn't do anything... and I don't have a setmenucheck function in my help library...
HMENU hMenu;
hMenu = LoadMenu(hInstance, "IDC_F4MEM");
case IDM_START:
{
CheckMenuItem(hMenu,IDM_START,MF_CHECKED);
}
break;
When I select Start from the menu, nothing happens regarding the
checked-mark.
Thank you for your help.
Martin
-
September 24th, 1999, 06:16 AM
#5
Re: Creating a MenuHandle
First, is your application win32 only or mfc.
this will tell me if you have access to the
CMenu class. if not, no big deal. i will do
up a example in win32.
mtighe,
[email protected]
-
September 24th, 1999, 08:27 AM
#6
Re: Creating a MenuHandle
It's Win32 only. No MFC and no CMENU.
Thanks!
Martin
-
September 24th, 1999, 04:08 PM
#7
Re: Creating a MenuHandle
The code could have been much shorter. but i thought maybe you would want to see the whole
thing. if you have any questions on the code
let me know.
// main.cpp
#define STRICT // strict type checking
#include <windows.h> // standard header
#include <windowsx.h> // message crackers
#include "resource.h" // resource definitions
//////////////////////////////////////////////////////////////////////
//
void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
static bool bChecked;
HMENU hm = GetMenu(hwnd);
CheckMenuItem(hm,IDM_CHECKTEST,(bChecked ? MF_UNCHECKED : MF_CHECKED));
bChecked = !bChecked;
}
/////////////////////////////////////////////////////////////////////
//
void OnDestroy(HWND hWnd)
{
PostQuitMessage(0);
}
/////////////////////////////////////////////////////////////////////
//
void OnPaint(HWND hWnd)
{
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hWnd,&ps);
Rectangle(hDC,50,50,100,100);
EndPaint(hWnd,&ps);
}
/////////////////////////////////////////////////////////////////////
//
long CALLBACK MainWndProc(
HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
HANDLE_MSG(hWnd,WM_COMMAND,OnCommand);
HANDLE_MSG(hWnd,WM_DESTROY,OnDestroy);
HANDLE_MSG(hWnd,WM_PAINT,OnPaint);
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
/////////////////////////////////////////////////////////////////////
//
BOOL InitInstance(HINSTANCE hInst,int nCmdShow)
{
HWND hAppWnd = 0;
hAppWnd = CreateWindowEx(WS_EX_CLIENTEDGE,TEXT("Martin"),TEXT("Martin"),
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,0,0,hInst,0);
if (!hAppWnd)
return FALSE;
ShowWindow(hAppWnd,nCmdShow);
UpdateWindow(hAppWnd);
return TRUE;
}
////////////////////////////////////////////////////////////////////
//
BOOL InitApplication(HINSTANCE hInst)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW|CS_VREDRAW;
wcex.lpfnWndProc = MainWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInst;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(0,IDC_ARROW);
wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1);
wcex.lpszMenuName = TEXT("AppMenu");
wcex.lpszClassName = TEXT("Martin");
wcex.hIconSm = 0;
if (0 == RegisterClassEx(&wcex))
return FALSE;
return TRUE;
}
/////////////////////////////////////////////////////////////////
//
int WINAPI WinMain(
HINSTANCE hInst,HINSTANCE hPrev,LPSTR lpCmdLine,int nCmdShow)
{
InitApplication(hInst);
InitInstance(hInst,nCmdShow);
MSG msg;
while (GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
HTH,
mtighe
[email protected]
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
|