SDI Menu App - MSVC 6

This is a discussion on SDI Menu App - MSVC 6 within the Windows Programming forums, part of the Platform Specific Boards category; I first posted this in the C++ board before I remembered there's a winows board, so sorry for the cross ...

  1. #1
    Unregistered
    Guest

    Question SDI Menu App - MSVC 6

    I first posted this in the C++ board before I remembered there's a winows board, so sorry for the cross post.

    The prof in our class gave this example of a windows program. When he first tried it in class, the "Sample Dialog" menu item was grayed out and inaccessible. He later got it to work, but he went through the procedure too fast to follow. When I try it, I still get the grayed out problem, as do others in the class. The prof insists it works fine. The example is this:

    Use MFC AppWizard(exe) to create an SDI (Single Document) framework called MenuApp.
    In Resource View, right click Dialog Resource and select Insert Dialog.
    In the Properties window for the Dialog Box that pops up, change ID to "IDD_SampleDlg", caption to "Sample Dialog".
    Back in Resource View, expand Menu Resource, double click IDR_MAINFRAME.
    Click File on Menu Resource that is displayed, and type "Sample Dialog" in the open box.
    In Sample Dialog Menu Item properties box, type "ID_SHOWDIALOG" in the ID field.
    Hold CTRL & double click Sample Dialog Menu Item to bring up Class Wizard, click Add Class and New.
    In Name field, enter CSampleDlg. In Base Class field choose CDialog. In Dialog ID field type ID_SHOWDIALOG.

    *** I believe the problem is in the above instructions, because we can't enter ID_SHOWDIALOG in the Dialog ID field in the last step. It's not an available choice, and can't be entered by hand. ***
    Later, in the OnShowDialog member function we enter:
    CSampleDlg dialog;
    dialog.DoModal();
    and #include CSampleDlg.h in MainFrm.cpp
    There's more to the example, but that's as far as I've gotten. This isn't homework, just an example he gave but doesn't support.
    Any help on this? The prof isn't. Thanks.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    When you open the menu are you clicking on a 'blank' menu item or on the FILE menu item?

    You should create a new item under FILE by clicking on a 'blank' menu item. Bring up its properties and you should be able to add in the new one for the dialog. Ensure that it is not 'INACTIVE' or 'GRAYED'.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    Originally posted by novacain
    When you open the menu are you clicking on a 'blank' menu item or on the FILE menu item?

    You should create a new item under FILE by clicking on a 'blank' menu item. Bring up its properties and you should be able to add in the new one for the dialog. Ensure that it is not 'INACTIVE' or 'GRAYED'.
    Well, I believe that's what I'm doing. I click File, which opens the drop down menus (new, save, etc), and type "Sample Dialog" in the box at the bottom of the menu that's outlined in hash marks or whatever. I bring up the property box ok. When I run the program, the item "Sample Dialog" is there, just grayed out. I haven't seen a "GRAYED" or "INACTIVE" property to set.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859

    My menu items start enabled by default

    I use WIN32 C no ++ on MSDev Studio 5.

    When I create a new menu item, entering the ID and text(caption), just under these edit boxes are a series of check boxes for the other properties of the menu item.
    There is also an other tab that contain more styles for the item.

    Not that I like to 'hack' round a problem, but you could try turning on the item from within the code.

    hDlg=GetActiveWindow();//handle of dialog
    hMenu=GetMenu(hDlg);//handle of menu
    EnableMenuItem(hMenu,ID_SHOWDIALOG,MF_BYCOMMAND|MF _ENABLED);//turn on menu item using its ID not position

    You should be able to find the C++/MFC equvalents in the help.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    It might be in the help, but we're not really learning windows/MFC per se yet. We're just being given examples, without much explanation. I'm not sure what I'd be looking for. I'll post the actual notes later, in case I missed something. I appreciate the help.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    Forgot to add, I did check on the grayed & inactive boxes, they weren't checked.

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    154

    Here's the instructions

    Here are the instructions as given. I think the problem is at or before step 13. I get as far as step 20, when the Sample Dialog item is grayed out. Thanks for any help:

    A Sample SDI Application using Menus....

    1. Create an SDI Framework with the MFC AppWizard (exe). Call it MenuApp.
    2. Open up the Resource View, Right Mouse-Click on the Dialog Resource.
    3. Select "Insert Dialog". A new Dialog Resource is created and displayed.
    4. Right Mouse-Click on the Dialog, select "Properties".
    5. In the Property Window, change the ID to "IDD_SampleDlg" and the caption to "Sample Dialog"
    6. Go back to the Resource View, Expand the Menu Resource and double-click on the IDR_MAINFRAME resource.
    7. The Menu Resource is displayed. Click on FILE to expand the File Menu. Then click on the last open box, below the Exit option.
    8. In this box, type in "Sample Dialog".
    9. Double-click on the Sample Dialog Menu Item to open the properties box.
    10. In ID, type "ID_SHOWDIALOG" and in the prompt, type "Display the Sample Dialog Window"
    11. Now, hold down the CTRL key and double click on the Sample Dialog Menu Item. This opens the Class Wizard.
    12. Click on the Add Class button. Choose New.
    13. In the Name Field, type CSampleDlg. In the Base Class field, choose CDialog. In the Dialog ID field, type ID_SHOWDIALOG.
    14. In the Class Wizard Object ID's, highlight ID_SHOWDIALOG. In Messages, select COMMAND and double mouse click on it. This opens up the Add Member Function Window.
    15. Leave the default name "OnShowdialog" and click on Ok.
    16. Now, double click on the OnShowdialog Member Function on the bottom of the window to get into the member function source code.
    17. Type the following two lines of code:

    CSampleDlg dialog;
    dialog.DoModal();

    18. Select BUILD | Rebuild All menu option.
    19. Note that it does not compile. The CSampleDlg.h file needs to be included. Scroll up to the top of the MainFrm.cpp source and type in "#include "SampleDlg.h" just below the "#include "MainFrm.h" line.
    20. Select BUILD | Rebuild All again. Run the program and select the FILE | Sample Dialog Menu Option. Note that the Dialog Window Opens. Clicking Ok or Cancel will close it. Exit the program.
    21. Open the Menu Resource and click on FILE to open the File Menu. You can move the Sample Dialog Menu Option by click and holding the option and moving it up/down the Menu. You can even move across Menus.
    22. Open the IDD_SampleDlg Resource. Move an Edit Box into the Resource. Open up the Resource Box's Properties and set the ID to IDC_INPUT.
    23. Point to the Edit Box and CTRL double-click on it. The Add Member Variable Window. Set the name to m_samplevar, the Category to variable, and the type to int. Click Ok.
    24. Click on the Spin Control and drag it over just to the right of the Edit Box. Open it's properties.
    25. Under the Styles tab, check Auto Buddy, and Set Buddy Integer.
    26. Click on LAYOUT | Set Tab Order. Verify that the spin control follows the Edit Box.
    27. Select BUILD | Rebuild All menu option again. Open the Dialog and check out your new spin control.


    Notes:

    The DoModal() function is inherited from the CDialog class. It displays the dialog and then waits until the dialog is closed (with the OK or Cancel) before returning control back to the MenuApp frame. Modal Windows require action to be taken in them before anything else can be done.

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >>Forgot to add, I did check on the grayed & inactive boxes, they weren't checked.

    They should NOT be checked or the item WILL be grayed or inactive.

    The instructions seem right. Though I use just C not MFC/C++. (No classes)

    I can't see the problem in the code but it could be in the Class member functions, prahaps try the C++ board.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 09:25 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM
  4. SDI Menu problem - Windows MSVC 6.0
    By Brown Drake in forum C++ Programming
    Replies: 0
    Last Post: 10-13-2001, 06:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21