diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-09-16 04:34:39 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-09-16 04:34:39 +0300 |
commit | c61e0019288a32da5f86c4c3d17038b082aba9c0 (patch) | |
tree | db790a5a5157c9311dd2fe85446f0e4027d2061a /src | |
parent | refactoring (diff) | |
download | privilege-check-c61e0019288a32da5f86c4c3d17038b082aba9c0.tar.gz privilege-check-c61e0019288a32da5f86c4c3d17038b082aba9c0.zip |
move more strings to resources
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 11 | ||||
-rw-r--r-- | src/main.rc | 12 | ||||
-rw-r--r-- | src/resource.hpp | 31 | ||||
-rw-r--r-- | src/resource_ids.h | 16 |
4 files changed, 62 insertions, 8 deletions
diff --git a/src/main.cpp b/src/main.cpp index 2045ef6..c2ffb21 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include "error.hpp" #include "os.hpp" #include "process.hpp" +#include "resource.hpp" #include "resource_ids.h" #include "sid.hpp" #include "token.hpp" @@ -108,6 +109,14 @@ BOOL on_init_dialog(HWND wnd, HWND, LPARAM) return TRUE; } +void report_already_elevated(HWND wnd) +{ + MessageBoxW(wnd, + resource::load_string(IDS_ALREADY_ELEVATED).c_str(), + resource::load_string(IDS_ELEVATION_CAPTION).c_str(), + MB_OK); +} + void on_button_elevate_click(HWND wnd) { bool as_admin = false; @@ -124,7 +133,7 @@ void on_button_elevate_click(HWND wnd) if (as_admin) { - MessageBoxW(wnd, L"Already elevated!", L"Elevation", MB_OK); + report_already_elevated(wnd); return; } diff --git a/src/main.rc b/src/main.rc index 70c04e5..28cb4f2 100644 --- a/src/main.rc +++ b/src/main.rc @@ -95,6 +95,18 @@ END #endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// +// +// String Table +// + +STRINGTABLE +BEGIN + IDS_ELEVATION_CAPTION "Privilege test" + IDS_ALREADY_ELEVATED "Already elevated." +END + #endif // English (United States) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/resource.hpp b/src/resource.hpp new file mode 100644 index 0000000..602541f --- /dev/null +++ b/src/resource.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include "error.hpp" + +#include <cstddef> + +#include <string> + +namespace resource +{ + HMODULE load_exe_module() + { + const auto module = GetModuleHandle(NULL); + if (module == NULL) + error::raise("GetModuleHandle"); + return module; + } + + std::wstring load_string(unsigned int id) + { + wchar_t* s = nullptr; + + const auto ret = LoadStringW( + load_exe_module(), id, reinterpret_cast<wchar_t*>(&s), 0); + + if (ret <= 0) + error::raise("LoadStringW"); + + return {s, static_cast<std::size_t>(ret)}; + } +} diff --git a/src/resource_ids.h b/src/resource_ids.h index 4c6d90f..8c12cf8 100644 --- a/src/resource_ids.h +++ b/src/resource_ids.h @@ -1,21 +1,23 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by resource.rc +// Used by main.rc // #define IDD_MAINDIALOG 100 +#define IDS_ELEVATION_CAPTION 2000 +#define IDS_ALREADY_ELEVATED 2001 #define IDC_BUTTON_ELEVATE 1000 -#define IDC_ADMINISTRATOR 1001 -#define IDC_RUN_AS_ADMINISTRATOR 1002 -#define IDC_ELEVATED 1003 -#define IDC_INTEGRITY_LEVEL 1004 +#define IDC_ADMINISTRATOR 1001 +#define IDC_RUN_AS_ADMINISTRATOR 1002 +#define IDC_ELEVATED 1003 +#define IDC_INTEGRITY_LEVEL 1004 #define IDC_STATIC -1 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 129 +#define _APS_NEXT_RESOURCE_VALUE 130 #define _APS_NEXT_COMMAND_VALUE 32771 #define _APS_NEXT_CONTROL_VALUE 1005 #define _APS_NEXT_SYMED_VALUE 110 |