Hey Nish,
I made a couple of modifications that make it a tad more useful. I also included the modification mentioned here earlier in a note.
I added the ability to include a help message to the dialog (I overloaded
First of all I added the following variables to InputBox.h
CButton m_help;
CString strHelp;
int ShowInputBox( CString, CString, CString, CString );
afx_msg void OnHelp();
Next I added the following things to InputBox.Cpp
ON_BN_CLICKED( 5100, OnHelp )
int CInputBox::ShowInputBox(CString strPrompt,CString strTitle,CString strDefault)
{
this->strDefault=strDefault;
this->strPrompt=strPrompt;
this->strTitle=strTitle;
Create( NULL,
strTitle,
WS_CAPTION | WS_SYSMENU,
CRect( 0, 0, 0, 0 ),
pParent );
pParent->EnableWindow( false );
RECT parentrect;
pParent->GetWindowRect( &parentrect );
MoveWindow( parentrect.left + ( ( parentrect.right - parentrect.left ) / 2 ) - 150,
parentrect.top + ( ( parentrect.bottom - parentrect.top ) / 2 ) - 65, 300, 130);
ShowWindow( SW_SHOW );
m_help.ShowWindow( false );
UpdateWindow();
MSG msg;
while ( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
if ( msg.message == WM_USER + 1 )
break;
switch( msg.message )
{
case WM_DESTROY:
break;
case WM_CLOSE:
break;
case WM_CHAR:
switch( msg.wParam )
{
case 0x0D:
OnOk();
break;
case 0x1B:
OnCancel();
break;
};
break;
};
}
ShowWindow( SW_HIDE );
pParent->EnableWindow( true );
return retvalue;
}
int CInputBox::ShowInputBox( CString strPrompt, CString strTitle, CString strDefault, CString strHelp )
{
this->strDefault = strDefault;
this->strPrompt = strPrompt;
this->strTitle = strTitle;
this->strHelp = strHelp;
Create( NULL,
strTitle,
WS_CAPTION | WS_SYSMENU,
CRect( 0, 0, 0, 0 ),
pParent );
pParent->EnableWindow( false );
RECT parentrect;
pParent->GetWindowRect( &parentrect );
MoveWindow( parentrect.left + ( ( parentrect.right - parentrect.left ) / 2 ) - 150,
parentrect.top + ( ( parentrect.bottom - parentrect.top ) / 2 ) - 65, 300, 130);
ShowWindow( SW_SHOW );
m_help.ShowWindow( true );
UpdateWindow();
MSG msg;
while ( GetMessage( &msg, NULL, 0, 0) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
if ( msg.message == WM_USER + 1 )
break;
switch( msg.message )
{
case WM_DESTROY:
break;
case WM_CLOSE:
break;
case WM_CHAR:
switch( msg.wParam )
{
case 0x0D:
OnOk();
break;
case 0x1B:
OnCancel();
break;
};
break;
};
}
ShowWindow( SW_HIDE );
pParent->EnableWindow( true );
return retvalue;
}
void CInputBox::OnClose()
{
retvalue=IDCANCEL;
InputText="";
PostMessage( WM_USER + 1 );
}
int CInputBox::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
if ( CFrameWnd::OnCreate(lpCreateStruct) == -1 )
return -1;
m_dummy.Create( "", WS_VISIBLE,CRect( 0, 0, 300, 130 ), this );
m_prompt.Create( strPrompt,
WS_VISIBLE,
CRect( 10, 5, 280, 40 ),
this, 3000 );
m_edit.Create( WS_VISIBLE | WS_BORDER,
CRect( 10, 50, 280, 70 ),
this,
4000 );
m_help.Create( "Help",
WS_VISIBLE,
CRect( 10, 75, 85, 95 ),
this,
5100 );
m_ok.Create( "OK",
WS_VISIBLE,
CRect( 100, 75, 180, 95 ),
this,
5000 );
m_cancel.Create( "Cancel",
WS_VISIBLE,
CRect( 195, 75, 275, 95 ),
this,
5050 );
m_edit.SetWindowText( strDefault );
m_edit.SetFocus();
return 0;
}
void CInputBox::OnCancel()
{
retvalue=IDCANCEL;
InputText="";
PostMessage(WM_USER+1);
}
void CInputBox::OnHelp()
{
AfxMessageBox( strHelp );
m_edit.SetFocus();
};
Sorry for the length. But I think this makes it even more useful.
-Doug
Doug Joseph (Engineering Guy)
|