4 * Copyright 1996 Ulrich Schmid
5 * Copyright 2002 Sylvain Petreolle
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 static VOID MAIN_CreateGroups(void);
33 static VOID MAIN_MenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
34 static ATOM MAIN_RegisterMainWinClass(void);
35 static VOID MAIN_CreateMainWindow(void);
36 static VOID MAIN_CreateMDIWindow(void);
37 static VOID MAIN_AutoStart(void);
38 static VOID WineLicense(HWND Wnd);
39 static VOID WineWarranty(HWND Wnd);
41 #define BUFFER_SIZE 1000
43 /***********************************************************************
48 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
52 Globals.lpszIniFile = "progman.ini";
53 Globals.lpszIcoFile = "progman.ico";
55 Globals.hInstance = hInstance;
57 Globals.hActiveGroup = 0;
59 /* Read Options from `progman.ini' */
60 Globals.bAutoArrange =
61 GetPrivateProfileInt("Settings", "AutoArrange", 0, Globals.lpszIniFile);
63 GetPrivateProfileInt("Settings", "MinOnRun", 0, Globals.lpszIniFile);
64 Globals.bSaveSettings =
65 GetPrivateProfileInt("Settings", "SaveSettings", 0, Globals.lpszIniFile);
67 /* Load default icons */
68 Globals.hMainIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
69 Globals.hGroupIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
70 Globals.hDefaultIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
71 if (!Globals.hMainIcon) Globals.hMainIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
72 if (!Globals.hGroupIcon) Globals.hGroupIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
73 if (!Globals.hDefaultIcon) Globals.hDefaultIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
75 /* Register classes */
78 if (!MAIN_RegisterMainWinClass()) return(FALSE);
79 if (!GROUP_RegisterGroupWinClass()) return(FALSE);
80 if (!PROGRAM_RegisterProgramWinClass()) return(FALSE);
83 /* Create main window */
84 MAIN_CreateMainWindow();
85 Globals.hAccel = LoadAccelerators(Globals.hInstance, STRING_ACCEL);
87 /* Setup menu, stringtable and resourcenames */
90 MAIN_CreateMDIWindow();
92 /* Initialize groups */
95 /* Start initial applications */
99 while (GetMessage (&msg, 0, 0, 0))
100 if (!TranslateAccelerator(Globals.hMainWnd, Globals.hAccel, &msg))
102 TranslateMessage (&msg);
103 DispatchMessage (&msg);
108 /***********************************************************************
113 static VOID MAIN_CreateGroups(void)
115 CHAR buffer[BUFFER_SIZE];
116 CHAR szPath[MAX_PATHNAME_LEN];
119 /* Initialize groups according the `Order' entry of `progman.ini' */
120 GetPrivateProfileString("Settings", "Order", "", buffer, sizeof(buffer), Globals.lpszIniFile);
122 while (ptr < buffer + sizeof(buffer))
125 ret = sscanf(ptr, "%d%n", &num, &skip);
127 MAIN_MessageBoxIDS_s(IDS_FILE_READ_ERROR_s, Globals.lpszIniFile, IDS_ERROR, MB_OK);
130 sprintf(key, "Group%d", num);
131 GetPrivateProfileString("Groups", key, "", szPath,
132 sizeof(szPath), Globals.lpszIniFile);
133 if (!szPath[0]) continue;
135 GRPFILE_ReadGroupFile(szPath);
139 /* FIXME initialize other groups, not enumerated by `Order' */
142 /***********************************************************************
147 VOID MAIN_AutoStart(void)
149 CHAR buffer[BUFFER_SIZE];
150 HLOCAL hGroup, hProgram;
152 GetPrivateProfileString("Settings", "AutoStart", "Autostart", buffer,
153 sizeof(buffer), Globals.lpszIniFile);
155 for (hGroup = GROUP_FirstGroup(); hGroup; hGroup = GROUP_NextGroup(hGroup))
156 if (!lstrcmp(buffer, GROUP_GroupName(hGroup)))
157 for (hProgram = PROGRAM_FirstProgram(hGroup); hProgram;
158 hProgram = PROGRAM_NextProgram(hProgram))
159 PROGRAM_ExecuteProgram(hProgram);
162 /***********************************************************************
167 static LRESULT CALLBACK MAIN_MainWndProc(HWND hWnd, UINT msg,
168 WPARAM wParam, LPARAM lParam)
171 printf("M %4.4x %4.4x\n", msg, wParam);
176 CheckMenuItem(Globals.hOptionMenu, PM_AUTO_ARRANGE,
177 MF_BYCOMMAND | (Globals.bAutoArrange ? MF_CHECKED : MF_UNCHECKED));
178 CheckMenuItem(Globals.hOptionMenu, PM_MIN_ON_RUN,
179 MF_BYCOMMAND | (Globals.bMinOnRun ? MF_CHECKED : MF_UNCHECKED));
180 CheckMenuItem(Globals.hOptionMenu, PM_SAVE_SETTINGS,
181 MF_BYCOMMAND | (Globals.bSaveSettings ? MF_CHECKED : MF_UNCHECKED));
185 if (wParam < PM_FIRST_CHILD){
186 MAIN_MenuCommand(hWnd, wParam, lParam);
194 return(DefFrameProc(hWnd, Globals.hMDIWnd, msg, wParam, lParam));
197 /***********************************************************************
202 static VOID MAIN_MenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
204 HLOCAL hActiveGroup = GROUP_ActiveGroup();
205 HLOCAL hActiveProgram = PROGRAM_ActiveProgram(hActiveGroup);
206 HWND hActiveGroupWnd = GROUP_GroupWnd(hActiveGroup);
212 switch (DIALOG_New((hActiveGroupWnd && !IsIconic(hActiveGroupWnd)) ?
213 PM_NEW_PROGRAM : PM_NEW_GROUP))
216 if (hActiveGroup) PROGRAM_NewProgram(hActiveGroup);
227 PROGRAM_ExecuteProgram(hActiveProgram);
228 else if (hActiveGroupWnd)
229 OpenIcon(hActiveGroupWnd);
235 PROGRAM_CopyMoveProgram(hActiveProgram, wParam == PM_MOVE);
241 if (DIALOG_Delete(IDS_DELETE_PROGRAM_s, PROGRAM_ProgramName(hActiveProgram)))
242 PROGRAM_DeleteProgram(hActiveProgram, TRUE);
244 else if (hActiveGroup)
246 if (DIALOG_Delete(IDS_DELETE_GROUP_s, GROUP_GroupName(hActiveGroup)))
247 GROUP_DeleteGroup(hActiveGroup);
253 PROGRAM_ModifyProgram(hActiveProgram);
254 else if (hActiveGroup)
255 GROUP_ModifyGroup(hActiveGroup);
267 case PM_AUTO_ARRANGE:
268 Globals.bAutoArrange = !Globals.bAutoArrange;
269 CheckMenuItem(Globals.hOptionMenu, PM_AUTO_ARRANGE,
270 MF_BYCOMMAND | (Globals.bAutoArrange ?
271 MF_CHECKED : MF_UNCHECKED));
272 WritePrivateProfileString("Settings", "AutoArrange",
273 Globals.bAutoArrange ? "1" : "0",
274 Globals.lpszIniFile);
275 WritePrivateProfileString(NULL,NULL,NULL,Globals.lpszIniFile); /* flush it */
279 Globals.bMinOnRun = !Globals.bMinOnRun;
280 CheckMenuItem(Globals.hOptionMenu, PM_MIN_ON_RUN,
281 MF_BYCOMMAND | (Globals.bMinOnRun ?
282 MF_CHECKED : MF_UNCHECKED));
283 WritePrivateProfileString("Settings", "MinOnRun",
284 Globals.bMinOnRun ? "1" : "0",
285 Globals.lpszIniFile);
286 WritePrivateProfileString(NULL,NULL,NULL,Globals.lpszIniFile); /* flush it */
289 case PM_SAVE_SETTINGS:
290 Globals.bSaveSettings = !Globals.bSaveSettings;
291 CheckMenuItem(Globals.hOptionMenu, PM_SAVE_SETTINGS,
292 MF_BYCOMMAND | (Globals.bSaveSettings ?
293 MF_CHECKED : MF_UNCHECKED));
294 WritePrivateProfileString("Settings", "SaveSettings",
295 Globals.bSaveSettings ? "1" : "0",
296 Globals.lpszIniFile);
297 WritePrivateProfileString(NULL,NULL,NULL,Globals.lpszIniFile); /* flush it */
303 if (hActiveGroupWnd && !IsIconic(hActiveGroupWnd))
304 ArrangeIconicWindows(hActiveGroupWnd);
306 SendMessage(Globals.hMDIWnd, WM_MDIICONARRANGE, 0, 0);
311 if (!WinHelp(Globals.hMainWnd, "progman.hlp", HELP_CONTENTS, 0))
312 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR, IDS_ERROR, MB_OK);
316 if (!WinHelp(Globals.hMainWnd, "progman.hlp", HELP_HELPONHELP, 0))
317 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR, IDS_ERROR, MB_OK);
321 WinExec("wintutor.exe", SW_SHOWNORMAL);
325 WineLicense(Globals.hMainWnd);
329 WineWarranty(Globals.hMainWnd);
333 ShellAbout(hWnd, "WINE", "Program Manager", 0);
337 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED, IDS_ERROR, MB_OK);
342 /***********************************************************************
344 * MAIN_RegisterMainWinClass
347 static ATOM MAIN_RegisterMainWinClass(void)
351 class.style = CS_HREDRAW | CS_VREDRAW;
352 class.lpfnWndProc = MAIN_MainWndProc;
353 class.cbClsExtra = 0;
354 class.cbWndExtra = 0;
355 class.hInstance = Globals.hInstance;
356 class.hIcon = Globals.hMainIcon;
357 class.hCursor = LoadCursor (0, IDC_ARROW);
358 class.hbrBackground = GetStockObject (NULL_BRUSH);
359 class.lpszMenuName = 0;
360 class.lpszClassName = STRING_MAIN_WIN_CLASS_NAME;
362 return RegisterClass(&class);
365 /***********************************************************************
367 * MAIN_CreateMainWindow
370 static VOID MAIN_CreateMainWindow(void)
372 INT left , top, right, bottom, width, height, show;
376 Globals.hMainMenu = 0;
378 /* Get the geometry of the main window */
379 GetPrivateProfileString("Settings", "Window", "",
380 buffer, sizeof(buffer), Globals.lpszIniFile);
381 if (5 == sscanf(buffer, "%d %d %d %d %d", &left, &top, &right, &bottom, &show))
383 width = right - left;
384 height = bottom - top;
388 left = top = width = height = CW_USEDEFAULT;
389 show = SW_SHOWNORMAL;
392 /* Create main Window */
394 CreateWindow (STRING_MAIN_WIN_CLASS_NAME, "",
395 WS_OVERLAPPEDWINDOW, left, top, width, height,
396 0, 0, Globals.hInstance, 0);
398 ShowWindow (Globals.hMainWnd, show);
399 UpdateWindow (Globals.hMainWnd);
402 /***********************************************************************
404 * MAIN_CreateMDIWindow
407 static VOID MAIN_CreateMDIWindow(void)
409 CLIENTCREATESTRUCT ccs;
412 /* Get the geometry of the MDI window */
413 GetClientRect(Globals.hMainWnd, &rect);
415 ccs.hWindowMenu = Globals.hWindowsMenu;
416 ccs.idFirstChild = PM_FIRST_CHILD;
418 /* Create MDI Window */
420 CreateWindow (STRING_MDI_WIN_CLASS_NAME, "",
421 WS_CHILD, rect.left, rect.top,
422 rect.right - rect.left, rect.bottom - rect.top,
424 Globals.hInstance, &ccs);
426 ShowWindow (Globals.hMDIWnd, SW_SHOW);
427 UpdateWindow (Globals.hMDIWnd);
430 /**********************************************************************/
431 /***********************************************************************
435 INT MAIN_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
437 CHAR text[MAX_STRING_LEN];
438 CHAR title[MAX_STRING_LEN];
440 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
441 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
443 return(MessageBox(Globals.hMainWnd, text, title, type));
446 /***********************************************************************
448 * MAIN_MessageBoxIDS_s
450 INT MAIN_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
452 CHAR text[MAX_STRING_LEN];
453 CHAR title[MAX_STRING_LEN];
454 CHAR newtext[MAX_STRING_LEN + MAX_PATHNAME_LEN];
456 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
457 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
458 wsprintf(newtext, text, str);
460 return(MessageBox(Globals.hMainWnd, newtext, title, type));
463 /***********************************************************************
468 VOID MAIN_ReplaceString(HLOCAL *handle, LPSTR replace)
470 HLOCAL newhandle = LocalAlloc(LMEM_FIXED, strlen(replace) + 1);
473 LPSTR newstring = LocalLock(newhandle);
474 lstrcpy(newstring, replace);
478 else MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
481 VOID WineLicense(HWND Wnd)
483 char cap[20], text[1024];
484 LoadString(Globals.hInstance, IDS_LICENSE, text, sizeof text);
485 LoadString(Globals.hInstance, IDS_LICENSE_CAPTION, cap, sizeof cap);
486 MessageBox(Wnd, text, cap, MB_ICONINFORMATION | MB_OK);
489 VOID WineWarranty(HWND Wnd)
491 char cap[20], text[1024];
492 LoadString(Globals.hInstance, IDS_WARRANTY, text, sizeof text);
493 LoadString(Globals.hInstance, IDS_WARRANTY_CAPTION, cap, sizeof cap);
494 MessageBox(Wnd, text, cap, MB_ICONEXCLAMATION | MB_OK);
497 /* Local Variables: */
498 /* c-file-style: "GNU" */