 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
David Erbas-White Guest
|
Posted: Fri Aug 26, 2005 5:00 pm Post subject: Using MessageBox |
|
|
Originally posted in ms_compatibility, it was suggested I move it here...
I've got a series of messages that are given to the user at different
stages of a process, and I'm simply using MessageBox for them (no real
reason not to up until this point).
Now, my client would like me to add the ability to 'print' the text
contents of them. No big deal, but rather than 'roll my own' message
box with a 'print' button on it, I was wondering whether anyone had
played around with finding out if keys can be captured by an application
while a messagebox is up -- then I could simply put a line at the bottom
that says "Press CTRL-P to print this screen" or something similar.
Barring that, any other suggestions/solutions that come to mind? If
not, I'll simply do the roll-your-own one...
David Erbas-White
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Fri Aug 26, 2005 10:42 pm Post subject: Re: Using MessageBox |
|
|
David Erbas-White <derbas (AT) arachneering (DOT) com> wrote:
| Quote: |
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
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Aug 26, 2005 11:46 pm Post subject: Re: Using MessageBox |
|
|
"JD" <nospam (AT) nospam (DOT) com> wrote
| Quote: | you can add another button
|
At no point in the code you showed do you add a button to the messagebox
dialog.
See my other reply.
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|