Be more Windowsy.
authorIain Patterson <me@iain.cx>
Wed, 1 Jan 2014 12:37:07 +0000 (12:37 +0000)
committerIain Patterson <me@iain.cx>
Wed, 1 Jan 2014 14:32:21 +0000 (14:32 +0000)
Now that the GUI is more functional, it should behave more like a real
Windows application.  That means having an icon and modal messageboxes.

event.cpp
event.h
gui.cpp
nssm.cpp

index 4af50a8..a409b11 100644 (file)
--- a/event.cpp
+++ b/event.cpp
@@ -72,7 +72,7 @@ void print_message(FILE *file, unsigned long id, ...) {
 }\r
 \r
 /* Show a GUI dialogue */\r
-int popup_message(unsigned int type, unsigned long id, ...) {\r
+int popup_message(HWND owner, unsigned int type, unsigned long id, ...) {\r
   va_list arg;\r
 \r
   TCHAR *format = message_string(id);\r
@@ -89,7 +89,20 @@ int popup_message(unsigned int type, unsigned long id, ...) {
   }\r
   va_end(arg);\r
 \r
-  int ret = MessageBox(0, blurb, NSSM, type);\r
+  MSGBOXPARAMS params;\r
+  ZeroMemory(&params, sizeof(params));\r
+  params.cbSize = sizeof(params);\r
+  params.hInstance = GetModuleHandle(0);\r
+  params.hwndOwner = owner;\r
+  params.lpszText = blurb;\r
+  params.lpszCaption = NSSM;\r
+  params.dwStyle = type;\r
+  if (type == MB_OK) {\r
+    params.dwStyle |= MB_USERICON;\r
+    params.lpszIcon = MAKEINTRESOURCE(IDI_NSSM);\r
+  }\r
+\r
+  int ret = MessageBoxIndirect(&params);\r
 \r
   LocalFree(format);\r
 \r
diff --git a/event.h b/event.h
index 849a347..d97fc94 100644 (file)
--- a/event.h
+++ b/event.h
@@ -5,6 +5,6 @@ TCHAR *error_string(unsigned long);
 TCHAR *message_string(unsigned long);\r
 void log_event(unsigned short, unsigned long, ...);\r
 void print_message(FILE *, unsigned long, ...);\r
-int popup_message(unsigned int, unsigned long, ...);\r
+int popup_message(HWND, unsigned int, unsigned long, ...);\r
 \r
 #endif\r
diff --git a/gui.cpp b/gui.cpp
index d704304..68ddb57 100644 (file)
--- a/gui.cpp
+++ b/gui.cpp
@@ -27,10 +27,16 @@ int nssm_gui(int resource, nssm_service_t *service) {
   /* Create window */\r
   HWND dlg = dialog(MAKEINTRESOURCE(resource), 0, nssm_dlg, (LPARAM) service);\r
   if (! dlg) {\r
-    popup_message(MB_OK, NSSM_GUI_CREATEDIALOG_FAILED, error_string(GetLastError()));\r
+    popup_message(0, MB_OK, NSSM_GUI_CREATEDIALOG_FAILED, error_string(GetLastError()));\r
     return 1;\r
   }\r
 \r
+  /* Load the icon. */\r
+  HANDLE icon = LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_NSSM), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0);\r
+  if (icon) SendMessage(dlg, WM_SETICON, ICON_SMALL, (LPARAM) icon);\r
+  icon = LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_NSSM), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0);\r
+  if (icon) SendMessage(dlg, WM_SETICON, ICON_BIG, (LPARAM) icon);\r
+\r
   /* Remember what the window is for. */\r
   SetWindowLongPtr(dlg, GWLP_USERDATA, (LONG_PTR) resource);\r
 \r
@@ -129,8 +135,8 @@ int nssm_gui(int resource, nssm_service_t *service) {
     if (! service->rotate_bytes_high) SetDlgItemInt(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW, service->rotate_bytes_low, 0);\r
 \r
     /* Check if advanced settings are in use. */\r
-    if (service->stdout_disposition ^ service->stderr_disposition || service->stdout_disposition & ~CREATE_ALWAYS || service->stderr_disposition & ~CREATE_ALWAYS) popup_message(MB_OK | MB_ICONWARNING, NSSM_GUI_WARN_STDIO);\r
-    if (service->rotate_bytes_high) popup_message(MB_OK | MB_ICONWARNING, NSSM_GUI_WARN_ROTATE_BYTES);\r
+    if (service->stdout_disposition ^ service->stderr_disposition || service->stdout_disposition & ~CREATE_ALWAYS || service->stderr_disposition & ~CREATE_ALWAYS) popup_message(dlg, MB_OK | MB_ICONWARNING, NSSM_GUI_WARN_STDIO);\r
+    if (service->rotate_bytes_high) popup_message(dlg, MB_OK | MB_ICONWARNING, NSSM_GUI_WARN_ROTATE_BYTES);\r
 \r
     /* Environment tab. */\r
     TCHAR *env;\r
@@ -149,14 +155,14 @@ int nssm_gui(int resource, nssm_service_t *service) {
       TCHAR *formatted;\r
       unsigned long newlen;\r
       if (format_environment(env, envlen, &formatted, &newlen)) {\r
-        popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("environment"), _T("nssm_dlg()"));\r
+        popup_message(dlg, MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("environment"), _T("nssm_dlg()"));\r
       }\r
       else {\r
         SetDlgItemText(tablist[NSSM_TAB_ENVIRONMENT], IDC_ENVIRONMENT, formatted);\r
         HeapFree(GetProcessHeap(), 0, formatted);\r
       }\r
     }\r
-    if (service->envlen && service->env_extralen) popup_message(MB_OK | MB_ICONWARNING, NSSM_GUI_WARN_ENVIRONMENT);\r
+    if (service->envlen && service->env_extralen) popup_message(dlg, MB_OK | MB_ICONWARNING, NSSM_GUI_WARN_ENVIRONMENT);\r
   }\r
 \r
   /* Go! */\r
@@ -222,10 +228,10 @@ static inline void set_rotation_enabled(unsigned char enabled) {
   EnableWindow(GetDlgItem(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW), enabled);\r
 }\r
 \r
-static inline void check_io(TCHAR *name, TCHAR *buffer, unsigned long len, unsigned long control) {\r
+static inline void check_io(HWND owner, TCHAR *name, TCHAR *buffer, unsigned long len, unsigned long control) {\r
   if (! SendMessage(GetDlgItem(tablist[NSSM_TAB_IO], control), WM_GETTEXTLENGTH, 0, 0)) return;\r
   if (GetDlgItemText(tablist[NSSM_TAB_IO], control, buffer, (int) len)) return;\r
-  popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_MESSAGE_PATH_TOO_LONG, name);\r
+  popup_message(owner, MB_OK | MB_ICONEXCLAMATION, NSSM_MESSAGE_PATH_TOO_LONG, name);\r
   ZeroMemory(buffer, len * sizeof(TCHAR));\r
 }\r
 \r
@@ -242,7 +248,7 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
 \r
   /* Get service name. */\r
   if (! GetDlgItemText(window, IDC_NAME, service->name, _countof(service->name))) {\r
-    popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_SERVICE_NAME);\r
+    popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_SERVICE_NAME);\r
     cleanup_nssm_service(service);\r
     return 2;\r
   }\r
@@ -250,7 +256,7 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
   /* Get executable name */\r
   if (! service->native) {\r
     if (! GetDlgItemText(tablist[NSSM_TAB_APPLICATION], IDC_PATH, service->exe, _countof(service->exe))) {\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PATH);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PATH);\r
       return 3;\r
     }\r
 \r
@@ -263,7 +269,7 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
     /* Get flags. */\r
     if (SendMessage(GetDlgItem(tablist[NSSM_TAB_APPLICATION], IDC_FLAGS), WM_GETTEXTLENGTH, 0, 0)) {\r
       if (! GetDlgItemText(tablist[NSSM_TAB_APPLICATION], IDC_FLAGS, service->flags, _countof(service->flags))) {\r
-        popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_OPTIONS);\r
+        popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_OPTIONS);\r
         return 4;\r
       }\r
     }\r
@@ -272,14 +278,14 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
   /* Get details. */\r
   if (SendMessage(GetDlgItem(tablist[NSSM_TAB_DETAILS], IDC_DISPLAYNAME), WM_GETTEXTLENGTH, 0, 0)) {\r
     if (! GetDlgItemText(tablist[NSSM_TAB_DETAILS], IDC_DISPLAYNAME, service->displayname, _countof(service->displayname))) {\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_DISPLAYNAME);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_DISPLAYNAME);\r
       return 5;\r
     }\r
   }\r
 \r
   if (SendMessage(GetDlgItem(tablist[NSSM_TAB_DETAILS], IDC_DESCRIPTION), WM_GETTEXTLENGTH, 0, 0)) {\r
     if (! GetDlgItemText(tablist[NSSM_TAB_DETAILS], IDC_DESCRIPTION, service->description, _countof(service->description))) {\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_DESCRIPTION);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_DESCRIPTION);\r
       return 5;\r
     }\r
   }\r
@@ -307,21 +313,21 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
     /* Username. */\r
     service->usernamelen = SendMessage(GetDlgItem(tablist[NSSM_TAB_LOGON], IDC_USERNAME), WM_GETTEXTLENGTH, 0, 0);\r
     if (! service->usernamelen) {\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_USERNAME);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_USERNAME);\r
       return 6;\r
     }\r
     service->usernamelen++;\r
 \r
     service->username = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, service->usernamelen * sizeof(TCHAR));\r
     if (! service->username) {\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("account name"), _T("install()"));\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("account name"), _T("install()"));\r
       return 6;\r
     }\r
     if (! GetDlgItemText(tablist[NSSM_TAB_LOGON], IDC_USERNAME, service->username, (int) service->usernamelen)) {\r
       HeapFree(GetProcessHeap(), 0, service->username);\r
       service->username = 0;\r
       service->usernamelen = 0;\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_USERNAME);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_USERNAME);\r
       return 6;\r
     }\r
 \r
@@ -341,11 +347,11 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
 \r
       if (! orig_service || ! orig_service->username || ! str_equiv(service->username, orig_service->username) || service->passwordlen || passwordlen) {\r
         if (! service->passwordlen) {\r
-          popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PASSWORD);\r
+          popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PASSWORD);\r
           return 6;\r
         }\r
         if (passwordlen != service->passwordlen) {\r
-          popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PASSWORD);\r
+          popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PASSWORD);\r
           return 6;\r
         }\r
         service->passwordlen++;\r
@@ -356,7 +362,7 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
           HeapFree(GetProcessHeap(), 0, service->username);\r
           service->username = 0;\r
           service->usernamelen = 0;\r
-          popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("password confirmation"), _T("install()"));\r
+          popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("password confirmation"), _T("install()"));\r
           return 6;\r
         }\r
 \r
@@ -367,7 +373,7 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
           HeapFree(GetProcessHeap(), 0, service->username);\r
           service->username = 0;\r
           service->usernamelen = 0;\r
-          popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("password"), _T("install()"));\r
+          popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("password"), _T("install()"));\r
           return 6;\r
         }\r
 \r
@@ -381,7 +387,7 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
           HeapFree(GetProcessHeap(), 0, service->username);\r
           service->username = 0;\r
           service->usernamelen = 0;\r
-          popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_PASSWORD);\r
+          popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_PASSWORD);\r
           return 6;\r
         }\r
 \r
@@ -396,13 +402,13 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
           HeapFree(GetProcessHeap(), 0, service->username);\r
           service->username = 0;\r
           service->usernamelen = 0;\r
-          popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_PASSWORD);\r
+          popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_PASSWORD);\r
           return 6;\r
         }\r
 \r
         /* Compare. */\r
         if (_tcsncmp(password, service->password, service->passwordlen)) {\r
-          popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PASSWORD);\r
+          popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PASSWORD);\r
           SecureZeroMemory(password, service->passwordlen);\r
           HeapFree(GetProcessHeap(), 0, password);\r
           SecureZeroMemory(service->password, service->passwordlen);\r
@@ -437,9 +443,9 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
   if (service->default_exit_action == CB_ERR) service->default_exit_action = 0;\r
 \r
   /* Get I/O stuff. */\r
-  check_io(_T("stdin"), service->stdin_path, _countof(service->stdin_path), IDC_STDIN);\r
-  check_io(_T("stdout"), service->stdout_path, _countof(service->stdout_path), IDC_STDOUT);\r
-  check_io(_T("stderr"), service->stderr_path, _countof(service->stderr_path), IDC_STDERR);\r
+  check_io(window, _T("stdin"), service->stdin_path, _countof(service->stdin_path), IDC_STDIN);\r
+  check_io(window, _T("stdout"), service->stdout_path, _countof(service->stdout_path), IDC_STDOUT);\r
+  check_io(window, _T("stderr"), service->stderr_path, _countof(service->stderr_path), IDC_STDERR);\r
 \r
   /* Override stdout and/or stderr. */\r
   if (SendDlgItemMessage(tablist[NSSM_TAB_ROTATION], IDC_TRUNCATE, BM_GETCHECK, 0, 0) & BST_CHECKED) {\r
@@ -459,13 +465,13 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
   if (envlen) {\r
     TCHAR *env = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (envlen + 2) * sizeof(TCHAR));\r
     if (! env) {\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("environment"), _T("install()"));\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("environment"), _T("install()"));\r
       cleanup_nssm_service(service);\r
       return 5;\r
     }\r
 \r
     if (! GetDlgItemText(tablist[NSSM_TAB_ENVIRONMENT], IDC_ENVIRONMENT, env, envlen + 1)) {\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_ENVIRONMENT);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_ENVIRONMENT);\r
       HeapFree(GetProcessHeap(), 0, env);\r
       cleanup_nssm_service(service);\r
       return 5;\r
@@ -475,7 +481,7 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
     unsigned long newlen;\r
     if (unformat_environment(env, envlen, &newenv, &newlen)) {\r
       HeapFree(GetProcessHeap(), 0, env);\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("environment"), _T("install()"));\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("environment"), _T("install()"));\r
       cleanup_nssm_service(service);\r
       return 5;\r
     }\r
@@ -486,7 +492,7 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
 \r
     /* Test the environment is valid. */\r
     if (test_environment(env)) {\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_ENVIRONMENT);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_ENVIRONMENT);\r
       HeapFree(GetProcessHeap(), 0, env);\r
       cleanup_nssm_service(service);\r
       return 5;\r
@@ -518,37 +524,37 @@ int install(HWND window) {
   /* See if it works. */\r
   switch (install_service(service)) {\r
     case 1:\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("service"), _T("install()"));\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("service"), _T("install()"));\r
       cleanup_nssm_service(service);\r
       return 1;\r
 \r
     case 2:\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_MESSAGE_OPEN_SERVICE_MANAGER_FAILED);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_MESSAGE_OPEN_SERVICE_MANAGER_FAILED);\r
       cleanup_nssm_service(service);\r
       return 2;\r
 \r
     case 3:\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_MESSAGE_PATH_TOO_LONG, NSSM);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_MESSAGE_PATH_TOO_LONG, NSSM);\r
       cleanup_nssm_service(service);\r
       return 3;\r
 \r
     case 4:\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_OUT_OF_MEMORY_FOR_IMAGEPATH);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_OUT_OF_MEMORY_FOR_IMAGEPATH);\r
       cleanup_nssm_service(service);\r
       return 4;\r
 \r
     case 5:\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INSTALL_SERVICE_FAILED);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INSTALL_SERVICE_FAILED);\r
       cleanup_nssm_service(service);\r
       return 5;\r
 \r
     case 6:\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_CREATE_PARAMETERS_FAILED);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_CREATE_PARAMETERS_FAILED);\r
       cleanup_nssm_service(service);\r
       return 6;\r
   }\r
 \r
-  popup_message(MB_OK, NSSM_MESSAGE_SERVICE_INSTALLED, service->name);\r
+  popup_message(window, MB_OK, NSSM_MESSAGE_SERVICE_INSTALLED, service->name);\r
   cleanup_nssm_service(service);\r
   return 0;\r
 }\r
@@ -562,13 +568,13 @@ int remove(HWND window) {
   if (service) {\r
     /* Get service name */\r
     if (! GetDlgItemText(window, IDC_NAME, service->name, _countof(service->name))) {\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_SERVICE_NAME);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_SERVICE_NAME);\r
       cleanup_nssm_service(service);\r
       return 2;\r
     }\r
 \r
     /* Confirm */\r
-    if (popup_message(MB_YESNO, NSSM_GUI_ASK_REMOVE_SERVICE, service->name) != IDYES) {\r
+    if (popup_message(window, MB_YESNO, NSSM_GUI_ASK_REMOVE_SERVICE, service->name) != IDYES) {\r
       cleanup_nssm_service(service);\r
       return 0;\r
     }\r
@@ -576,27 +582,27 @@ int remove(HWND window) {
 \r
   switch (remove_service(service)) {\r
     case 1:\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("service"), _T("remove()"));\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("service"), _T("remove()"));\r
       cleanup_nssm_service(service);\r
       return 1;\r
 \r
     case 2:\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_MESSAGE_OPEN_SERVICE_MANAGER_FAILED);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_MESSAGE_OPEN_SERVICE_MANAGER_FAILED);\r
       cleanup_nssm_service(service);\r
       return 2;\r
 \r
     case 3:\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_SERVICE_NOT_INSTALLED);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_SERVICE_NOT_INSTALLED);\r
       return 3;\r
       cleanup_nssm_service(service);\r
 \r
     case 4:\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_REMOVE_SERVICE_FAILED);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_REMOVE_SERVICE_FAILED);\r
       cleanup_nssm_service(service);\r
       return 4;\r
   }\r
 \r
-  popup_message(MB_OK, NSSM_MESSAGE_SERVICE_REMOVED, service->name);\r
+  popup_message(window, MB_OK, NSSM_MESSAGE_SERVICE_REMOVED, service->name);\r
   cleanup_nssm_service(service);\r
   return 0;\r
 }\r
@@ -612,28 +618,28 @@ int edit(HWND window, nssm_service_t *orig_service) {
 \r
   switch (edit_service(service, true)) {\r
     case 1:\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("service"), _T("edit()"));\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("service"), _T("edit()"));\r
       cleanup_nssm_service(service);\r
       return 1;\r
 \r
     case 3:\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_MESSAGE_PATH_TOO_LONG, NSSM);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_MESSAGE_PATH_TOO_LONG, NSSM);\r
       cleanup_nssm_service(service);\r
       return 3;\r
 \r
     case 4:\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_OUT_OF_MEMORY_FOR_IMAGEPATH);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_OUT_OF_MEMORY_FOR_IMAGEPATH);\r
       cleanup_nssm_service(service);\r
       return 4;\r
 \r
     case 5:\r
     case 6:\r
-      popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_EDIT_PARAMETERS_FAILED);\r
+      popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_EDIT_PARAMETERS_FAILED);\r
       cleanup_nssm_service(service);\r
       return 6;\r
   }\r
 \r
-  popup_message(MB_OK, NSSM_MESSAGE_SERVICE_EDITED, service->name);\r
+  popup_message(window, MB_OK, NSSM_MESSAGE_SERVICE_EDITED, service->name);\r
   cleanup_nssm_service(service);\r
   return 0;\r
 }\r
index 7e1e7ce..02ad21f 100644 (file)
--- a/nssm.cpp
+++ b/nssm.cpp
@@ -25,7 +25,7 @@ void strip_basename(TCHAR *buffer) {
 /* How to use me correctly */\r
 int usage(int ret) {\r
   if (GetConsoleWindow()) print_message(stderr, NSSM_MESSAGE_USAGE, NSSM_VERSION, NSSM_DATE);\r
-  else popup_message(MB_OK, NSSM_MESSAGE_USAGE, NSSM_VERSION, NSSM_DATE);\r
+  else popup_message(0, MB_OK, NSSM_MESSAGE_USAGE, NSSM_VERSION, NSSM_DATE);\r
   return(ret);\r
 }\r
 \r