aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-09-15 20:32:55 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-09-15 20:32:55 +0300
commitc238b5afc88ead55aca680931d2b847bf689b625 (patch)
treeddc422890a73e38df4376d52f3ccf6d60d00084b
parentget rid of accidental UTF-16 (diff)
downloadprivilege-check-c238b5afc88ead55aca680931d2b847bf689b625.tar.gz
privilege-check-c238b5afc88ead55aca680931d2b847bf689b625.zip
refactoring
Diffstat (limited to '')
-rw-r--r--main.cpp88
1 files changed, 55 insertions, 33 deletions
diff --git a/main.cpp b/main.cpp
index 322626c..2d2ba1a 100644
--- a/main.cpp
+++ b/main.cpp
@@ -102,43 +102,47 @@ BOOL on_init_dialog(HWND wnd, HWND, LPARAM)
return TRUE;
}
-void on_command(HWND wnd, int id, HWND, unsigned int)
+void on_button_elevate_click(HWND wnd)
{
- switch (id)
+ bool as_admin = false;
+
+ try
{
- case IDC_BUTTON_ELEVATE:
- {
- bool as_admin = false;
- try
- {
- as_admin = is_run_as_administrator();
- }
- catch (const Error& e)
- {
- error::report(e);
- break;
- }
+ as_admin = is_run_as_administrator();
+ }
+ catch (const Error& e)
+ {
+ error::report(e);
+ return;
+ }
- if (as_admin)
- {
- MessageBoxW(wnd, L"Already elevated!", L"Elevation", MB_OK);
- break;
- }
+ if (as_admin)
+ {
+ MessageBoxW(wnd, L"Already elevated!", L"Elevation", MB_OK);
+ return;
+ }
- try
- {
- process::runas(process::get_executable_path());
- }
- catch (const Error& e)
- {
- if (error::get_code(e) != ERROR_CANCELLED)
- error::report(e);
- break;
- }
+ try
+ {
+ process::runas(process::get_executable_path());
+ }
+ catch (const Error& e)
+ {
+ if (error::get_code(e) != ERROR_CANCELLED)
+ error::report(e);
+ return;
+ }
- EndDialog(wnd, 1);
+ EndDialog(wnd, 1);
+}
+
+void on_command(HWND wnd, int id, HWND, unsigned int)
+{
+ switch (id)
+ {
+ case IDC_BUTTON_ELEVATE:
+ on_button_elevate_click(wnd);
break;
- }
case IDOK:
case IDCANCEL:
@@ -175,9 +179,27 @@ int APIENTRY wWinMain(
wchar_t*,
int)
{
- return static_cast<int>(DialogBox(
+ const auto ret = DialogBoxW(
instance,
MAKEINTRESOURCE(IDD_MAINDIALOG),
NULL,
- dialog_main));
+ dialog_main);
+
+ switch (ret)
+ {
+ case -1:
+ try
+ {
+ error::raise("DialogBoxW");
+ }
+ catch (const Error& e)
+ {
+ error::report(e);
+ return 1;
+ }
+ break;
+
+ default:
+ return static_cast<int>(ret);
+ }
}