MessageBox variation
-
Hello guys, I am looking for a function that is similiar to MessageBox function, however, would have ability to include formatted variable in the pop-up windows box. Best way to illustrate, is something in combination of printf and MessageBox int number = 3; printf("Number is : %d", number); so, might mean doing that in forms of MessageBox MessageBox("Number is : %d", number); Is there funtion MFC that could server that purpose? Thanks in advance for any help.
-
Hello guys, I am looking for a function that is similiar to MessageBox function, however, would have ability to include formatted variable in the pop-up windows box. Best way to illustrate, is something in combination of printf and MessageBox int number = 3; printf("Number is : %d", number); so, might mean doing that in forms of MessageBox MessageBox("Number is : %d", number); Is there funtion MFC that could server that purpose? Thanks in advance for any help.
CString myMessage; myMessage.Format("Number is : %d", number); MessageBox(myMessage, ..., MB_OK); Brian
-
Hello guys, I am looking for a function that is similiar to MessageBox function, however, would have ability to include formatted variable in the pop-up windows box. Best way to illustrate, is something in combination of printf and MessageBox int number = 3; printf("Number is : %d", number); so, might mean doing that in forms of MessageBox MessageBox("Number is : %d", number); Is there funtion MFC that could server that purpose? Thanks in advance for any help.
There isn't an MFC function for this. I use code like the following in ED (see sig) for it's "Do not ask again" message boxs.
MsgBox( TCHAR* pStr, ... ) { va_list marker; va_start( marker, pStr ); const int nMaxMsgSize = 10 * 1024; // we don't know how to calc required size, so pick something large enough. TCHAR substmsg[ nMaxMsgSize+1 ] = {0}; _vsnprintf( substmsg, nMaxMsgSize, pStr, marker ); MessageBox( hWnd, substmsg, Caption, uType ); va_end( marker ); }
You need to fill in the missing bits like hWnd etc, Hope that helps. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program -
Hello guys, I am looking for a function that is similiar to MessageBox function, however, would have ability to include formatted variable in the pop-up windows box. Best way to illustrate, is something in combination of printf and MessageBox int number = 3; printf("Number is : %d", number); so, might mean doing that in forms of MessageBox MessageBox("Number is : %d", number); Is there funtion MFC that could server that purpose? Thanks in advance for any help.
Hello, The solution is to first format your string, then display the message box. The best way is probably to use a varlist and to implement your own function. Here is my own:
int AfxMessageBoxFormat (LPCTSTR lpszFormat, ...) { // Build message from parameters CString s; va_list args; va_start (args, lpszFormat); s.FormatV (lpszFormat, args); va_end (args); // Message box return AfxMessageBox (s); }
Hope that helps, JM Web: http://goa.ifrance.com -
Hello guys, I am looking for a function that is similiar to MessageBox function, however, would have ability to include formatted variable in the pop-up windows box. Best way to illustrate, is something in combination of printf and MessageBox int number = 3; printf("Number is : %d", number); so, might mean doing that in forms of MessageBox MessageBox("Number is : %d", number); Is there funtion MFC that could server that purpose? Thanks in advance for any help.