Article View: borland.public.cppbuilder.nativeapi
Article #5197Re: Using MessageBox
From: JD
Date: Fri, 26 Aug 2005 22:42
Date: Fri, 26 Aug 2005 22:42
81 lines
4068 bytes
4068 bytes
David Erbas-White <derbas@arachneering.com> wrote:
>
> any other suggestions/solutions that come to mind?
As long as language isn't an issue, you can add another button
and change it's caption but check for the original result.
//-------------------------------------------------------------
BOOL CALLBACK EnumChildCallBack( HWND hWnd, LPARAM lParam )
{
char Buffer[256] = {0};
if( ::GetClassName(hWnd, Buffer, 255) )
{
if( stricmp(Buffer, (char*)lParam) == 0 )
{
::GetWindowText( hWnd, Buffer, 255 );
if( stricmp(Buffer, "OK") == 0 ) strcpy(Buffer, "OK Button");
else if( stricmp(Buffer, "Cancel") == 0 ) strcpy(Buffer, "Cancel Button");
else if( stricmp(Buffer, "&Yes") == 0 ) strcpy(Buffer, "&Yes Button");
else if( stricmp(Buffer, "&No") == 0 ) strcpy(Buffer, "&No Button");
else if( stricmp(Buffer, "&Abort") == 0 ) strcpy(Buffer, "&Abort Button");
else if( stricmp(Buffer, "&Retry") == 0 ) strcpy(Buffer, "&Retry Button");
else if( stricmp(Buffer, "&Ignore") == 0 ) strcpy(Buffer, "&Ignore Button");
::SetWindowText( hWnd, Buffer );
}
}
return TRUE;
}
//-------------------------------------------------------------
void __fastcall TForm1::WndProc(TMessage &Message)
{
if( Message.Msg == APP_MESSAGEBOX_MESSAGE )
{
SetupMessageBox( this );
}
TForm::WndProc(Message);
}
//-------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString Text = "First row of message.\nSecond row of message.";
MessageBoxCaption = "This is the message box caption";
::PostMessage( Handle, APP_MESSAGEBOX_MESSAGE, 0, 0 );
::MessageBox( Handle, Text.c_str(), MessageBoxCaption.c_str(), MB_ICONERROR | MB_ABORTRETRYIGNORE );
}
//-------------------------------------------------------------
void __fastcall TForm1::SetupMessageBox( TForm* pForm )
{
RECT R;
int x, y, w, h;
HWND MessageBoxHandle = FindWindow( MAKEINTRESOURCE(WC_DIALOG), MessageBoxCaption.c_str() );
if( MessageBoxHandle )
{
AnsiString WindowClassName = "Button";
::EnumChildWindows( MessageBoxHandle, (WNDENUMPROC)EnumChildCallBack, (LPARAM)WindowClassName.c_str() );
// center it on the target form
::GetWindowRect( MessageBoxHandle, &R );
w = R.right - R.left;
h = R.bottom - R.top;
// center the box
x = pForm->Left + ((pForm->Width - w) / 2);
y = pForm->Top + ((pForm->Height - h) / 2);
// keep on screen
if( x < 0 ) x = 0;
else if( x + w > Screen->Width ) x = Screen->Width - w;
if( y < 0 ) y = 0;
else if ( y + h > Screen->Height ) y = Screen->Height - h;
// set new windows position
::SetWindowPos( MessageBoxHandle, 0, x, y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER );
}
}
//-------------------------------------------------------------
~ JD
Technical Details
Message-ID:
<430f9ad3$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.moat.net!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<430f4a7f$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,f7584baaf146a181 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "JD" <nospam@nospam.com> Sender: "JD" <nospam@nospam.com> Reply-To: "JD" <nospam@nospam.com> Subject: Re: Using MessageBox Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 205.188.116.198 X-Forwarded-For: 172.156.199.172 References: <430f4a7f$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <430f9ad3$1@newsgroups.borland.com> Date: 26 Aug 2005 15:42:27 -0700 X-Trace: newsgroups.borland.com 1125096147 207.105.83.66 (26 Aug 2005 15:42:27 -0700) Lines: 82 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.moat.net!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mail