4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
20 VOID WINAPI WriteOutProfiles16(void);
22 static VOID MAIN_CreateGroups(void);
23 static VOID MAIN_MenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
24 static ATOM MAIN_RegisterMainWinClass(void);
25 static VOID MAIN_CreateMainWindow(void);
26 static VOID MAIN_CreateMDIWindow(void);
27 static VOID MAIN_AutoStart(void);
29 #define BUFFER_SIZE 1000
31 /***********************************************************************
36 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
41 Globals.lpszIniFile = "progman.ini";
42 Globals.lpszIcoFile = "progman.ico";
43 #else /* Configuration in `wine.ini' */
45 CHAR buffer[MAX_PATHNAME_LEN], *p;
47 /* Redirect `progman.ini' */
48 PROFILE_GetWineIniString("progman", "progman.ini", "progman.ini",
49 buffer, sizeof(buffer));
50 Globals.lpszIniFile = p = LocalLock(LocalAlloc(LMEM_FIXED, lstrlen(buffer)+1));
51 memcpy(p, buffer, 1 + lstrlen(buffer));
53 /* Redirect `progman.ico' */
54 PROFILE_GetWineIniString("progman", "progman.ico", "progman.ico",
55 buffer, sizeof(buffer));
56 Globals.lpszIcoFile = p = LocalLock(LocalAlloc(LMEM_FIXED, lstrlen(buffer)+1));
57 memcpy(p, buffer, 1 + lstrlen(buffer));
62 Globals.lpszLanguage = "En";
63 Globals.hInstance = hInstance;
65 Globals.hActiveGroup = 0;
67 /* Read Options from `progman.ini' */
68 Globals.bAutoArrange =
69 GetPrivateProfileInt("Settings", "AutoArrange", 0, Globals.lpszIniFile);
71 GetPrivateProfileInt("Settings", "MinOnRun", 0, Globals.lpszIniFile);
72 Globals.bSaveSettings =
73 GetPrivateProfileInt("Settings", "SaveSettings", 0, Globals.lpszIniFile);
75 /* Load default icons */
76 Globals.hMainIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
77 Globals.hGroupIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
78 Globals.hDefaultIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
79 if (!Globals.hMainIcon) Globals.hMainIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
80 if (!Globals.hGroupIcon) Globals.hGroupIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
81 if (!Globals.hDefaultIcon) Globals.hDefaultIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
83 /* Register classes */
86 if (!MAIN_RegisterMainWinClass()) return(FALSE);
87 if (!GROUP_RegisterGroupWinClass()) return(FALSE);
88 if (!PROGRAM_RegisterProgramWinClass()) return(FALSE);
91 /* Create main window */
92 MAIN_CreateMainWindow();
93 Globals.hAccel = LoadAccelerators(Globals.hInstance, STRING_ACCEL);
95 /* Setup menu, stringtable and resourcenames */
96 STRING_SelectLanguageByName(Globals.lpszLanguage);
98 MAIN_CreateMDIWindow();
100 /* Initialize groups */
103 /* Start initial applications */
107 while (GetMessage (&msg, 0, 0, 0))
108 if (!TranslateAccelerator(Globals.hMainWnd, Globals.hAccel, &msg))
110 TranslateMessage (&msg);
111 DispatchMessage (&msg);
116 /***********************************************************************
121 static VOID MAIN_CreateGroups()
123 CHAR buffer[BUFFER_SIZE];
124 CHAR szPath[MAX_PATHNAME_LEN];
127 /* Initialize groups according the `Order' entry of `progman.ini' */
128 GetPrivateProfileString("Settings", "Order", "", buffer, sizeof(buffer), Globals.lpszIniFile);
130 while (ptr < buffer + sizeof(buffer))
133 ret = sscanf(ptr, "%d%n", &num, &skip);
135 MAIN_MessageBoxIDS_s(IDS_FILE_READ_ERROR_s, Globals.lpszIniFile, IDS_ERROR, MB_OK);
138 sprintf(key, "Group%d", num);
139 GetPrivateProfileString("Groups", key, "", szPath,
140 sizeof(szPath), Globals.lpszIniFile);
141 if (!szPath[0]) continue;
143 GRPFILE_ReadGroupFile(szPath);
147 /* FIXME initialize other groups, not enumerated by `Order' */
150 /***********************************************************************
155 VOID MAIN_AutoStart()
157 CHAR buffer[BUFFER_SIZE];
158 HLOCAL hGroup, hProgram;
160 GetPrivateProfileString("Settings", "AutoStart", "Autostart", buffer,
161 sizeof(buffer), Globals.lpszIniFile);
163 for (hGroup = GROUP_FirstGroup(); hGroup; hGroup = GROUP_NextGroup(hGroup))
164 if (!lstrcmp(buffer, GROUP_GroupName(hGroup)))
165 for (hProgram = PROGRAM_FirstProgram(hGroup); hProgram;
166 hProgram = PROGRAM_NextProgram(hProgram))
167 PROGRAM_ExecuteProgram(hProgram);
170 /***********************************************************************
175 static LRESULT MAIN_MainWndProc (HWND hWnd, UINT msg,
176 WPARAM wParam, LPARAM lParam)
179 printf("M %4.4x %4.4x\n", msg, wParam);
184 CheckMenuItem(Globals.hOptionMenu, PM_AUTO_ARRANGE,
185 MF_BYCOMMAND | (Globals.bAutoArrange ? MF_CHECKED : MF_UNCHECKED));
186 CheckMenuItem(Globals.hOptionMenu, PM_MIN_ON_RUN,
187 MF_BYCOMMAND | (Globals.bMinOnRun ? MF_CHECKED : MF_UNCHECKED));
188 CheckMenuItem(Globals.hOptionMenu, PM_SAVE_SETTINGS,
189 MF_BYCOMMAND | (Globals.bSaveSettings ? MF_CHECKED : MF_UNCHECKED));
193 if (wParam < PM_FIRST_CHILD)
194 MAIN_MenuCommand(hWnd, wParam, lParam);
201 return(DefFrameProc(hWnd, Globals.hMDIWnd, msg, wParam, lParam));
204 /***********************************************************************
209 static VOID MAIN_MenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
211 HLOCAL hActiveGroup = GROUP_ActiveGroup();
212 HLOCAL hActiveProgram = PROGRAM_ActiveProgram(hActiveGroup);
213 HWND hActiveGroupWnd = GROUP_GroupWnd(hActiveGroup);
219 switch (DIALOG_New((hActiveGroupWnd && !IsIconic(hActiveGroupWnd)) ?
220 PM_NEW_PROGRAM : PM_NEW_GROUP))
223 if (hActiveGroup) PROGRAM_NewProgram(hActiveGroup);
234 PROGRAM_ExecuteProgram(hActiveProgram);
235 else if (hActiveGroupWnd)
236 OpenIcon(hActiveGroupWnd);
242 PROGRAM_CopyMoveProgram(hActiveProgram, wParam == PM_MOVE);
248 if (DIALOG_Delete(IDS_DELETE_PROGRAM_s, PROGRAM_ProgramName(hActiveProgram)))
249 PROGRAM_DeleteProgram(hActiveProgram, TRUE);
251 else if (hActiveGroup)
253 if (DIALOG_Delete(IDS_DELETE_GROUP_s, GROUP_GroupName(hActiveGroup)))
254 GROUP_DeleteGroup(hActiveGroup);
260 PROGRAM_ModifyProgram(hActiveProgram);
261 else if (hActiveGroup)
262 GROUP_ModifyGroup(hActiveGroup);
274 case PM_AUTO_ARRANGE:
275 Globals.bAutoArrange = !Globals.bAutoArrange;
276 CheckMenuItem(Globals.hOptionMenu, PM_AUTO_ARRANGE,
277 MF_BYCOMMAND | (Globals.bAutoArrange ?
278 MF_CHECKED : MF_UNCHECKED));
279 WritePrivateProfileString("Settings", "AutoArrange",
280 Globals.bAutoArrange ? "1" : "0",
281 Globals.lpszIniFile);
282 WriteOutProfiles16();
286 Globals.bMinOnRun = !Globals.bMinOnRun;
287 CheckMenuItem(Globals.hOptionMenu, PM_MIN_ON_RUN,
288 MF_BYCOMMAND | (Globals.bMinOnRun ?
289 MF_CHECKED : MF_UNCHECKED));
290 WritePrivateProfileString("Settings", "MinOnRun",
291 Globals.bMinOnRun ? "1" : "0",
292 Globals.lpszIniFile);
293 WriteOutProfiles16();
296 case PM_SAVE_SETTINGS:
297 Globals.bSaveSettings = !Globals.bSaveSettings;
298 CheckMenuItem(Globals.hOptionMenu, PM_SAVE_SETTINGS,
299 MF_BYCOMMAND | (Globals.bSaveSettings ?
300 MF_CHECKED : MF_UNCHECKED));
301 WritePrivateProfileString("Settings", "SaveSettings",
302 Globals.bSaveSettings ? "1" : "0",
303 Globals.lpszIniFile);
304 WriteOutProfiles16();
309 if (hActiveGroupWnd && !IsIconic(hActiveGroupWnd))
310 ArrangeIconicWindows(hActiveGroupWnd);
312 SendMessage(Globals.hMDIWnd, WM_MDIICONARRANGE, 0, 0);
317 if (!WinHelp(Globals.hMainWnd, "progman.hlp", HELP_INDEX, 0))
318 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR, IDS_ERROR, MB_OK);
322 if (!WinHelp(Globals.hMainWnd, "progman.hlp", HELP_HELPONHELP, 0))
323 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR, IDS_ERROR, MB_OK);
327 WinExec("wintutor.exe", SW_SHOWNORMAL);
331 WineLicense(Globals.hMainWnd, Globals.lpszLanguage);
335 WineWarranty(Globals.hMainWnd, Globals.lpszLanguage);
339 ShellAbout(hWnd, "WINE", "Program Manager", 0);
343 if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
344 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
346 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED, IDS_ERROR, MB_OK);
351 /***********************************************************************
353 * MAIN_RegisterMainWinClass
356 static ATOM MAIN_RegisterMainWinClass()
360 class.style = CS_HREDRAW | CS_VREDRAW;
361 class.lpfnWndProc = MAIN_MainWndProc;
362 class.cbClsExtra = 0;
363 class.cbWndExtra = 0;
364 class.hInstance = Globals.hInstance;
365 class.hIcon = Globals.hMainIcon;
366 class.hCursor = LoadCursor (0, IDC_ARROW);
367 class.hbrBackground = GetStockObject (NULL_BRUSH);
368 class.lpszMenuName = 0;
369 class.lpszClassName = STRING_MAIN_WIN_CLASS_NAME;
371 return RegisterClass(&class);
374 /***********************************************************************
376 * MAIN_CreateMainWindow
379 static VOID MAIN_CreateMainWindow()
381 INT left , top, right, bottom, width, height, show;
385 Globals.hMainMenu = 0;
387 /* Get the geometry of the main window */
388 GetPrivateProfileString("Settings", "Window", "",
389 buffer, sizeof(buffer), Globals.lpszIniFile);
390 if (5 == sscanf(buffer, "%d %d %d %d %d", &left, &top, &right, &bottom, &show))
392 width = right - left;
393 height = bottom - top;
397 left = top = width = height = CW_USEDEFAULT;
398 show = SW_SHOWNORMAL;
401 /* Create main Window */
403 CreateWindow (STRING_MAIN_WIN_CLASS_NAME, "",
404 WS_OVERLAPPEDWINDOW, left, top, width, height,
405 0, 0, Globals.hInstance, 0);
407 ShowWindow (Globals.hMainWnd, show);
408 UpdateWindow (Globals.hMainWnd);
411 /***********************************************************************
413 * MAIN_CreateMDIWindow
416 static VOID MAIN_CreateMDIWindow()
418 CLIENTCREATESTRUCT ccs;
421 /* Get the geometry of the MDI window */
422 GetClientRect(Globals.hMainWnd, &rect);
424 ccs.hWindowMenu = Globals.hWindowsMenu;
425 ccs.idFirstChild = PM_FIRST_CHILD;
427 /* Create MDI Window */
429 CreateWindow (STRING_MDI_WIN_CLASS_NAME, "",
430 WS_CHILD, rect.left, rect.top,
431 rect.right - rect.left, rect.bottom - rect.top,
433 Globals.hInstance, &ccs);
435 ShowWindow (Globals.hMDIWnd, SW_SHOW);
436 UpdateWindow (Globals.hMDIWnd);
439 /**********************************************************************/
440 /***********************************************************************
444 INT MAIN_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
446 CHAR text[MAX_STRING_LEN];
447 CHAR title[MAX_STRING_LEN];
449 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
450 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
452 return(MessageBox(Globals.hMainWnd, text, title, type));
455 /***********************************************************************
457 * MAIN_MessageBoxIDS_s
459 INT MAIN_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
461 CHAR text[MAX_STRING_LEN];
462 CHAR title[MAX_STRING_LEN];
463 CHAR newtext[MAX_STRING_LEN + MAX_PATHNAME_LEN];
465 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
466 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
467 wsprintf(newtext, text, str);
469 return(MessageBox(Globals.hMainWnd, newtext, title, type));
472 /***********************************************************************
477 VOID MAIN_ReplaceString(HLOCAL *handle, LPSTR replace)
479 HLOCAL newhandle = LocalAlloc(LMEM_FIXED, strlen(replace) + 1);
482 LPSTR newstring = LocalLock(newhandle);
483 lstrcpy(newstring, replace);
487 else MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
490 /* Local Variables: */
491 /* c-file-style: "GNU" */