visual studio 6.0 MFC question.

Sep 29, 2004
18,656
68
91
This is aggrivating.

I created a test project in Visual Studio 6.0 (I am updating some old code that used 6.0 so it will be used to update code as well).

Specifically, I created a project using the "MFC class wizard(exe)"

That was fine. It compiled and ran with the default menu.

So, I added a new menu item via the resource editor. Now for the confusing thing. The menu item shows up in the disabled state when I run it (not in the resource editor). How do I fix this? Somewhere in the code, it is being disabled.

I could reproduce the problem with some specific steps for others to try if anyone has visual studio 6.0.

I am totally stuck at this point.

also: MICROSOFT SUCKS
 

SunnyD

Belgian Waffler
Jan 2, 2001
32,675
146
106
www.neftastic.com
Did you map that menu item to anything?

In the resource editor, right click on your menu option and select "ClassWizard". You'll see your command in the left pane and the message type in the right pane. You'll want to select "COMMAND" which will enable the "Add Function" button, then click on it which will prompt you for the name of the event handler you want to create. Name it, hit okay and start coding.

Alternatively you can manually edit the AFX message mappings in the code, though this will likely break ClassWizard if you don't do it right.

edit: Microsoft doesn't suck. RTFM before complaining.
 
Sep 29, 2004
18,656
68
91
Eclipse IDE vs Anything Visual Studio. Eclipse wins.

Regardless, sorry for complaining. I'm rusty with Visual Studio and never did menu controls in MFC this way. I've coded GUIs without resource managers in the past and it wasn't troublesome from what I remember. That was 5+ years ago though. I'm very rusty and I am now maintaining some code I didn't author, so I need to try and use the same techniques as the original authors.

Trying my best.

So, as long as there is a message handler, the menu item is enabled?
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
They have to be linked in some way using a Macro area of the .cpp file (VS should place the Macro in place when you use the Resource Editor to generate the association) - other than that, your answer is yes.
 

SunnyD

Belgian Waffler
Jan 2, 2001
32,675
146
106
www.neftastic.com
Originally posted by: IHateMyJob2004
So, as long as there is a message handler, the menu item is enabled?

Yes. With MFC you have to utilize the AFX message map macros in order to hook up the handlers.

Take a look at this sample message map from a derived view class if you want to do it by hand:

// TestView.cpp
IMPLEMENT_DYNCREATE(CTestView, CView)

BEGIN_MESSAGE_MAP(CTestView, CView)
//{{AFX_MSG_MAP(CTestView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::eek:nFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::eek:nFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::eek:nFilePrintPreview)
END_MESSAGE_MAP()
//------

If you don't want to use class wizard, this is what you'll edit by hand. Add an "ON_COMMAND" handler to the resource ID you want handled, then the function/method you want to handle that message. As I said before, be careful through, especially not to put anything in the AFX_MSG_MAP "commented" section otherwise ClassWizard usually breaks and sometimes causes the project itself to break.