X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/26e06f4464c58704889bdc536edc25b73e8c0179..1259009aa17da6dc038afff96963f6d9bbd3b8e1:/nt/runemacs.c diff --git a/nt/runemacs.c b/nt/runemacs.c index 440fd8d95b..dbb18bcd82 100644 --- a/nt/runemacs.c +++ b/nt/runemacs.c @@ -1,5 +1,6 @@ -/* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 - Free Software Foundation, Inc. +/* runemacs --- Simple program to start Emacs with its console window hidden. + +Copyright (C) 2001-2012 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -43,6 +44,9 @@ along with GNU Emacs. If not, see . */ #include #include +static void set_user_model_id (void); +static int ensure_unicows_dll (void); + int WINAPI WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow) { @@ -56,6 +60,11 @@ WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow) char *p; char modname[MAX_PATH]; + if (!ensure_unicows_dll ()) + goto error; + + set_user_model_id (); + if (!GetModuleFileName (NULL, modname, MAX_PATH)) goto error; if ((p = strrchr (modname, '\\')) == NULL) @@ -102,7 +111,7 @@ WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow) #endif /* Append original arguments if any; first look for arguments we - recognise (-wait, -high, and -low), and apply them ourselves. */ + recognize (-wait, -high, and -low), and apply them ourselves. */ while (cmdline[0] == '-' || cmdline[0] == '/') { if (strncmp (cmdline+1, "wait", 4) == 0) @@ -170,5 +179,71 @@ error: return 1; } -/* arch-tag: 7e02df73-4df7-4aa0-baea-99c6d047a384 - (do not change this comment) */ +void +set_user_model_id (void) +{ + HMODULE shell; + HRESULT (WINAPI * set_user_model) (wchar_t * id); + + /* On Windows 7 and later, we need to set the user model ID + to associate emacsclient launched files with Emacs frames + in the UI. */ + shell = LoadLibrary ("shell32.dll"); + if (shell) + { + set_user_model + = (void *) GetProcAddress (shell, + "SetCurrentProcessExplicitAppUserModelID"); + + /* If the function is defined, then we are running on Windows 7 + or newer, and the UI uses this to group related windows + together. Since emacs, runemacs, emacsclient are related, we + want them grouped even though the executables are different, + so we need to set a consistent ID between them. */ + if (set_user_model) + set_user_model (L"GNU.Emacs"); + + FreeLibrary (shell); + } +} + +static int +ensure_unicows_dll (void) +{ + OSVERSIONINFO os_ver; + HMODULE h; + + ZeroMemory (&os_ver, sizeof (OSVERSIONINFO)); + os_ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); + if (!GetVersionEx (&os_ver)) + return 0; + + if (os_ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) + { + h = LoadLibrary ("Unicows.dll"); + if (!h) + { + int button; + + button = MessageBox (NULL, + "Emacs cannot load the UNICOWS.DLL library.\n" + "This library is essential for using Emacs\n" + "on this system. You need to install it.\n\n" + "However, you can still use Emacs by invoking\n" + "it with the '-nw' command-line option.\n\n" + "Emacs will exit when you click OK.", + "Emacs cannot load UNICOWS.DLL", + MB_ICONERROR | MB_TASKMODAL + | MB_SETFOREGROUND | MB_OK); + switch (button) + { + case IDOK: + default: + return 0; + } + } + FreeLibrary (h); + return 1; + } + return 1; +}