Kaynağa Gözat

Allow to specify title and tray icon for the Windows standalone server

bel 11 yıl önce
ebeveyn
işleme
32cbb48710
3 değiştirilmiş dosya ile 16 ekleme ve 4 silme
  1. 1 0
      RELEASE_NOTES.md
  2. 15 4
      src/main.c
  3. BIN
      test/test.ico

+ 1 - 0
RELEASE_NOTES.md

@@ -5,6 +5,7 @@ Release Notes v1.6 (Under Development)
 Changes
 -------
 
+- Allow to specify title and tray icon for the Windows standalone server (bel)
 - Fix minor memory leaks (bel)
 - Redirect all memory allocation/deallocation through mg functions which may be overwritten (bel)
 - Support Cross-Origin Resource Sharing (CORS) for static files and scripts (bel)

+ 15 - 4
src/main.c

@@ -80,6 +80,7 @@ extern char *_getcwd(char *buf, size_t size);
 static int exit_flag;
 static char server_base_name[40];       /* Set by init_server_name() */
 static char *server_name;               /* Set by init_server_name() */
+static char *icon_name;                 /* Set by init_server_name() */
 static char config_file[PATH_MAX] = ""; /* Set by process_command_line_arguments() */
 static struct mg_context *ctx;          /* Set by start_civetweb() */
 
@@ -222,7 +223,7 @@ static int set_option(char **options, const char *name, const char *value)
     const struct mg_option *default_options = mg_get_valid_options();
 
     for (i = 0; main_config_options[i].name != 0; i++) {
-        if (0==strcmp(name, main_config_options[OPTION_TITLE].name)) {
+        if (0==strcmp(name, main_config_options[i].name)) {
             /* This option is evaluated by main.c, not civetweb.c - just skip it and return OK */
             return 1;
         }
@@ -401,6 +402,12 @@ static void init_server_name(int argc, const char *argv[])
             server_name = (char*)(argv[i+1]);
         }
     }
+    icon_name = 0;
+    for (i=0; i<argc-1; i++) {
+        if ((argv[i][0]=='-') && (0==strcmp(argv[i]+1, main_config_options[OPTION_ICON].name))) {
+            icon_name = (char*)(argv[i+1]);
+        }
+    }
 }
 
 static int log_message(const struct mg_connection *conn, const char *message)
@@ -1077,12 +1084,16 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show)
                         0, 0, 0, 0, NULL, NULL, NULL, NULL);
     ShowWindow(hWnd, SW_HIDE);
 
+    if (icon_name) {
+        hIcon = LoadImage(NULL, icon_name, IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
+    } else {
+        hIcon = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_ICON), IMAGE_ICON, 16, 16, 0);
+    }
+
     TrayIcon.cbSize = sizeof(TrayIcon);
     TrayIcon.uID = ID_ICON;
     TrayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
-    TrayIcon.hIcon = hIcon = LoadImage(GetModuleHandle(NULL),
-                                       MAKEINTRESOURCE(ID_ICON),
-                                       IMAGE_ICON, 16, 16, 0);
+    TrayIcon.hIcon = hIcon;
     TrayIcon.hWnd = hWnd;
     snprintf(TrayIcon.szTip, sizeof(TrayIcon.szTip), "%s", server_name);
     TrayIcon.uCallbackMessage = WM_USER;

BIN
test/test.ico