Link to home
Start Free TrialLog in
Avatar of allmer
allmerFlag for Türkiye

asked on

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

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?
Thanks,
Jens
Avatar of Roshan Davis
Roshan Davis
Flag of United States of America image

For adding context help button in title bar...

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

~roshan
Avatar of allmer

ASKER

Thanks,
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.
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of allmer

ASKER

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?
Jens
Avatar of allmer

ASKER

Hi,
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.
Jens
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