65.9K
CodeProject 正在变化。 阅读更多。
Home

MessageBoxIndirect 的包装器

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.79/5 (7投票s)

2000年2月23日

viewsIcon

61915

downloadIcon

1736

一个封装了 MessageBoxIndirect 的类。

  • 下载演示项目 - 16 Kb
  • 下载源代码文件 - 2 Kb
  • Sample Image - messagebox.gif

    引言

    有时你可能希望在消息框中使用 Windows 提供的图标之外的其他图标,或者你可能希望更好地控制你的消息框,例如指定要使用的语言等。嗯,有一种方法可以使用鲜为人知的 API 调用 MessageBoxIndirect 来完成所有这些。

    这里有一个封装 MessageBoxIndirect 的类(实际上,它继承自传递给 MessageBoxIndirectMESSAGEBOXPARAMS 结构)。你可以像使用 MFC CDialog 一样使用它,尽管它没有 MFC 依赖项。


    用法

    1. 声明一个 CMessageBox 对象。
    #include "MessageBox.h"
    ....
    
    CMessageBox box;
    

    CMessageBox box(hWnd, "My Text", "My Caption", MB_OK);
    

    2. 初始化它(如果你只是显示一个标准消息框,可以跳过此步骤)

    box.SetIcon(IDI_SOMEICON);
    box.SetLangID(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL));
    

    3. 调用 DoModal

    if(box.DoModal() == MB_OK)
    {
    	// Do something here
    }
    else
    {
    	// Do something else
    }
    


    就是这样!

    © . All rights reserved.