AfxMessageBox另外一种快速使用方法

在MFC中,很多字符串是要写到String table中的,如果AfxMessageBox要用到这种字符串,可以使用2种方法:

假设字符串ID为IDS_STRING1;

1.CString str;

str.LoadString(IDS_STRING1);

AfxMessageBox(str);

2.AfxMessageBox(IDS_STRING1); //这种方法明显更快。


AfxMessageBox

int AfxMessageBox( LPCTSTR lpszText, UINT nType = MB_OK, UINT nIDHelp = 0 );

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

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.

The functions AfxFormatString1 and AfxFormatString2 can be useful in formatting text that appears in a message box.

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.

Remarks

Displays a message box on the screen. The first form of this overloaded function displays a text string pointed to by lpszText in the message box and uses nIDHelp to describe a Help context. The Help context is used to jump to an associated Help topic when the user presses the Help key (typically F1).

The second form of the function uses the string resource with the ID nIDPrompt to display a message in the message box. The associated Help page is found through the value of nIDHelp. If the default value of nIDHelp is used (– 1), the string resource ID, nIDPrompt, is used for the Help context. For more information about defining Help contexts, see the articleHelp Topics in Visual C++ Programmer’s Guide and Technical Note 28.

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);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值