How to add "What's this?" button to the dialog (not the title bar)?

Posted on 2005-04-27
Last Modified: 2013-11-20
Hi experts,
I would like the CDialog I am using to be minimizable.
I would also like a ?-button. This doesn't have to be in
the title bar, it may be a regular CButton. It should however
have the same functionallity as the ?-button that could be
in the title bar if it wasn't for minimize and maximize.
Any ideas?
Question by:allmer
    LVL 23

    Expert Comment

    by:Roshan Davis
    For adding context help button in title bar...

       BOOL CMyDialog::OnInitDialog()
            LONG style = ::GetWindowLong(m_hWnd, GWL_EXSTYLE);
            style |= WS_EX_CONTEXTHELP;
            ::SetWindowLong(m_hWnd, GWL_EXSTYLE, style);
            return TRUE;

    LVL 5

    Author Comment

    as I understand it is not possible to have a minimize, maximize and help button in the titlebar.
    How can I add a button to the dialog that has the same functionallity as the help button in
    the titlebar?
    I tried the adding the code, but the ?-button didn't show up.
    LVL 49

    Accepted Solution

    In the resource editor, set the properties
    Under the "Styles" tab set checks in "TitleBar" "System menu," and "Minimize Box"
    Under the "Extended Styles" tab, put a check in the "Context menu" checkbox.

    That shows all four buttons, but Maximize is disabled.  

       PRB: Context Help Not Compatible with Min or Max Button;en-us;135787

    says ... this behavior is by design"
    (but the article itself is incorrect in that the minimize button *is* allowed and thus (apparenttly) compatible.

    And I agree... dialog boxes are intended to float above an app...  One would never want to maximize one.

    I tried several tricks to force the maximize to be enabled, but
    (which works to disable the minimize button) does not work to enable the maximize button.

    In theory, you could draw your own button on the caption (title bar), but that is something of a pain, and, anyway, as I said, it should not be necessary.

    -- Dan
    LVL 5

    Author Comment

    Thanks Dan,
    I am fine with not beeing able to maximize the Dialog.
    I didn't code any resize functionallity anyway.

    Problem is that I don't have context menu option in fact I
    don't see extended styles at all.
    And under Misc I cannot set context help when I set the
    other parameters that you suggested.
    Am I missing something here?
    LVL 5

    Author Comment

    it seems to work on some computers.
    I have examples for it working in XP and
    also examples for it not working in XP.

    I would really like to mirror the ? functionallity to a regular CButton on my dialog.
    Something like:
    void CMyDlg::OnBnClickedButtonF1Help() {
       //Make the ?-pointer appear and behave
      //as if the ? in the titlebar would have been clicked.

    That would be perfect.
    LVL 49

    Expert Comment

    Alas, that will be rather tricky.  I can give you a general outline, but I don't have any code for you:

    1) Call SetCapture()
    2) Call SetCursoe to set the mouse cursor to look different.
    3) Provide a handler for WM_MOUSEMOVE and other mouse events
    4) When you get a WM_LBUTTONDOWN, based on the location, figure out which button or control is at the location clicked
    5) Call ReleaseCapture();
    6) Take some action such as displaying a page of your help.
    7) Also you need to be able to detect the ESC key to let the User get out of the captured mouse mode if he decides not to use it.

    All in all, it is not worth it.  
    I suggest just using the built-in/standard handling of the standard [?] button in the title bar.

    -- Dan

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Powershell based monitoring system 2 118
    iSeries DB2 Query 2 69
    string initialization in java 11 94
    Window placement 17 56
    Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
    Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now