Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to change button text in AfxMessageBox()

1,984 views
Skip to first unread message

Horst Steigner

unread,
Sep 4, 2001, 9:42:21 AM9/4/01
to
Hi,

is it possible (and how) to change the text of a button in
AfxMessageBox()! Background is, that i want to support diverent
languages in my application. Thanks for any hint.

Horst

--

======================================================================
Visolution GmbH, Systemlösungen für Bildverarbeitung
Horst Steigner
Barthelsmühlring 18
D-76870 Kandel
Tel.: 07275/9593-0
Fax: 07275/9593-33
email: H.Ste...@visolution.de
http://www.visolution.de
======================================================================

CheckAbdoul

unread,
Sep 4, 2001, 9:56:24 AM9/4/01
to

AfxMessageBox() calls the CWinApp's DoMessageBox(..) virtual function to
display the message box. Override this message handler in your derived App
class and show the dialog box of your choice. { which has the color button
you want }

Cheers
Check Abdoul
-------------------


"Horst Steigner" <h.ste...@visolution.de> wrote in message
news:3b94d822$1...@news.punkt.de...

Horst Steigner

unread,
Sep 4, 2001, 12:10:46 PM9/4/01
to
Hi Abdoul,

thanks for the hint. Overriding the DoMessageBox() is exactly what i
want to avoid. Because i have to write code for the whole handling of
the dialog (e.g. resizing the static field for the message text,
resizing the dialog itself depending of the size of the message text,
arrange the buttons ...). So i'm looking for an easier and less time
intensive solution.

Is overriding DoMessageBox() really the only way to change text of the
buttons in AfxMessageBox()?

Best regards

Scott McPhillips

unread,
Sep 4, 2001, 7:39:08 PM9/4/01
to
Horst Steigner wrote:
>
> Hi Abdoul,
>
> thanks for the hint. Overriding the DoMessageBox() is exactly what i
> want to avoid. Because i have to write code for the whole handling of
> the dialog (e.g. resizing the static field for the message text,
> resizing the dialog itself depending of the size of the message text,
> arrange the buttons ...). So i'm looking for an easier and less time
> intensive solution.
>
> Is overriding DoMessageBox() really the only way to change text of the
> buttons in AfxMessageBox()?
>
> Best regards
> Horst

Yes, it is the only way. The standard message box text is hard-coded
within Windows, not accessible from MFC or the API.

--
Scott McPhillips [VC++ MVP]

Jeff Partch

unread,
Sep 4, 2001, 11:32:56 PM9/4/01
to

"Horst Steigner" <h.ste...@visolution.de> wrote in message news:3b94d822$1...@news.punkt.de...
> Hi,
>
> is it possible (and how) to change the text of a button in
> AfxMessageBox()! Background is, that i want to support diverent
> languages in my application. Thanks for any hint.
>
> Horst

You could experiment with something along these lines...

void AFXAPI AfxHookWindowCreate(CWnd* pWnd);
BOOL AFXAPI AfxUnhookWindowCreate();

class CMessageBox : public CDialog
{
public:
int DoModal(LPCTSTR lpszText, UINT nType=MB_OK, UINT nIDHelp = 0)
{
AfxUnhookWindowCreate();
AfxHookWindowCreate(this);
return AfxMessageBox(lpszText, nType, nIDHelp);
}
protected:
virtual BOOL OnInitDialog()
{
BOOL bRet = CDialog::OnInitDialog();

if (CWnd* pWnd = GetDlgItem(IDOK))
pWnd->SetWindowText(_T("I Agree"));

return bRet;
}
// Messages
LRESULT CMessageBox::InternalInitDialog(WPARAM, LPARAM)
{
return (LRESULT)OnInitDialog();
}
DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(CMessageBox, CDialog)
ON_MESSAGE(WM_INITDIALOG, InternalInitDialog)
END_MESSAGE_MAP()

void CMainPageOne::OnButtonProceed()
{
CMessageBox mb;
mb.DoModal(_T("You must accept the terms of this license before proceeding..."));
}

HTH,

Jeff...
--
Please post all follow-ups to the newsgroup only.

Horst Steigner

unread,
Sep 5, 2001, 3:53:36 AM9/5/01
to
Hi Jeff,

seems to be an absolutly great solution. Thanks alot. All i have to do
is removing calls of AfxMessageBox() with CMessageBox::DoModal(). But
there i still one problem left. Messages from MFC are still shown using
AfxMessageBox().

0 new messages