comparison nt/runemacs.c @ 103641:48d529d3a5a4

bug#1849 - Windows 7 Taskbar Support * w32term.c (w32_initialize): Use GetModuleHandle for library that is already loaded. Set user model ID if supported (bug#1849). * runemacs.c (set_user_model_id): New function. (WinMain): Use it. * emacsclient.c (w32_give_focus): Use GetModuleHandle for library that is already loaded. (w32_set_user_model_id): New function. (main): Use it to associate emacsclient with emacs (bug#1849).
author Jason Rumney <jasonr@gnu.org>
date Tue, 30 Jun 2009 15:48:23 +0000
parents aeceb2460b39
children 7bad97f82eb6
comparison
equal deleted inserted replaced
103640:fd001b102e15 103641:48d529d3a5a4
41 41
42 #include <windows.h> 42 #include <windows.h>
43 #include <string.h> 43 #include <string.h>
44 #include <malloc.h> 44 #include <malloc.h>
45 45
46 static void set_user_model_id ();
47
46 int WINAPI 48 int WINAPI
47 WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow) 49 WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow)
48 { 50 {
49 STARTUPINFO start; 51 STARTUPINFO start;
50 SECURITY_ATTRIBUTES sec_attrs; 52 SECURITY_ATTRIBUTES sec_attrs;
53 DWORD priority_class = NORMAL_PRIORITY_CLASS; 55 DWORD priority_class = NORMAL_PRIORITY_CLASS;
54 DWORD ret_code = 0; 56 DWORD ret_code = 0;
55 char *new_cmdline; 57 char *new_cmdline;
56 char *p; 58 char *p;
57 char modname[MAX_PATH]; 59 char modname[MAX_PATH];
60
61 set_user_model_id ();
58 62
59 if (!GetModuleFileName (NULL, modname, MAX_PATH)) 63 if (!GetModuleFileName (NULL, modname, MAX_PATH))
60 goto error; 64 goto error;
61 if ((p = strrchr (modname, '\\')) == NULL) 65 if ((p = strrchr (modname, '\\')) == NULL)
62 goto error; 66 goto error;
168 error: 172 error:
169 MessageBox (NULL, "Could not start Emacs.", "Error", MB_ICONSTOP); 173 MessageBox (NULL, "Could not start Emacs.", "Error", MB_ICONSTOP);
170 return 1; 174 return 1;
171 } 175 }
172 176
177 void set_user_model_id ()
178 {
179 HMODULE shell;
180 HRESULT (WINAPI * set_user_model) (PCWSTR);
181
182 /* On Windows 7 and later, we need to set the user model ID
183 to associate emacsclient launched files with Emacs frames
184 in the UI. */
185 shell = LoadLibrary ("shell32.dll");
186 if (shell)
187 {
188 set_user_model
189 = (void *) GetProcAddress (shell,
190 "SetCurrentProcessExplicitAppUserModelID");
191
192 /* If the function is defined, then we are running on Windows 7
193 or newer, and the UI uses this to group related windows
194 together. Since emacs, runemacs, emacsclient are related, we
195 want them grouped even though the executables are different,
196 so we need to set a consistent ID between them. */
197 if (set_user_model)
198 set_user_model (L"GNU.Emacs");
199
200 FreeLibrary (shell);
201 }
202 }
203
173 /* arch-tag: 7e02df73-4df7-4aa0-baea-99c6d047a384 204 /* arch-tag: 7e02df73-4df7-4aa0-baea-99c6d047a384
174 (do not change this comment) */ 205 (do not change this comment) */