Click here to Skip to main content
15,892,537 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionC++ reads utf-8 xml file Pin
Member 47565741-Mar-09 11:52
Member 47565741-Mar-09 11:52 
AnswerRe: C++ reads utf-8 xml file Pin
Sarath C1-Mar-09 17:36
Sarath C1-Mar-09 17:36 
QuestionGetShortPathName Pin
tom groezer1-Mar-09 9:54
tom groezer1-Mar-09 9:54 
AnswerRe: GetShortPathName Pin
Stuart Dootson1-Mar-09 10:09
professionalStuart Dootson1-Mar-09 10:09 
GeneralRe: GetShortPathName Pin
tom groezer1-Mar-09 21:08
tom groezer1-Mar-09 21:08 
GeneralRe: GetShortPathName Pin
Stuart Dootson1-Mar-09 21:55
professionalStuart Dootson1-Mar-09 21:55 
QuestionStupid Menu Question Pin
Mats Selen1-Mar-09 8:19
Mats Selen1-Mar-09 8:19 
AnswerRe: Stupid Menu Question [modified] Pin
Stuart Dootson1-Mar-09 10:06
professionalStuart Dootson1-Mar-09 10:06 
If it's the same as the sample I just created, you specify the menu in the window class:

ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_XX));
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= MAKEINTRESOURCE(IDC_XX);
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

	return RegisterClassEx(&wcex);
}


To get the menu for a window of this class, use GetMenu[^] using the window handle.

[edit]Here's a sample commnd handler (insert in a switch statement like the one you have in your post) that inverts the checked state for a menu item (ID_FILE_TESTITEM) when the menu item is selected. This does assume that the File menu is the first sub-menu on the menu bar.

case ID_FILE_TESTITEM:
   {
      HMENU menu = GetMenu(hWnd);
      menu = GetSubMenu(menu, 0);
      const bool checked = (GetMenuState(menu, ID_FILE_TESTITEM, MF_BYCOMMAND)&MF_CHECKED)==MF_CHECKED;
      CheckMenuItem(menu, ID_FILE_TESTITEM, MF_BYCOMMAND | (checked?MF_UNCHECKED:MF_CHECKED));
   }


[/edit]

PS - any reason you're using raw C/C++ rather than a framework (WTL or MFC)? They do make it easier to do all this, honest Smile | :)

Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

modified on Sunday, March 1, 2009 4:25 PM

GeneralRe: Stupid Menu Question Pin
Mats Selen1-Mar-09 10:47
Mats Selen1-Mar-09 10:47 
GeneralRe: Stupid Menu Question Pin
Stuart Dootson1-Mar-09 11:29
professionalStuart Dootson1-Mar-09 11:29 
GeneralRe: Stupid Menu Question Pin
Richard Andrew x641-Mar-09 13:22
professionalRichard Andrew x641-Mar-09 13:22 
GeneralRe: Stupid Menu Question Pin
Mats Selen2-Mar-09 1:40
Mats Selen2-Mar-09 1:40 
Questiontemplate and vector [modified] Pin
transoft1-Mar-09 7:24
transoft1-Mar-09 7:24 
AnswerRe: template and vector Pin
Code-o-mat1-Mar-09 7:59
Code-o-mat1-Mar-09 7:59 
GeneralRe: template and vector Pin
transoft1-Mar-09 8:14
transoft1-Mar-09 8:14 
GeneralRe: template and vector Pin
Code-o-mat1-Mar-09 8:18
Code-o-mat1-Mar-09 8:18 
GeneralRe: template and vector Pin
transoft1-Mar-09 8:22
transoft1-Mar-09 8:22 
GeneralRe: template and vector Pin
Code-o-mat1-Mar-09 8:43
Code-o-mat1-Mar-09 8:43 
GeneralRe: template and vector Pin
transoft1-Mar-09 8:45
transoft1-Mar-09 8:45 
GeneralRe: template and vector Pin
Code-o-mat1-Mar-09 9:08
Code-o-mat1-Mar-09 9:08 
GeneralRe: template and vector Pin
transoft1-Mar-09 9:50
transoft1-Mar-09 9:50 
GeneralRe: template and vector Pin
Stuart Dootson1-Mar-09 9:30
professionalStuart Dootson1-Mar-09 9:30 
QuestionCan a ellipsis (Variadic) function i.e Func(...) be exported from a DLL Pin
Ru_Coding1-Mar-09 4:06
Ru_Coding1-Mar-09 4:06 
AnswerRe: Can a ellipsis (Variadic) function i.e Func(...) be exported from a DLL Pin
Stuart Dootson1-Mar-09 4:50
professionalStuart Dootson1-Mar-09 4:50 
GeneralRe: Can a ellipsis (Variadic) function i.e Func(...) be exported from a DLL Pin
Ru_Coding2-Mar-09 1:04
Ru_Coding2-Mar-09 1:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.