4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
16 static VOID MAIN_CreateGroups(void);
17 static VOID MAIN_MenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
18 static ATOM MAIN_RegisterMainWinClass(void);
19 static VOID MAIN_CreateMainWindow(void);
20 static VOID MAIN_CreateMDIWindow(void);
21 static VOID MAIN_AutoStart(void);
23 #define BUFFER_SIZE 1000
25 /***********************************************************************
30 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
34 Globals.lpszIniFile = "progman.ini";
35 Globals.lpszIcoFile = "progman.ico";
38 Globals.lpszLanguage = "En";
39 Globals.hInstance = hInstance;
41 Globals.hActiveGroup = 0;
43 /* Read Options from `progman.ini' */
44 Globals.bAutoArrange =
45 GetPrivateProfileInt("Settings", "AutoArrange", 0, Globals.lpszIniFile);
47 GetPrivateProfileInt("Settings", "MinOnRun", 0, Globals.lpszIniFile);
48 Globals.bSaveSettings =
49 GetPrivateProfileInt("Settings", "SaveSettings", 0, Globals.lpszIniFile);
51 /* Load default icons */
52 Globals.hMainIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
53 Globals.hGroupIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
54 Globals.hDefaultIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
55 if (!Globals.hMainIcon) Globals.hMainIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
56 if (!Globals.hGroupIcon) Globals.hGroupIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
57 if (!Globals.hDefaultIcon) Globals.hDefaultIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
59 /* Register classes */
62 if (!MAIN_RegisterMainWinClass()) return(FALSE);
63 if (!GROUP_RegisterGroupWinClass()) return(FALSE);
64 if (!PROGRAM_RegisterProgramWinClass()) return(FALSE);
67 /* Create main window */
68 MAIN_CreateMainWindow();
69 Globals.hAccel = LoadAccelerators(Globals.hInstance, STRING_ACCEL);
71 /* Setup menu, stringtable and resourcenames */
72 STRING_SelectLanguageByName(Globals.lpszLanguage);
74 MAIN_CreateMDIWindow();
76 /* Initialize groups */
79 /* Start initial applications */
83 while (GetMessage (&msg, 0, 0, 0))
84 if (!TranslateAccelerator(Globals.hMainWnd, Globals.hAccel, &msg))
86 TranslateMessage (&msg);
87 DispatchMessage (&msg);
92 /***********************************************************************
97 static VOID MAIN_CreateGroups()
99 CHAR buffer[BUFFER_SIZE];
100 CHAR szPath[MAX_PATHNAME_LEN];
103 /* Initialize groups according the `Order' entry of `progman.ini' */
104 GetPrivateProfileString("Settings", "Order", "", buffer, sizeof(buffer), Globals.lpszIniFile);
106 while (ptr < buffer + sizeof(buffer))
109 ret = sscanf(ptr, "%d%n", &num, &skip);
111 MAIN_MessageBoxIDS_s(IDS_FILE_READ_ERROR_s, Globals.lpszIniFile, IDS_ERROR, MB_OK);
114 sprintf(key, "Group%d", num);
115 GetPrivateProfileString("Groups", key, "", szPath,
116 sizeof(szPath), Globals.lpszIniFile);
117 if (!szPath[0]) continue;
119 GRPFILE_ReadGroupFile(szPath);
123 /* FIXME initialize other groups, not enumerated by `Order' */
126 /***********************************************************************
131 VOID MAIN_AutoStart()
133 CHAR buffer[BUFFER_SIZE];
134 HLOCAL hGroup, hProgram;
136 GetPrivateProfileString("Settings", "AutoStart", "Autostart", buffer,
137 sizeof(buffer), Globals.lpszIniFile);
139 for (hGroup = GROUP_FirstGroup(); hGroup; hGroup = GROUP_NextGroup(hGroup))
140 if (!lstrcmp(buffer, GROUP_GroupName(hGroup)))
141 for (hProgram = PROGRAM_FirstProgram(hGroup); hProgram;
142 hProgram = PROGRAM_NextProgram(hProgram))
143 PROGRAM_ExecuteProgram(hProgram);
146 /***********************************************************************
151 static LRESULT MAIN_MainWndProc (HWND hWnd, UINT msg,
152 WPARAM wParam, LPARAM lParam)
155 printf("M %4.4x %4.4x\n", msg, wParam);
160 CheckMenuItem(Globals.hOptionMenu, PM_AUTO_ARRANGE,
161 MF_BYCOMMAND | (Globals.bAutoArrange ? MF_CHECKED : MF_UNCHECKED));
162 CheckMenuItem(Globals.hOptionMenu, PM_MIN_ON_RUN,
163 MF_BYCOMMAND | (Globals.bMinOnRun ? MF_CHECKED : MF_UNCHECKED));
164 CheckMenuItem(Globals.hOptionMenu, PM_SAVE_SETTINGS,
165 MF_BYCOMMAND | (Globals.bSaveSettings ? MF_CHECKED : MF_UNCHECKED));
169 if (wParam < PM_FIRST_CHILD)
170 MAIN_MenuCommand(hWnd, wParam, lParam);
177 return(DefFrameProc(hWnd, Globals.hMDIWnd, msg, wParam, lParam));
180 /***********************************************************************
185 static VOID MAIN_MenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
187 HLOCAL hActiveGroup = GROUP_ActiveGroup();
188 HLOCAL hActiveProgram = PROGRAM_ActiveProgram(hActiveGroup);
189 HWND hActiveGroupWnd = GROUP_GroupWnd(hActiveGroup);
195 switch (DIALOG_New((hActiveGroupWnd && !IsIconic(hActiveGroupWnd)) ?
196 PM_NEW_PROGRAM : PM_NEW_GROUP))
199 if (hActiveGroup) PROGRAM_NewProgram(hActiveGroup);
210 PROGRAM_ExecuteProgram(hActiveProgram);
211 else if (hActiveGroupWnd)
212 OpenIcon(hActiveGroupWnd);
218 PROGRAM_CopyMoveProgram(hActiveProgram, wParam == PM_MOVE);
224 if (DIALOG_Delete(IDS_DELETE_PROGRAM_s, PROGRAM_ProgramName(hActiveProgram)))
225 PROGRAM_DeleteProgram(hActiveProgram, TRUE);
227 else if (hActiveGroup)
229 if (DIALOG_Delete(IDS_DELETE_GROUP_s, GROUP_GroupName(hActiveGroup)))
230 GROUP_DeleteGroup(hActiveGroup);
236 PROGRAM_ModifyProgram(hActiveProgram);
237 else if (hActiveGroup)
238 GROUP_ModifyGroup(hActiveGroup);
250 case PM_AUTO_ARRANGE:
251 Globals.bAutoArrange = !Globals.bAutoArrange;
252 CheckMenuItem(Globals.hOptionMenu, PM_AUTO_ARRANGE,
253 MF_BYCOMMAND | (Globals.bAutoArrange ?
254 MF_CHECKED : MF_UNCHECKED));
255 WritePrivateProfileString("Settings", "AutoArrange",
256 Globals.bAutoArrange ? "1" : "0",
257 Globals.lpszIniFile);
258 WritePrivateProfileString(NULL,NULL,NULL,Globals.lpszIniFile); /* flush it */
262 Globals.bMinOnRun = !Globals.bMinOnRun;
263 CheckMenuItem(Globals.hOptionMenu, PM_MIN_ON_RUN,
264 MF_BYCOMMAND | (Globals.bMinOnRun ?
265 MF_CHECKED : MF_UNCHECKED));
266 WritePrivateProfileString("Settings", "MinOnRun",
267 Globals.bMinOnRun ? "1" : "0",
268 Globals.lpszIniFile);
269 WritePrivateProfileString(NULL,NULL,NULL,Globals.lpszIniFile); /* flush it */
272 case PM_SAVE_SETTINGS:
273 Globals.bSaveSettings = !Globals.bSaveSettings;
274 CheckMenuItem(Globals.hOptionMenu, PM_SAVE_SETTINGS,
275 MF_BYCOMMAND | (Globals.bSaveSettings ?
276 MF_CHECKED : MF_UNCHECKED));
277 WritePrivateProfileString("Settings", "SaveSettings",
278 Globals.bSaveSettings ? "1" : "0",
279 Globals.lpszIniFile);
280 WritePrivateProfileString(NULL,NULL,NULL,Globals.lpszIniFile); /* flush it */
285 if (hActiveGroupWnd && !IsIconic(hActiveGroupWnd))
286 ArrangeIconicWindows(hActiveGroupWnd);
288 SendMessage(Globals.hMDIWnd, WM_MDIICONARRANGE, 0, 0);
293 if (!WinHelp(Globals.hMainWnd, "progman.hlp", HELP_INDEX, 0))
294 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR, IDS_ERROR, MB_OK);
298 if (!WinHelp(Globals.hMainWnd, "progman.hlp", HELP_HELPONHELP, 0))
299 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR, IDS_ERROR, MB_OK);
303 WinExec("wintutor.exe", SW_SHOWNORMAL);
307 WineLicense(Globals.hMainWnd, Globals.lpszLanguage);
311 WineWarranty(Globals.hMainWnd, Globals.lpszLanguage);
315 ShellAbout(hWnd, "WINE", "Program Manager", 0);
319 if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
320 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
322 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED, IDS_ERROR, MB_OK);
327 /***********************************************************************
329 * MAIN_RegisterMainWinClass
332 static ATOM MAIN_RegisterMainWinClass()
336 class.style = CS_HREDRAW | CS_VREDRAW;
337 class.lpfnWndProc = MAIN_MainWndProc;
338 class.cbClsExtra = 0;
339 class.cbWndExtra = 0;
340 class.hInstance = Globals.hInstance;
341 class.hIcon = Globals.hMainIcon;
342 class.hCursor = LoadCursor (0, IDC_ARROW);
343 class.hbrBackground = GetStockObject (NULL_BRUSH);
344 class.lpszMenuName = 0;
345 class.lpszClassName = STRING_MAIN_WIN_CLASS_NAME;
347 return RegisterClass(&class);
350 /***********************************************************************
352 * MAIN_CreateMainWindow
355 static VOID MAIN_CreateMainWindow()
357 INT left , top, right, bottom, width, height, show;
361 Globals.hMainMenu = 0;
363 /* Get the geometry of the main window */
364 GetPrivateProfileString("Settings", "Window", "",
365 buffer, sizeof(buffer), Globals.lpszIniFile);
366 if (5 == sscanf(buffer, "%d %d %d %d %d", &left, &top, &right, &bottom, &show))
368 width = right - left;
369 height = bottom - top;
373 left = top = width = height = CW_USEDEFAULT;
374 show = SW_SHOWNORMAL;
377 /* Create main Window */
379 CreateWindow (STRING_MAIN_WIN_CLASS_NAME, "",
380 WS_OVERLAPPEDWINDOW, left, top, width, height,
381 0, 0, Globals.hInstance, 0);
383 ShowWindow (Globals.hMainWnd, show);
384 UpdateWindow (Globals.hMainWnd);
387 /***********************************************************************
389 * MAIN_CreateMDIWindow
392 static VOID MAIN_CreateMDIWindow()
394 CLIENTCREATESTRUCT ccs;
397 /* Get the geometry of the MDI window */
398 GetClientRect(Globals.hMainWnd, &rect);
400 ccs.hWindowMenu = Globals.hWindowsMenu;
401 ccs.idFirstChild = PM_FIRST_CHILD;
403 /* Create MDI Window */
405 CreateWindow (STRING_MDI_WIN_CLASS_NAME, "",
406 WS_CHILD, rect.left, rect.top,
407 rect.right - rect.left, rect.bottom - rect.top,
409 Globals.hInstance, &ccs);
411 ShowWindow (Globals.hMDIWnd, SW_SHOW);
412 UpdateWindow (Globals.hMDIWnd);
415 /**********************************************************************/
416 /***********************************************************************
420 INT MAIN_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
422 CHAR text[MAX_STRING_LEN];
423 CHAR title[MAX_STRING_LEN];
425 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
426 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
428 return(MessageBox(Globals.hMainWnd, text, title, type));
431 /***********************************************************************
433 * MAIN_MessageBoxIDS_s
435 INT MAIN_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
437 CHAR text[MAX_STRING_LEN];
438 CHAR title[MAX_STRING_LEN];
439 CHAR newtext[MAX_STRING_LEN + MAX_PATHNAME_LEN];
441 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
442 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
443 wsprintf(newtext, text, str);
445 return(MessageBox(Globals.hMainWnd, newtext, title, type));
448 /***********************************************************************
453 VOID MAIN_ReplaceString(HLOCAL *handle, LPSTR replace)
455 HLOCAL newhandle = LocalAlloc(LMEM_FIXED, strlen(replace) + 1);
458 LPSTR newstring = LocalLock(newhandle);
459 lstrcpy(newstring, replace);
463 else MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
466 /* Local Variables: */
467 /* c-file-style: "GNU" */