Using help for custom checkbox in CFileDialog

 I am using a class derived from CFileDialog. I have created a custom checkbox below the default one that comes with CFileDialog i.e. 'Open as read-only'. However when I try to associate help with that custom checkbox I get no help associated.
Here is the code I am using
CRect rectCheckbox;
GetParent()->GetDlgItem( chx1 )->GetWindowRect( rectCheckbox );

// Make the text window a little bigger
int nWindowWidth = rectCheckbox.Width() + 200;
int nWindowHeight = rectCheckbox.Height();
ScreenToClient( &rectCheckbox );

//  Create checkbox with style and font and location from the //read-only checkbox
CButton m_TestHelp;

rectCheckbox, GetParent(),IDC_TEST_HELP);

CWnd *pCtl = GetParent()->GetDlgItem( IDC_TEST_HELP );

pCtl->SetWindowPos( NULL, rectCheckbox.left,, nWindowWidth, nWindowHeight,

pCtl->EnableWindow( TRUE );
pCtl->ShowWindow( SW_SHOW );
pCtl->SetWindowContextHelpId( HIDC_TEST_HELP);
So when I click on the question mark next to 'X' at the top of the dialog and drag it on the custon checkbox created I don't get the help id associated with HIDC_TEST_HELP. I get the default help id 28441/0x6f19 which says 'no help associated with this item'.
Please help.
Who is Participating?
akalmaniConnect With a Mentor Commented:
Hi I could get hold of one more link just have a look if it solves your problem
Check this link, probably you need to override ON_WM_HELPINFO and display help. As per your code pasted I do not see anything which is done like this..
vgandhi2003Author Commented:
Hi ,
 Thanks for your comment. I have the following method defined in the dialog but it doesn't even hit this method when I click on the question mark and drag it on the checkbox.

BOOL CCustomFileDialog::OnHelpInfo(HELPINFO* pHelpInfo)
      // TODO: Add your message handler code here and/or call default      
      return CFileDialog::OnHelpInfo(pHelpInfo);
So please let me know.
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

>>>//  Create checkbox with style and font and location from the //read-only checkbox
>>>CButton m_TestHelp;

Is m_TestHelp a member of the CCustomFileDialog or a local variable created in  CCustomFileDialog::OnInitDialog() ?

Create this as a member of CCustomFileDialog as it needs to persist until the dialog is destroyed.

Try this out ..
You can set up help on modal dialogs by changing their style. Dialog needs this properties. If you have created your own dialog resource for CCustomFileDialog, then set the Context Help property in the extended properties of the dialog resource.

If you are using the default dialog resource template then do the following...
ModifyStyleEx(0, WS_EX_CONTEXTHELP) in the on initdialog.
I gave it a try it does not work..please ignore my comments.
Take a look and see if you can implement something like this..;en-us;117563
I serached a few MS KB articles...maybe this will give you some hints;en-us;195034
vgandhi2003Author Commented:
 Thanks  a lot for your help. Infact on the last link that you sent me;en-us;195034
if you check out the context sensitive help support section it says
CCustomFileDialog::OnHelpInfo() is called when the WM_HELP message is generated by clicking the ? on the caption bar.
However if you download the files for this project and put a break point in the OnHelpInfo method it never hits it even though Microsoft claims that it will hit it if you click on the ?.
So is there something I might be missing? Let me know. thanks
In the final window which is shown from the above mentioned sample. Deselect "Explorer style" and select "Multi-Select". Then click "Go!". Set a break point on ON_WM_HELPINFO. See that it works and the function is called.

I am wondering if EXPLORER style is set then this function is not called. Maybe a bug in MFC.
vgandhi2003Author Commented:
Ok so now if I add the following line
      m_ofn.Flags &= ~(OFN_EXPLORER|OFN_HIDEREADONLY);
in the constructor and pass in the following flags

I get the multi select dialog with the onhelpinfo working but how do I add my custom checkbox ?
I don't have the id for the read-only checkbox so not sure how it would work?
vgandhi2003Author Commented:
Also I investigated and found out that through SPY++ the WM_HELP message is generated when you click on the question mark but it doesn't get caught. I tried using hook procedure and through callback but doesn't get caught at all. Something in the middle eats it up.
vgandhi2003Author Commented:
hey the solution is that u have to create a derived class.
make a component of that derived class
and in the dialog's oninit dialog
do the following

BOOL bSubclwhassed = m_wndTempDervivedmember.SubclassWindow(GetParent()->m_hWnd);
You'll be able to hit on the OnHelpInfo msg then.

Seems weird but thats the way.
Since you've really helped me a lot I'll give the points to you. Thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.