Board index » cppbuilder » Application->MessageBox

Application->MessageBox

A Message Box can be made to display a Help button by including the
MB_HELP flag in the Flags field.  But how does one activate a specific
Help topic when this Help button is clicked?  I tried:

if (Application->MessageBox(Text1.c_str(), Caption1.c_str(), MB_OK |
MB_HELP | MB_ICONERROR) != IDOK)
{Application->HelpCommand(HELP_CONTEXT, 413);}

where Text1 and Caption1 are AnsiStrings, and 413 is the desired
HelpContext.  The Message Box will not close if the Help button is
clicked, and the above code is never reached.  (Clicking the OK button
closes the Message Box.)

Any suggestions would be appreciated.

Regards,

Jon Gabel

 

Re:Application->MessageBox


Use the Win32 API function MessageBox() instead of the VCL one, then you can
catch the WM_HELP message being sent when the Help button or F1 is pressed.
For example:

class TForm1 : public TForm
{
private:
    void __fastcall WMHelp(TMessage &Message);
public:
    BEGIN_MESSAGE_MAP
        VCL_MESSAGE_HANDLER(WM_HELP, TMessage, WMHelp)
    END_MESSAGE_MAP(TForm)

Quote
};

void __fastcall TForm1::WMHelp(TMessage &Message)
{
    HELPINFO *lphi = (HELPINFO*)Message.LParam;
    // lphi contains information about the request

    TForm::Dispatch(&Message);

Quote
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    ::MessageBox(Handle, Text1.c_str(), Caption1.c_str(), MB_OK | MB_HELP |
MB_ICONERROR);

Quote
}

Gambit
Quote
"Jon Gabel" <jonga...@dnai.com> wrote in message news:3b4dece9_2@dnews...
> A Message Box can be made to display a Help button by including the
> MB_HELP flag in the Flags field.  But how does one activate a specific
> Help topic when this Help button is clicked?

Re:Application->MessageBox


Try the VCL function MessageDlg(.......)

It allows you to supply a help context as a parameter.  it allows has more
button features than App->MessageBox.

Mark

Quote
"Jon Gabel" <jonga...@dnai.com> wrote in message news:3b4dece9_2@dnews...
> A Message Box can be made to display a Help button by including the
> MB_HELP flag in the Flags field.  But how does one activate a specific
> Help topic when this Help button is clicked?  I tried:

> if (Application->MessageBox(Text1.c_str(), Caption1.c_str(), MB_OK |
> MB_HELP | MB_ICONERROR) != IDOK)
> {Application->HelpCommand(HELP_CONTEXT, 413);}

> where Text1 and Caption1 are AnsiStrings, and 413 is the desired
> HelpContext.  The Message Box will not close if the Help button is
> clicked, and the above code is never reached.  (Clicking the OK button
> closes the Message Box.)

> Any suggestions would be appreciated.

> Regards,

> Jon Gabel

Re:Application->MessageBox


Remy,

Thanks for the info, it will come in useful, but....I have one more
question, do you know how to set the help context for a MessageBox. The
API apparently needs the window handle to set the context using
SetWindowContextHelpId, but the message dialog doesn't exist prior to it
being displayed, and afterwards there is no opportunity to get the
handle until it is closed, then it is gone! What is the trick?

--
......................................................................
Men never do evil so completely and cheerfully as when they do it from
religious conviction.

Blaise Pascal, philosopher and mathematician (1623-1662)

Re:Application->MessageBox


As was already suggested, use MessageDlg() instead of MessageBox().
MessageDlg() has a HelpCtx parameter.  MessageBox() doesn't support what
you're asking about now.

Gambit

Quote
"Colin Attwell" <co...@new.co.za> wrote in message

news:3B50B401.1277BFB3@new.co.za...
Quote
> Thanks for the info, it will come in useful, but....I have one more
> question, do you know how to set the help context for a MessageBox. The
> API apparently needs the window handle to set the context using
> SetWindowContextHelpId, but the message dialog doesn't exist prior to it
> being displayed, and afterwards there is no opportunity to get the
> handle until it is closed, then it is gone! What is the trick?

Re:Application->MessageBox


Quote
Remy Lebeau wrote:

> As was already suggested, use MessageDlg() instead of MessageBox().
> MessageDlg() has a HelpCtx parameter.  MessageBox() doesn't support
> what
> you're asking about now.

> Gambit

> "Colin Attwell" <co...@new.co.za> wrote in message
> news:3B50B401.1277BFB3@new.co.za...

> > Thanks for the info, it will come in useful, but....I have one more
> > question, do you know how to set the help context for a MessageBox.
> The
> > API apparently needs the window handle to set the context using
> > SetWindowContextHelpId, but the message dialog doesn't exist prior
> to it
> > being displayed, and afterwards there is no opportunity to get the
> > handle until it is closed, then it is gone! What is the trick?

Ta.
--
......................................................................
Men never do evil so completely and cheerfully as when they do it from
religious conviction.

Blaise Pascal, philosopher and mathematician (1623-1662)

Re:Application->MessageBox


Quote
> As was already suggested, use MessageDlg() instead of MessageBox().
> MessageDlg() has a HelpCtx parameter.  MessageBox() doesn't support

Actually, on second thoughts MessageDlg doesn't cut the cheese for me.
I'd like more control of the Caption, and when I tried it last night I
couldn't get the WM_HELP event to fire when hitting the help button, so
I guess I'll need to roll my own....

Other Threads