MFC 有没有弹框(类似MessageBox)函数能像TRACE 一样带参数呢

2025-03-04 21:33:41
推荐回答(4个)
回答1:

给你一个函数:
CString Format(const char *strLine, ...)
{
va_list v;
va_start(v, strLine);
char buf[1000]={0};
vsprintf(buf, strLine, v);
return buf;
}
这样你就可以这样用了,如:
AfxMessageBox(Format("结果为:%d",a));

回答2:

没有现成的,也没有必要有现成的,因为可以先用CString格式化完后再输出:

CString str;
str.Format(_T("..."),...);

MessageBox(str, ...);

回答3:

int AfxMessageBox(
LPCTSTR lpszText,
UINT nType = MB_OK,
UINT nIDHelp = 0
);
int AFXAPI AfxMessageBox(
UINT nIDPrompt,
UINT nType = MB_OK,
UINT nIDHelp = (UINT
) -1
);

Parameters
lpszText
Points to a CString object or null-terminated string containing the message to be displayed in the message box.

nType
The style of the message box. Apply any of the message-box styles to the box.

nIDHelp
The Help context ID for the message; 0 indicates the application's default Help context will be used.

nIDPrompt
A unique ID used to reference a string in the string table.

Return Value
Zero if there is not enough memory to display the message box; otherwise, one of the following values is returned:

IDABORT The Abort button was selected.

IDCANCEL The Cancel button was selected.

IDIGNORE The Ignore button was selected.

IDNO The No button was selected.

IDOK The OK button was selected.

IDRETRY The Retry button was selected.

IDYES The Yes button was selected.

If a message box has a Cancel button, the IDCANCEL value will be returned if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing the ESC key has no effect.

Example
// A simple message box, with only the OK button.
AfxMessageBox("Simple message box.");

// A message box that uses a string from a string table
// with yes and no buttons and the stop icon.
// NOTE: nStringID is an integer that contains a valid id of
// a string in the current resource.
AfxMessageBox(nStringID, MB_YESNO|MB_ICONSTOP);

回答4:

我一般是用之前格式化下字符串。