Mood:

Topic: VC++
It's a hard chore for a programmer to display string and integers in a message box, mainly because they have to use CString or sprintf to get these integers in formatted manner...
For eg:
int nAge = 27, nSal=100;
CString csStr;
csStr.Format( _T( "Age: %d, nSal: %d" ), nAge, nSal );
AfxMessageBox( csStr );
How can we automate this whole process? Here is the answer in the form of a function called ShowMsg.
For eg:
// Shows dialog
void __cdecl ShowMsg( LPCTSTR lpctszTitle_i, const DWORD dwIconType_i, LPCTSTR lpctszMessage_i, ... )
{
va_list vaArgList;
va_start( vaArgList, lpctszMessage_i );
CString csMsg;
csMsg.FormatV( lpctszMessage_i, vaArgList );
MessageBox( AfxGetMainWnd()->GetSafeHwnd(),
csMsg,
lpctszTitle_i,
dwIconType_i );
va_end( vaArgList );
}// End ShowMsg
And call this function like wise
ShowMsg( _T( "Title" ),You can customize this function based on your need.
MB_OK|MB_ICONINFORMATION,
_T( "My name is %s, my age is %d, my salary is %d" ),
_T( "Nibu babu thomas" ), 27, 100 );