localize buttons in message boxes when possible

pull/1/head
Heiko Hund 2012-07-20 17:44:48 +02:00
parent beead0e1a4
commit 82eb645a5e
6 changed files with 42 additions and 32 deletions

View File

@ -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);
}

View File

@ -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);

36
main.c
View File

@ -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

View File

@ -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])

View File

@ -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);

3
tray.c
View File

@ -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();
}
}