小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

MessageBox 按鈕顯示英文或其他語言

 藍色飄零 2015-05-05
由于特殊原因我們需要將 MessageBox 或 Dialog 的按鈕“確定”、“取消”用英文或其他語言顯示。在網上查找了很多相關內容,但很多要么很麻煩,要么根本就不能實現所需效果。最后發(fā)現還是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的默認按鈕文字只需要在創(chuàng)建Dialog前加上一句:

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

即可,參數中MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)的使用和上文的使用方法中一樣。

    本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯系方式、誘導購買等信息,謹防詐騙。如發(fā)現有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多