4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
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();
24 static VOID MAIN_CreateGroups(void);
25 static VOID MAIN_MenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
26 static ATOM MAIN_RegisterMainWinClass(void);
27 static VOID MAIN_CreateMainWindow(void);
28 static VOID MAIN_CreateMDIWindow(void);
29 static VOID MAIN_AutoStart(void);
31 #define BUFFER_SIZE 1000
33 /***********************************************************************
38 int PASCAL WinMain (HANDLE hInstance, HANDLE prev, LPSTR cmdline, int show)
42 #if defined(WINELIB) && !defined(HAVE_WINE_CONSTRUCTOR)
43 /* Register resources */
44 LIBWINE_Register_accel();
45 LIBWINE_Register_De();
46 LIBWINE_Register_En();
47 LIBWINE_Register_Fi();
48 LIBWINE_Register_Fr();
52 Globals.lpszIniFile = "progman.ini";
53 Globals.lpszIcoFile = "progman.ico";
54 #else /* Configuration in `wine.ini' */
56 CHAR buffer[MAX_PATHNAME_LEN], *p;
58 /* Redirect `progman.ini' */
59 PROFILE_GetWineIniString("progman", "progman.ini", "progman.ini",
60 buffer, sizeof(buffer));
61 Globals.lpszIniFile = p = LocalLock(LocalAlloc(LMEM_FIXED, lstrlen(buffer)));
62 hmemcpy(p, buffer, 1 + lstrlen(buffer));
64 /* Redirect `progman.ico' */
65 PROFILE_GetWineIniString("progman", "progman.ico", "progman.ico",
66 buffer, sizeof(buffer));
67 Globals.lpszIcoFile = p = LocalLock(LocalAlloc(LMEM_FIXED, lstrlen(buffer)));
68 hmemcpy(p, buffer, 1 + lstrlen(buffer));
74 Globals.lpszLanguage = Languages[Options.language].name;
76 Globals.lpszLanguage = "En";
79 Globals.hInstance = hInstance;
81 Globals.hActiveGroup = 0;
83 /* Read Options from `progman.ini' */
84 Globals.bAutoArrange =
85 GetPrivateProfileInt("Settings", "AutoArrange", 0, Globals.lpszIniFile);
87 GetPrivateProfileInt("Settings", "MinOnRun", 0, Globals.lpszIniFile);
88 Globals.bSaveSettings =
89 GetPrivateProfileInt("Settings", "SaveSettings", 0, Globals.lpszIniFile);
91 /* Load default icons */
92 Globals.hMainIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
93 Globals.hGroupIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
94 Globals.hDefaultIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
95 if (!Globals.hMainIcon) Globals.hMainIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
96 if (!Globals.hGroupIcon) Globals.hGroupIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
97 if (!Globals.hDefaultIcon) Globals.hDefaultIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
99 /* Register classes */
102 if (!MAIN_RegisterMainWinClass()) return(FALSE);
103 if (!GROUP_RegisterGroupWinClass()) return(FALSE);
104 if (!PROGRAM_RegisterProgramWinClass()) return(FALSE);
107 /* Create main window */
108 MAIN_CreateMainWindow();
109 Globals.hAccel = LoadAccelerators(Globals.hInstance, STRING_ACCEL);
111 /* Setup menu, stringtable and resourcenames */
112 STRING_SelectLanguageByName(Globals.lpszLanguage);
114 MAIN_CreateMDIWindow();
116 /* Initialize groups */
119 /* Start initial applications */
123 while (GetMessage (&msg, 0, 0, 0))
124 if (!TranslateAccelerator(Globals.hMainWnd, Globals.hAccel, &msg))
126 TranslateMessage (&msg);
127 DispatchMessage (&msg);
132 /***********************************************************************
137 static VOID MAIN_CreateGroups()
139 CHAR buffer[BUFFER_SIZE];
140 CHAR szPath[MAX_PATHNAME_LEN];
143 /* Initialize groups according the `Order' entry of `progman.ini' */
144 GetPrivateProfileString("Settings", "Order", "", buffer, sizeof(buffer), Globals.lpszIniFile);
146 while (ptr < buffer + sizeof(buffer))
149 ret = sscanf(ptr, "%d%n", &num, &skip);
151 MAIN_MessageBoxIDS_s(IDS_FILE_READ_ERROR_s, Globals.lpszIniFile, IDS_ERROR, MB_OK);
154 sprintf(key, "Group%d", num);
155 GetPrivateProfileString("Groups", key, "", szPath,
156 sizeof(szPath), Globals.lpszIniFile);
157 if (!szPath[0]) continue;
159 GRPFILE_ReadGroupFile(szPath);
163 /* FIXME initialize other groups, not enumerated by `Order' */
166 /***********************************************************************
171 VOID MAIN_AutoStart()
173 CHAR buffer[BUFFER_SIZE];
174 HLOCAL hGroup, hProgram;
176 GetPrivateProfileString("Settings", "AutoStart", "Autostart", buffer,
177 sizeof(buffer), Globals.lpszIniFile);
179 for (hGroup = GROUP_FirstGroup(); hGroup; hGroup = GROUP_NextGroup(hGroup))
180 if (!lstrcmp(buffer, GROUP_GroupName(hGroup)))
181 for (hProgram = PROGRAM_FirstProgram(hGroup); hProgram;
182 hProgram = PROGRAM_NextProgram(hProgram))
183 PROGRAM_ExecuteProgram(hProgram);
186 /***********************************************************************
191 static LRESULT MAIN_MainWndProc (HWND hWnd, UINT msg,
192 WPARAM wParam, LPARAM lParam)
195 printf("M %4.4x %4.4x\n", msg, wParam);
200 CheckMenuItem(Globals.hOptionMenu, PM_AUTO_ARRANGE,
201 MF_BYCOMMAND | (Globals.bAutoArrange ? MF_CHECKED : MF_UNCHECKED));
202 CheckMenuItem(Globals.hOptionMenu, PM_MIN_ON_RUN,
203 MF_BYCOMMAND | (Globals.bMinOnRun ? MF_CHECKED : MF_UNCHECKED));
204 CheckMenuItem(Globals.hOptionMenu, PM_SAVE_SETTINGS,
205 MF_BYCOMMAND | (Globals.bSaveSettings ? MF_CHECKED : MF_UNCHECKED));
209 if (wParam < PM_FIRST_CHILD)
210 MAIN_MenuCommand(hWnd, wParam, lParam);
217 return(DefFrameProc(hWnd, Globals.hMDIWnd, msg, wParam, lParam));
220 /***********************************************************************
225 static VOID MAIN_MenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
227 HLOCAL hActiveGroup = GROUP_ActiveGroup();
228 HLOCAL hActiveProgram = PROGRAM_ActiveProgram(hActiveGroup);
229 HWND hActiveGroupWnd = GROUP_GroupWnd(hActiveGroup);
235 switch (DIALOG_New((hActiveGroupWnd && !IsIconic(hActiveGroupWnd)) ?
236 PM_NEW_PROGRAM : PM_NEW_GROUP))
239 if (hActiveGroup) PROGRAM_NewProgram(hActiveGroup);
250 PROGRAM_ExecuteProgram(hActiveProgram);
251 else if (hActiveGroupWnd)
252 OpenIcon(hActiveGroupWnd);
258 PROGRAM_CopyMoveProgram(hActiveProgram, wParam == PM_MOVE);
264 if (DIALOG_Delete(IDS_DELETE_PROGRAM_s, PROGRAM_ProgramName(hActiveProgram)))
265 PROGRAM_DeleteProgram(hActiveProgram, TRUE);
267 else if (hActiveGroup)
269 if (DIALOG_Delete(IDS_DELETE_GROUP_s, GROUP_GroupName(hActiveGroup)))
270 GROUP_DeleteGroup(hActiveGroup);
276 PROGRAM_ModifyProgram(hActiveProgram);
277 else if (hActiveGroup)
278 GROUP_ModifyGroup(hActiveGroup);
290 case PM_AUTO_ARRANGE:
291 Globals.bAutoArrange = !Globals.bAutoArrange;
292 CheckMenuItem(Globals.hOptionMenu, PM_AUTO_ARRANGE,
293 MF_BYCOMMAND | (Globals.bAutoArrange ?
294 MF_CHECKED : MF_UNCHECKED));
295 WritePrivateProfileString("Settings", "AutoArrange",
296 Globals.bAutoArrange ? "1" : "0",
297 Globals.lpszIniFile);
302 Globals.bMinOnRun = !Globals.bMinOnRun;
303 CheckMenuItem(Globals.hOptionMenu, PM_MIN_ON_RUN,
304 MF_BYCOMMAND | (Globals.bMinOnRun ?
305 MF_CHECKED : MF_UNCHECKED));
306 WritePrivateProfileString("Settings", "MinOnRun",
307 Globals.bMinOnRun ? "1" : "0",
308 Globals.lpszIniFile);
312 case PM_SAVE_SETTINGS:
313 Globals.bSaveSettings = !Globals.bSaveSettings;
314 CheckMenuItem(Globals.hOptionMenu, PM_SAVE_SETTINGS,
315 MF_BYCOMMAND | (Globals.bSaveSettings ?
316 MF_CHECKED : MF_UNCHECKED));
317 WritePrivateProfileString("Settings", "SaveSettings",
318 Globals.bSaveSettings ? "1" : "0",
319 Globals.lpszIniFile);
325 if (hActiveGroupWnd && !IsIconic(hActiveGroupWnd))
326 ArrangeIconicWindows(hActiveGroupWnd);
328 SendMessage(Globals.hMDIWnd, WM_MDIICONARRANGE, 0, 0);
333 if (!WinHelp(Globals.hMainWnd, "progman.hlp", HELP_INDEX, 0))
334 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR, IDS_ERROR, MB_OK);
338 if (!WinHelp(Globals.hMainWnd, "progman.hlp", HELP_HELPONHELP, 0))
339 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR, IDS_ERROR, MB_OK);
343 WinExec("wintutor.exe", SW_SHOWNORMAL);
347 WineLicense(Globals.hMainWnd, Globals.lpszLanguage);
351 WineWarranty(Globals.hMainWnd, Globals.lpszLanguage);
357 extern const char people[];
358 ShellAbout(hWnd, "WINE", people, 0);
364 if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
365 STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
367 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED, IDS_ERROR, MB_OK);
372 /***********************************************************************
374 * MAIN_RegisterMainWinClass
377 static ATOM MAIN_RegisterMainWinClass()
381 class.style = CS_HREDRAW | CS_VREDRAW;
382 class.lpfnWndProc = MAIN_MainWndProc;
383 class.cbClsExtra = 0;
384 class.cbWndExtra = 0;
385 class.hInstance = Globals.hInstance;
386 class.hIcon = Globals.hMainIcon;
387 class.hCursor = LoadCursor (0, IDC_ARROW);
388 class.hbrBackground = GetStockObject (NULL_BRUSH);
389 class.lpszMenuName = 0;
390 class.lpszClassName = STRING_MAIN_WIN_CLASS_NAME;
392 return RegisterClass(&class);
395 /***********************************************************************
397 * MAIN_CreateMainWindow
400 static VOID MAIN_CreateMainWindow()
402 INT left , top, right, bottom, width, height, show;
406 Globals.hMainMenu = 0;
408 /* Get the geometry of the main window */
409 GetPrivateProfileString("Settings", "Window", "",
410 buffer, sizeof(buffer), Globals.lpszIniFile);
411 if (5 == sscanf(buffer, "%d %d %d %d %d", &left, &top, &right, &bottom, &show))
413 width = right - left;
414 height = bottom - top;
418 left = top = width = height = CW_USEDEFAULT;
419 show = SW_SHOWNORMAL;
422 /* Create main Window */
424 CreateWindow (STRING_MAIN_WIN_CLASS_NAME, "",
425 WS_OVERLAPPEDWINDOW, left, top, width, height,
426 0, 0, Globals.hInstance, 0);
428 ShowWindow (Globals.hMainWnd, show);
429 UpdateWindow (Globals.hMainWnd);
432 /***********************************************************************
434 * MAIN_CreateMDIWindow
437 static VOID MAIN_CreateMDIWindow()
439 CLIENTCREATESTRUCT ccs;
442 /* Get the geometry of the MDI window */
443 GetClientRect(Globals.hMainWnd, &rect);
445 ccs.hWindowMenu = Globals.hWindowsMenu;
446 ccs.idFirstChild = PM_FIRST_CHILD;
448 /* Create MDI Window */
450 CreateWindow (STRING_MDI_WIN_CLASS_NAME, "",
451 WS_CHILD, rect.left, rect.top,
452 rect.right - rect.left, rect.bottom - rect.top,
454 Globals.hInstance, &ccs);
456 ShowWindow (Globals.hMDIWnd, SW_SHOW);
457 UpdateWindow (Globals.hMDIWnd);
460 /**********************************************************************/
461 /***********************************************************************
465 INT MAIN_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
467 CHAR text[MAX_STRING_LEN];
468 CHAR title[MAX_STRING_LEN];
470 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
471 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
473 return(MessageBox(Globals.hMainWnd, text, title, type));
476 /***********************************************************************
478 * MAIN_MessageBoxIDS_s
480 INT MAIN_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
482 CHAR text[MAX_STRING_LEN];
483 CHAR title[MAX_STRING_LEN];
484 CHAR newtext[MAX_STRING_LEN + MAX_PATHNAME_LEN];
486 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
487 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
488 wsprintf(newtext, text, str);
490 return(MessageBox(Globals.hMainWnd, newtext, title, type));
493 /***********************************************************************
498 VOID MAIN_ReplaceString(HLOCAL *handle, LPSTR replace)
500 HLOCAL newhandle = LocalAlloc(LMEM_FIXED, strlen(replace) + 1);
503 LPSTR newstring = LocalLock(newhandle);
504 lstrcpy(newstring, replace);
508 else MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
511 /* Local Variables: */
512 /* c-file-style: "GNU" */