zoukankan      html  css  js  c++  java
  • VS mfc MessageBox() 使用英文显示

    转载:http://blog.csdn.net/guoyk1990/article/details/44337249

    由于特殊原因我们需要将 MessageBox 或 Dialog 的按钮“确定”、“取消”用英文或其他语言显示。在网上查找了很多相关内容,但很多要么很麻烦,要么根本就不能实现所需效果。最后发现还是MSDN最好用。 
    首先是MessageBox中如何将按钮中的文字显示为其他语言。MessageBox要使用 MessageBoxEx才可以,其定义如下:

    int WINAPI MessageBoxEx(
      _In_opt_  HWND hWnd,
      _In_opt_  LPCTSTR lpText,
      _In_opt_  LPCTSTR lpCaption,
      _In_      UINT uType,
      _In_      WORD wLanguageId
    );
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    最后一个参数MSDN上给出的解释是:

    wLanguageId [in] 
    Type: WORD 
    The language for the text displayed in the message box button(s). Specifying a value of zero (0) indicates to display the button text in the default system language. If this parameter is MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), the current language associated with the calling thread is used. 
    To specify a language other than the current language, use the MAKELANGID macro to create this parameter. For more information, see MAKELANGID.

    意思就是我们需要用函数MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),来生成最后一个参数。它的定义为

    WORD MAKELANGID(
      USHORT usPrimaryLanguage,
      USHORT usSubLanguage
    );
    • 1
    • 2
    • 3
    • 4

    微软给我们提供了足够多的语言支持,关于这两个参数可以参见微软提供的Language Identifier Constants and Strings表格。从表格中查找相应的语言的PrimaryLanguage和SubLanguage即可。如英语为:LANG_ENGLISH 和 SUBLANG_ENGLISH_US ,可以写成MAKELANGID(LANG_ENGLISH , UBLANG_ENGLISH_US ); 
    最后举一个例子:

    MessageBoxEx(NULL,L"This is an English MessageBox!",L"Alert",MB_OKCANCEL,MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
    • 1

    MessageBox示例

    下面介绍一下如何修改Dialog中的默认按钮上的文字,这里只介绍系统定义的Dialog,如:CFileDialog。(Customer Dialog 也没有做这些的意义了,因为直接修改按钮的Caption 属性即可)。修改Dialog的默认按钮文字只需要在创建Dialog前加上一句:

    SetThreadUILanguage(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
    • 1

    即可,参数中MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)的使用和上文的使用方法中一样。

  • 相关阅读:
    CopyOnWriteArrayList设计思路与源码分析
    点击页面按钮以excel保存到本地
    上传图片
    关于重复点击的
    去首尾空格还有换行问题//把数字换位大写字母//向后台传输数据
    判断输入的时间与当前的时间(判断时间是今天还是以前的)
    前端的一些小技巧
    git 操作大全
    移动web开发常见问题解决方案
    响应式布局
  • 原文地址:https://www.cnblogs.com/ransn/p/8276296.html
Copyright © 2011-2022 走看看