Getting strings with VerQueryValue32W was broken. Complete
[wine/multimedia.git] / programs / progman / main.c
blob6f0e985e5ae1361704e92e49dcc1bffacac8d240
1 /*
2 * Program Manager
4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
5 */
7 #include <stdio.h>
8 #include "windows.h"
9 #include "license.h"
10 #include "progman.h"
11 #ifdef WINELIB
12 #include "resource.h"
13 #include "options.h"
14 #include "shell.h"
15 void LIBWINE_Register_accel();
16 void LIBWINE_Register_De();
17 void LIBWINE_Register_En();
18 void LIBWINE_Register_Fi();
19 void LIBWINE_Register_Fr();
20 void LIBWINE_Register_It();
21 void LIBWINE_Register_Ko();
22 void LIBWINE_Register_Hu();
23 #endif
25 GLOBALS Globals;
27 static VOID MAIN_CreateGroups(void);
28 static VOID MAIN_MenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
29 static ATOM MAIN_RegisterMainWinClass(void);
30 static VOID MAIN_CreateMainWindow(void);
31 static VOID MAIN_CreateMDIWindow(void);
32 static VOID MAIN_AutoStart(void);
34 #define BUFFER_SIZE 1000
36 /***********************************************************************
38 * WinMain
41 int PASCAL WinMain (HANDLE hInstance, HANDLE prev, LPSTR cmdline, int show)
43 MSG msg;
45 #if defined(WINELIB) && !defined(HAVE_WINE_CONSTRUCTOR)
46 /* Register resources */
47 LIBWINE_Register_accel();
48 LIBWINE_Register_De();
49 LIBWINE_Register_En();
50 LIBWINE_Register_Fi();
51 LIBWINE_Register_Fr();
52 LIBWINE_Register_It();
53 LIBWINE_Register_Ko();
54 LIBWINE_Register_Hu();
55 #endif
57 #ifndef WINELIB
58 Globals.lpszIniFile = "progman.ini";
59 Globals.lpszIcoFile = "progman.ico";
60 #else /* Configuration in `wine.ini' */
62 CHAR buffer[MAX_PATHNAME_LEN], *p;
64 /* Redirect `progman.ini' */
65 PROFILE_GetWineIniString("progman", "progman.ini", "progman.ini",
66 buffer, sizeof(buffer));
67 Globals.lpszIniFile = p = LocalLock(LocalAlloc(LMEM_FIXED, lstrlen(buffer)));
68 hmemcpy(p, buffer, 1 + lstrlen(buffer));
70 /* Redirect `progman.ico' */
71 PROFILE_GetWineIniString("progman", "progman.ico", "progman.ico",
72 buffer, sizeof(buffer));
73 Globals.lpszIcoFile = p = LocalLock(LocalAlloc(LMEM_FIXED, lstrlen(buffer)));
74 hmemcpy(p, buffer, 1 + lstrlen(buffer));
76 #endif
78 /* Select Language */
79 #ifdef WINELIB
80 Globals.lpszLanguage = Languages[Options.language].name;
81 #else
82 Globals.lpszLanguage = "En";
83 #endif
85 Globals.hInstance = hInstance;
86 Globals.hGroups = 0;
87 Globals.hActiveGroup = 0;
89 /* Read Options from `progman.ini' */
90 Globals.bAutoArrange =
91 GetPrivateProfileInt("Settings", "AutoArrange", 0, Globals.lpszIniFile);
92 Globals.bMinOnRun =
93 GetPrivateProfileInt("Settings", "MinOnRun", 0, Globals.lpszIniFile);
94 Globals.bSaveSettings =
95 GetPrivateProfileInt("Settings", "SaveSettings", 0, Globals.lpszIniFile);
97 /* Load default icons */
98 Globals.hMainIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
99 Globals.hGroupIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
100 Globals.hDefaultIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
101 if (!Globals.hMainIcon) Globals.hMainIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
102 if (!Globals.hGroupIcon) Globals.hGroupIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
103 if (!Globals.hDefaultIcon) Globals.hDefaultIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
105 /* Register classes */
106 if (!prev)
108 if (!MAIN_RegisterMainWinClass()) return(FALSE);
109 if (!GROUP_RegisterGroupWinClass()) return(FALSE);
110 if (!PROGRAM_RegisterProgramWinClass()) return(FALSE);
113 /* Create main window */
114 MAIN_CreateMainWindow();
115 Globals.hAccel = LoadAccelerators(Globals.hInstance, STRING_ACCEL);
117 /* Setup menu, stringtable and resourcenames */
118 STRING_SelectLanguageByName(Globals.lpszLanguage);
120 MAIN_CreateMDIWindow();
122 /* Initialize groups */
123 MAIN_CreateGroups();
125 /* Start initial applications */
126 MAIN_AutoStart();
128 /* Message loop */
129 while (GetMessage (&msg, 0, 0, 0))
130 if (!TranslateAccelerator(Globals.hMainWnd, Globals.hAccel, &msg))
132 TranslateMessage (&msg);
133 DispatchMessage (&msg);
135 return 0;
138 /***********************************************************************
140 * MAIN_CreateGroups
143 static VOID MAIN_CreateGroups()
145 CHAR buffer[BUFFER_SIZE];
146 CHAR szPath[MAX_PATHNAME_LEN];
147 CHAR key[20], *ptr;
149 /* Initialize groups according the `Order' entry of `progman.ini' */
150 GetPrivateProfileString("Settings", "Order", "", buffer, sizeof(buffer), Globals.lpszIniFile);
151 ptr = buffer;
152 while (ptr < buffer + sizeof(buffer))
154 int num, skip, ret;
155 ret = sscanf(ptr, "%d%n", &num, &skip);
156 if (ret == 0)
157 MAIN_MessageBoxIDS_s(IDS_FILE_READ_ERROR_s, Globals.lpszIniFile, IDS_ERROR, MB_OK);
158 if (ret != 1) break;
160 sprintf(key, "Group%d", num);
161 GetPrivateProfileString("Groups", key, "", szPath,
162 sizeof(szPath), Globals.lpszIniFile);
163 if (!szPath[0]) continue;
165 GRPFILE_ReadGroupFile(szPath);
167 ptr += skip;
169 /* FIXME initialize other groups, not enumerated by `Order' */
172 /***********************************************************************
174 * MAIN_AutoStart
177 VOID MAIN_AutoStart()
179 CHAR buffer[BUFFER_SIZE];
180 HLOCAL hGroup, hProgram;
182 GetPrivateProfileString("Settings", "AutoStart", "Autostart", buffer,
183 sizeof(buffer), Globals.lpszIniFile);
185 for (hGroup = GROUP_FirstGroup(); hGroup; hGroup = GROUP_NextGroup(hGroup))
186 if (!lstrcmp(buffer, GROUP_GroupName(hGroup)))
187 for (hProgram = PROGRAM_FirstProgram(hGroup); hProgram;
188 hProgram = PROGRAM_NextProgram(hProgram))
189 PROGRAM_ExecuteProgram(hProgram);
192 /***********************************************************************
194 * MAIN_MainWndProc
197 static LRESULT MAIN_MainWndProc (HWND hWnd, UINT msg,
198 WPARAM wParam, LPARAM lParam)
200 #if 0
201 printf("M %4.4x %4.4x\n", msg, wParam);
202 #endif
203 switch (msg)
205 case WM_INITMENU:
206 CheckMenuItem(Globals.hOptionMenu, PM_AUTO_ARRANGE,
207 MF_BYCOMMAND | (Globals.bAutoArrange ? MF_CHECKED : MF_UNCHECKED));
208 CheckMenuItem(Globals.hOptionMenu, PM_MIN_ON_RUN,
209 MF_BYCOMMAND | (Globals.bMinOnRun ? MF_CHECKED : MF_UNCHECKED));
210 CheckMenuItem(Globals.hOptionMenu, PM_SAVE_SETTINGS,
211 MF_BYCOMMAND | (Globals.bSaveSettings ? MF_CHECKED : MF_UNCHECKED));
212 break;
214 case WM_COMMAND:
215 if (wParam < PM_FIRST_CHILD)
216 MAIN_MenuCommand(hWnd, wParam, lParam);
217 break;
219 case WM_DESTROY:
220 PostQuitMessage (0);
221 break;
223 return(DefFrameProc(hWnd, Globals.hMDIWnd, msg, wParam, lParam));
226 /***********************************************************************
228 * MAIN_MenuCommand
231 static VOID MAIN_MenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
233 HLOCAL hActiveGroup = GROUP_ActiveGroup();
234 HLOCAL hActiveProgram = PROGRAM_ActiveProgram(hActiveGroup);
235 HWND hActiveGroupWnd = GROUP_GroupWnd(hActiveGroup);
237 switch(wParam)
239 /* Menu File */
240 case PM_NEW:
241 switch (DIALOG_New((hActiveGroupWnd && !IsIconic(hActiveGroupWnd)) ?
242 PM_NEW_PROGRAM : PM_NEW_GROUP))
244 case PM_NEW_PROGRAM:
245 if (hActiveGroup) PROGRAM_NewProgram(hActiveGroup);
246 break;
248 case PM_NEW_GROUP:
249 GROUP_NewGroup();
250 break;
252 break;
254 case PM_OPEN:
255 if (hActiveProgram)
256 PROGRAM_ExecuteProgram(hActiveProgram);
257 else if (hActiveGroupWnd)
258 OpenIcon(hActiveGroupWnd);
259 break;
261 case PM_MOVE:
262 case PM_COPY:
263 if (hActiveProgram)
264 PROGRAM_CopyMoveProgram(hActiveProgram, wParam == PM_MOVE);
265 break;
267 case PM_DELETE:
268 if (hActiveProgram)
270 if (DIALOG_Delete(IDS_DELETE_PROGRAM_s, PROGRAM_ProgramName(hActiveProgram)))
271 PROGRAM_DeleteProgram(hActiveProgram, TRUE);
273 else if (hActiveGroup)
275 if (DIALOG_Delete(IDS_DELETE_GROUP_s, GROUP_GroupName(hActiveGroup)))
276 GROUP_DeleteGroup(hActiveGroup);
278 break;
280 case PM_ATTRIBUTES:
281 if (hActiveProgram)
282 PROGRAM_ModifyProgram(hActiveProgram);
283 else if (hActiveGroup)
284 GROUP_ModifyGroup(hActiveGroup);
285 break;
287 case PM_EXECUTE:
288 DIALOG_Execute();
289 break;
291 case PM_EXIT:
292 PostQuitMessage(0);
293 break;
295 /* Menu Options */
296 case PM_AUTO_ARRANGE:
297 Globals.bAutoArrange = !Globals.bAutoArrange;
298 CheckMenuItem(Globals.hOptionMenu, PM_AUTO_ARRANGE,
299 MF_BYCOMMAND | (Globals.bAutoArrange ?
300 MF_CHECKED : MF_UNCHECKED));
301 WritePrivateProfileString("Settings", "AutoArrange",
302 Globals.bAutoArrange ? "1" : "0",
303 Globals.lpszIniFile);
304 WriteOutProfiles();
305 break;
307 case PM_MIN_ON_RUN:
308 Globals.bMinOnRun = !Globals.bMinOnRun;
309 CheckMenuItem(Globals.hOptionMenu, PM_MIN_ON_RUN,
310 MF_BYCOMMAND | (Globals.bMinOnRun ?
311 MF_CHECKED : MF_UNCHECKED));
312 WritePrivateProfileString("Settings", "MinOnRun",
313 Globals.bMinOnRun ? "1" : "0",
314 Globals.lpszIniFile);
315 WriteOutProfiles();
316 break;
318 case PM_SAVE_SETTINGS:
319 Globals.bSaveSettings = !Globals.bSaveSettings;
320 CheckMenuItem(Globals.hOptionMenu, PM_SAVE_SETTINGS,
321 MF_BYCOMMAND | (Globals.bSaveSettings ?
322 MF_CHECKED : MF_UNCHECKED));
323 WritePrivateProfileString("Settings", "SaveSettings",
324 Globals.bSaveSettings ? "1" : "0",
325 Globals.lpszIniFile);
326 WriteOutProfiles();
327 break;
329 /* Menu Windows */
330 case PM_ARRANGE:
331 if (hActiveGroupWnd && !IsIconic(hActiveGroupWnd))
332 ArrangeIconicWindows(hActiveGroupWnd);
333 else
334 SendMessage(Globals.hMDIWnd, WM_MDIICONARRANGE, 0, 0);
335 break;
337 /* Menu Help */
338 case PM_CONTENTS:
339 if (!WinHelp(Globals.hMainWnd, "progman.hlp", HELP_INDEX, 0))
340 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR, IDS_ERROR, MB_OK);
341 break;
343 case PM_HELPONHELP:
344 if (!WinHelp(Globals.hMainWnd, "progman.hlp", HELP_HELPONHELP, 0))
345 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR, IDS_ERROR, MB_OK);
346 break;
348 case PM_TUTORIAL:
349 WinExec("wintutor.exe", SW_SHOWNORMAL);
350 break;
352 case PM_LICENSE:
353 WineLicense(Globals.hMainWnd, Globals.lpszLanguage);
354 break;
356 case PM_NO_WARRANTY:
357 WineWarranty(Globals.hMainWnd, Globals.lpszLanguage);
358 break;
360 case PM_ABOUT_WINE:
361 ShellAbout(hWnd, "WINE", "Program Manager", 0);
362 break;
364 default:
365 if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
366 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
367 else
368 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED, IDS_ERROR, MB_OK);
369 break;
373 /***********************************************************************
375 * MAIN_RegisterMainWinClass
378 static ATOM MAIN_RegisterMainWinClass()
380 WNDCLASS class;
382 class.style = CS_HREDRAW | CS_VREDRAW;
383 class.lpfnWndProc = MAIN_MainWndProc;
384 class.cbClsExtra = 0;
385 class.cbWndExtra = 0;
386 class.hInstance = Globals.hInstance;
387 class.hIcon = Globals.hMainIcon;
388 class.hCursor = LoadCursor (0, IDC_ARROW);
389 class.hbrBackground = GetStockObject (NULL_BRUSH);
390 class.lpszMenuName = 0;
391 class.lpszClassName = STRING_MAIN_WIN_CLASS_NAME;
393 return RegisterClass(&class);
396 /***********************************************************************
398 * MAIN_CreateMainWindow
401 static VOID MAIN_CreateMainWindow()
403 INT left , top, right, bottom, width, height, show;
404 CHAR buffer[100];
406 Globals.hMDIWnd = 0;
407 Globals.hMainMenu = 0;
409 /* Get the geometry of the main window */
410 GetPrivateProfileString("Settings", "Window", "",
411 buffer, sizeof(buffer), Globals.lpszIniFile);
412 if (5 == sscanf(buffer, "%d %d %d %d %d", &left, &top, &right, &bottom, &show))
414 width = right - left;
415 height = bottom - top;
417 else
419 left = top = width = height = CW_USEDEFAULT;
420 show = SW_SHOWNORMAL;
423 /* Create main Window */
424 Globals.hMainWnd =
425 CreateWindow (STRING_MAIN_WIN_CLASS_NAME, "",
426 WS_OVERLAPPEDWINDOW, left, top, width, height,
427 0, 0, Globals.hInstance, 0);
429 ShowWindow (Globals.hMainWnd, show);
430 UpdateWindow (Globals.hMainWnd);
433 /***********************************************************************
435 * MAIN_CreateMDIWindow
438 static VOID MAIN_CreateMDIWindow()
440 CLIENTCREATESTRUCT ccs;
441 RECT rect;
443 /* Get the geometry of the MDI window */
444 GetClientRect(Globals.hMainWnd, &rect);
446 ccs.hWindowMenu = Globals.hWindowsMenu;
447 ccs.idFirstChild = PM_FIRST_CHILD;
449 /* Create MDI Window */
450 Globals.hMDIWnd =
451 CreateWindow (STRING_MDI_WIN_CLASS_NAME, "",
452 WS_CHILD, rect.left, rect.top,
453 rect.right - rect.left, rect.bottom - rect.top,
454 Globals.hMainWnd, 0,
455 Globals.hInstance, &ccs);
457 ShowWindow (Globals.hMDIWnd, SW_SHOW);
458 UpdateWindow (Globals.hMDIWnd);
461 /**********************************************************************/
462 /***********************************************************************
464 * MAIN_MessageBoxIDS
466 INT MAIN_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
468 CHAR text[MAX_STRING_LEN];
469 CHAR title[MAX_STRING_LEN];
471 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
472 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
474 return(MessageBox(Globals.hMainWnd, text, title, type));
477 /***********************************************************************
479 * MAIN_MessageBoxIDS_s
481 INT MAIN_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
483 CHAR text[MAX_STRING_LEN];
484 CHAR title[MAX_STRING_LEN];
485 CHAR newtext[MAX_STRING_LEN + MAX_PATHNAME_LEN];
487 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
488 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
489 wsprintf(newtext, text, str);
491 return(MessageBox(Globals.hMainWnd, newtext, title, type));
494 /***********************************************************************
496 * MAIN_ReplaceString
499 VOID MAIN_ReplaceString(HLOCAL *handle, LPSTR replace)
501 HLOCAL newhandle = LocalAlloc(LMEM_FIXED, strlen(replace) + 1);
502 if (newhandle)
504 LPSTR newstring = LocalLock(newhandle);
505 lstrcpy(newstring, replace);
506 LocalFree(*handle);
507 *handle = newhandle;
509 else MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
512 /* Local Variables: */
513 /* c-file-style: "GNU" */
514 /* End: */