CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2002
    Posts
    936

    Simple MFC Question

    I haven't worked with MFC for a long time. I just tried a simple ribbon application. After adding a button to a group and add a handler for the button. I added a value in the string table for the button as well as in the afxres.h. The problem I have, when I click on the button, I try to display a messagebox, however the button is disable when I ran the program. I want to know how to fix that. Maybe I don't remember. I haven't been using MFC for a long time.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Simple MFC Question

    I do not use ribbon bars in my projects because I consider them to be absolutely unusable.
    As for old style MFC application the toolbar button stays disabled unless either ON_COMMAND or ON_UPDATE_COMMAND_UI message handler for it has been implemented.
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2002
    Posts
    936

    Re: Simple MFC Question

    Quote Originally Posted by VictorN View Post
    I do not use ribbon bars in my projects because I consider them to be absolutely unusable.
    As for old style MFC application the toolbar button stays disabled unless either ON_COMMAND or ON_UPDATE_COMMAND_UI message handler for it has been implemented.
    The following has been added to message map

    ON_COMMAND(ID_BUTTON2, &CAboutDlg::OnButton2)

    and the function implementation here

    void CAboutDlg::OnButton2()
    {
    MessageBox(L"my data", L"my caption");
    }

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Simple MFC Question

    Quote Originally Posted by vcstarter View Post
    The following has been added to message map

    ON_COMMAND(ID_BUTTON2, &CAboutDlg::OnButton2)

    and the function implementation here

    void CAboutDlg::OnButton2()
    {
    MessageBox(L"my data", L"my caption");
    }
    First, please use Code tags while posting code snippes.
    Second, I have no idea what ID_BUTTON2 is and where is it supposed to be placed. BTW, did you added your ribbon bar to the CAboutDlg dialog?
    Victor Nijegorodov

  5. #5
    Join Date
    Jun 2002
    Posts
    936

    Re: Simple MFC Question

    ID_BUTTON2 is the ID of the button in the ribbon. I tried to zip the project and attached it, but it is too big after I zip it. It looks like the wirzard created a big SQL Compaq file.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Simple MFC Question

    Quote Originally Posted by vcstarter View Post
    ID_BUTTON2 is the ID of the button in the ribbon. I tried to zip the project and attached it, but it is too big after I zip it. It looks like the wirzard created a big SQL Compaq file.
    Delete the SQL file and debug and release folders, then rezip.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Simple MFC Question

    Quote Originally Posted by vcstarter View Post
    ID_BUTTON2 is the ID of the button in the ribbon. I tried to zip the project and attached it, but it is too big after I zip it. It looks like the wirzard created a big SQL Compaq file.
    Don't include Debug, Release, ipch folders, nor any unneed file (like .suo, .aps, .sdf.)
    You haven't answer my question about where is your ribbon bar belong to and where do you try to handle messages from it.
    Victor Nijegorodov

  8. #8
    Join Date
    Jun 2002
    Posts
    936

    Re: Simple MFC Question

    I created the test project from the wizard. When I added the handler for the button, it looks like it choose the CDialog class, so that may be the problem. Maybe it should be in CView.

    you can take a look of the project. I attached it
    Attached Files Attached Files

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Simple MFC Question

    If the handler for the toolbar button is in a modal dialog then it is wrong.
    Handler should be in one on the following classes:
    • CView derived class
    • CDocument derived class
    • CWinApp derived class
    • CMainFrame derived class
    Victor Nijegorodov

  10. #10
    Join Date
    Jun 2002
    Posts
    936

    Re: Simple MFC Question

    Quote Originally Posted by VictorN View Post
    If the handler for the toolbar button is in a modal dialog then it is wrong.
    Handler should be in one on the following classes:
    • CView derived class
    • CDocument derived class
    • CWinApp derived class
    • CMainFrame derived class
    That was the problem. I realized that now. It was in the wrong place.

    thanks

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Simple MFC Question

    Btw, unless you always want to have the button enabled, be sure to create an ON_COMMAND_UPDATE_UI handler as well.

    Then you can enable or disable the button on the fly using pCmdUI->Enable(...) method.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured