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)的使用和上文的使用方法中一样。

  • 相关阅读:
    jsp转向
    什么是 XDoclet?
    tomcat中的几点配置说明
    mysql5问题
    POJ 3734 Blocks
    POJ 2409 Let it Bead
    HDU 1171 Big Event in HDU
    POJ 3046 Ant Counting
    HDU 2082 找单词
    POJ 1286 Necklace of Beads
  • 原文地址:https://www.cnblogs.com/ransn/p/8276296.html
Copyright © 2011-2022 走看看