2
votes

I have a dialog box in MFC which has help button. I am able to map help button with my help content.

on my dialog box, I have a edit box also i which user can enter anything. i am validating the edit control box that if something wrong user enters it will open error message box which display error and having help button too.

i wanted to map this error message box helpid to my content (which different from parent dialog box) but whenever click help button it shows me parent help content.

NOTE: i tried both APIs Afxmessagebox and Messagebox.

Solution from my side , (i don't know if it is correct ) Create another dialog box and mapp to help id as i di fro parent dialog box. and treat this dialog box as a error messagebox with domodal.

I feel i we can do this with messagebox itself but didn't find anything on web.

What i tried -

I tried following link but couldn't get success. http://www.codeproject.com/Articles/562/Add-a-Help-Button-to-a-MessageBox

VOID CALLBACK MsgBoxCallback(LPHELPINFO lpHelpInfo)
{
    CString str = AfxGetApp()->m_pszHelpFilePath;
    AfxGetApp()->WinHelp(lpHelpInfo->dwContextId);
} 

UINT AfxMessageBox(HWND hWnd, LPCTSTR szText, UINT nType, UINT nIDHelp = 0)
{
    MSGBOXPARAMS mbp;

    memset(&mbp, 0, sizeof mbp);

    mbp.cbSize = sizeof MSGBOXPARAMS; 
    mbp.hwndOwner = hWnd; 
    mbp.hInstance = AfxGetInstanceHandle(); 
    mbp.lpszText = szText; 
    AfxGetApp()->m_pszHelpFilePath = "C:\\Program Files (x86)\\\HELP\\130.htm";

    // if you wanted to specify a different caption, here is where you do it
    mbp.lpszCaption = AfxGetAppName(); 

    // if Help ID is not 0, then add a help button
    if (nIDHelp != 0)
    {
        mbp.dwStyle = nType | MB_HELP; 
    }
    else
    {
        mbp.dwStyle = nType; 
    }

    //  mbp.lpszIcon = ; // note, you could provide your own custom ICON here!

    mbp.dwContextHelpId = nIDHelp; 
    mbp.lpfnMsgBoxCallback = &MsgBoxCallback; 
    mbp.dwLanguageId = 0x0409;

    return ::MessageBoxIndirect(&mbp); 
}
1

1 Answers

0
votes

Here's how to do it:

  1. Create a string resource for each message box.

    Be sure to name the resource with an IDP_ prefix. Although IDS_ also corresponds to strings, the makehm command-line tool will not look for IDS_ when it builds the HTMLDefines.h file.

  2. Change your message box call(s) to AfxMessageBox(IDP_FOO, MB_OK|MB_HELP, IDP_FOO), substituting in other flags, as needed.

(Note: I had another answer, but it was way off, so I decided to start clean with a new answer instead of updating it.)