From 82eb645a5e0537809fe01a1cb579e81c752c6cd2 Mon Sep 17 00:00:00 2001 From: Heiko Hund Date: Fri, 20 Jul 2012 17:44:48 +0200 Subject: [PATCH] localize buttons in message boxes when possible --- localization.c | 22 ++++++++++++++++++++-- localization.h | 1 + main.c | 36 +++++++++++++++--------------------- options.c | 2 +- passphrase.c | 10 ++++------ tray.c | 3 +-- 6 files changed, 42 insertions(+), 32 deletions(-) diff --git a/localization.c b/localization.c index 131d815..1fffac2 100644 --- a/localization.c +++ b/localization.c @@ -40,7 +40,7 @@ extern options_t o; -static const LANGID fallbackLangId = MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL); +static const LANGID fallbackLangId = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT); static LANGID gui_language; static HRSRC @@ -176,12 +176,30 @@ LoadLocalizedStringBuf(PTSTR buffer, int bufferSize, const UINT stringId, ...) } +static int +__ShowLocalizedMsgEx(const UINT type, LPCTSTR caption, const UINT stringId, va_list args) +{ + return MessageBoxEx(NULL, __LoadLocalizedString(stringId, args), caption, + type | MB_SETFOREGROUND, GetGUILanguage()); +} + + +int +ShowLocalizedMsgEx(const UINT type, LPCTSTR caption, const UINT stringId, ...) +{ + va_list args; + va_start(args, stringId); + return __ShowLocalizedMsgEx(type, caption, stringId, args); + va_end(args); +} + + void ShowLocalizedMsg(const UINT stringId, ...) { va_list args; va_start(args, stringId); - MessageBox(NULL, __LoadLocalizedString(stringId, args), _T(PACKAGE_NAME), MB_OK | MB_SETFOREGROUND); + __ShowLocalizedMsgEx(MB_OK, _T(PACKAGE_NAME), stringId, args); va_end(args); } diff --git a/localization.h b/localization.h index 714ff41..72b7e9d 100644 --- a/localization.h +++ b/localization.h @@ -25,6 +25,7 @@ PTSTR LoadLocalizedString(const UINT, ...); int LoadLocalizedStringBuf(PTSTR, const int, const UINT, ...); void ShowLocalizedMsg(const UINT, ...); +int ShowLocalizedMsgEx(const UINT, LPCTSTR, const UINT, ...); HICON LoadLocalizedIcon(const UINT); LPCDLGTEMPLATE LocalizedDialogResource(const UINT); INT_PTR LocalizedDialogBoxParam(const UINT, DLGPROC, const LPARAM); diff --git a/main.c b/main.c index f5cdcad..07375b6 100644 --- a/main.c +++ b/main.c @@ -471,32 +471,26 @@ ShowSettingsDialog() } -void CloseApplication(HWND hwnd) +void +CloseApplication(HWND hwnd) { - int i, ask_exit=0; + int i; - if (o.service_state == service_connected) + if (o.service_state == service_connected + && ShowLocalizedMsgEx(MB_YESNO, _T("Exit OpenVPN"), IDS_NFO_SERVICE_ACTIVE_EXIT) == IDNO) + return; + + for (i = 0; i < o.num_configs; i++) { - if (MessageBox(NULL, LoadLocalizedString(IDS_NFO_SERVICE_ACTIVE_EXIT), _T("Exit OpenVPN"), MB_YESNO) == IDNO) - { - return; - } + if (o.conn[i].state == disconnected) + continue; + + /* Ask for confirmation if still connected */ + if (ShowLocalizedMsgEx(MB_YESNO, _T("Exit OpenVPN"), IDS_NFO_ACTIVE_CONN_EXIT) == IDNO) + return; } - for (i=0; i < o.num_configs; i++) { - if (o.conn[i].state != disconnected) { - ask_exit=1; - break; - } - } - if (ask_exit) { - /* aks for confirmation */ - if (MessageBox(NULL, LoadLocalizedString(IDS_NFO_ACTIVE_CONN_EXIT), _T("Exit OpenVPN"), MB_YESNO) == IDNO) - { - return; - } - } - DestroyWindow(hwnd); + DestroyWindow(hwnd); } #ifdef DEBUG diff --git a/options.c b/options.c index a2f574d..59ab408 100644 --- a/options.c +++ b/options.c @@ -46,7 +46,7 @@ add_option(options_t *options, int i, TCHAR **p) { TCHAR caption[200]; LoadLocalizedStringBuf(caption, _countof(caption), IDS_NFO_USAGECAPTION); - MessageBox(NULL, LoadLocalizedString(IDS_NFO_USAGE), caption, MB_OK); + ShowLocalizedMsgEx(MB_OK, caption, IDS_NFO_USAGE); exit(0); } else if (streq(p[0], _T("connect")) && p[1]) diff --git a/passphrase.c b/passphrase.c index 03ca57b..d11b645 100644 --- a/passphrase.c +++ b/passphrase.c @@ -377,12 +377,10 @@ ChangePassphraseDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM break; } - /* Check if the new password is empty. */ - if (NewPasswordLengh(hwndDlg) == 0) - { - if (MessageBox(NULL, LoadLocalizedString(IDS_NFO_EMPTY_PWD), _T(PACKAGE_NAME), MB_YESNO) != IDYES) - break; - } + /* Confirm if the new password is empty. */ + if (NewPasswordLengh(hwndDlg) == 0 + && ShowLocalizedMsgEx(MB_YESNO, _T(PACKAGE_NAME), IDS_NFO_EMPTY_PWD) == IDNO) + break; GetDlgItemText(hwndDlg, ID_TXT_KEYFILE, keyfile, _countof(keyfile) - 1); keyfile_format=GetDlgItemInt(hwndDlg, ID_TXT_KEYFORMAT, &Translated, FALSE); diff --git a/tray.c b/tray.c index 3799097..39be3dd 100644 --- a/tray.c +++ b/tray.c @@ -197,8 +197,7 @@ OnNotifyTray(LPARAM lParam) MyStartService(); } else if (o.service_state == service_connected - && MessageBox(NULL, LoadLocalizedString(IDS_MENU_ASK_STOP_SERVICE), - _T(PACKAGE_NAME), MB_YESNO | MB_SETFOREGROUND) == IDYES) { + && ShowLocalizedMsgEx(MB_YESNO, _T(PACKAGE_NAME), IDS_MENU_ASK_STOP_SERVICE) == IDYES) { MyStopService(); } }