4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 static VOID
MAIN_CreateGroups(void);
31 static VOID
MAIN_MenuCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
32 static ATOM
MAIN_RegisterMainWinClass(void);
33 static VOID
MAIN_CreateMainWindow(void);
34 static VOID
MAIN_CreateMDIWindow(void);
35 static VOID
MAIN_AutoStart(void);
37 #define BUFFER_SIZE 1000
39 /***********************************************************************
44 int PASCAL
WinMain (HINSTANCE hInstance
, HINSTANCE prev
, LPSTR cmdline
, int show
)
48 Globals
.lpszIniFile
= "progman.ini";
49 Globals
.lpszIcoFile
= "progman.ico";
52 Globals
.lpszLanguage
= "En";
53 Globals
.hInstance
= hInstance
;
55 Globals
.hActiveGroup
= 0;
57 /* Read Options from `progman.ini' */
58 Globals
.bAutoArrange
=
59 GetPrivateProfileInt("Settings", "AutoArrange", 0, Globals
.lpszIniFile
);
61 GetPrivateProfileInt("Settings", "MinOnRun", 0, Globals
.lpszIniFile
);
62 Globals
.bSaveSettings
=
63 GetPrivateProfileInt("Settings", "SaveSettings", 0, Globals
.lpszIniFile
);
65 /* Load default icons */
66 Globals
.hMainIcon
= ExtractIcon(Globals
.hInstance
, Globals
.lpszIcoFile
, 0);
67 Globals
.hGroupIcon
= ExtractIcon(Globals
.hInstance
, Globals
.lpszIcoFile
, 0);
68 Globals
.hDefaultIcon
= ExtractIcon(Globals
.hInstance
, Globals
.lpszIcoFile
, 0);
69 if (!Globals
.hMainIcon
) Globals
.hMainIcon
= LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON
));
70 if (!Globals
.hGroupIcon
) Globals
.hGroupIcon
= LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON
));
71 if (!Globals
.hDefaultIcon
) Globals
.hDefaultIcon
= LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON
));
73 /* Register classes */
76 if (!MAIN_RegisterMainWinClass()) return(FALSE
);
77 if (!GROUP_RegisterGroupWinClass()) return(FALSE
);
78 if (!PROGRAM_RegisterProgramWinClass()) return(FALSE
);
81 /* Create main window */
82 MAIN_CreateMainWindow();
83 Globals
.hAccel
= LoadAccelerators(Globals
.hInstance
, STRING_ACCEL
);
85 /* Setup menu, stringtable and resourcenames */
86 STRING_SelectLanguageByName(Globals
.lpszLanguage
);
88 MAIN_CreateMDIWindow();
90 /* Initialize groups */
93 /* Start initial applications */
97 while (GetMessage (&msg
, 0, 0, 0))
98 if (!TranslateAccelerator(Globals
.hMainWnd
, Globals
.hAccel
, &msg
))
100 TranslateMessage (&msg
);
101 DispatchMessage (&msg
);
106 /***********************************************************************
111 static VOID
MAIN_CreateGroups()
113 CHAR buffer
[BUFFER_SIZE
];
114 CHAR szPath
[MAX_PATHNAME_LEN
];
117 /* Initialize groups according the `Order' entry of `progman.ini' */
118 GetPrivateProfileString("Settings", "Order", "", buffer
, sizeof(buffer
), Globals
.lpszIniFile
);
120 while (ptr
< buffer
+ sizeof(buffer
))
123 ret
= sscanf(ptr
, "%d%n", &num
, &skip
);
125 MAIN_MessageBoxIDS_s(IDS_FILE_READ_ERROR_s
, Globals
.lpszIniFile
, IDS_ERROR
, MB_OK
);
128 sprintf(key
, "Group%d", num
);
129 GetPrivateProfileString("Groups", key
, "", szPath
,
130 sizeof(szPath
), Globals
.lpszIniFile
);
131 if (!szPath
[0]) continue;
133 GRPFILE_ReadGroupFile(szPath
);
137 /* FIXME initialize other groups, not enumerated by `Order' */
140 /***********************************************************************
145 VOID
MAIN_AutoStart()
147 CHAR buffer
[BUFFER_SIZE
];
148 HLOCAL hGroup
, hProgram
;
150 GetPrivateProfileString("Settings", "AutoStart", "Autostart", buffer
,
151 sizeof(buffer
), Globals
.lpszIniFile
);
153 for (hGroup
= GROUP_FirstGroup(); hGroup
; hGroup
= GROUP_NextGroup(hGroup
))
154 if (!lstrcmp(buffer
, GROUP_GroupName(hGroup
)))
155 for (hProgram
= PROGRAM_FirstProgram(hGroup
); hProgram
;
156 hProgram
= PROGRAM_NextProgram(hProgram
))
157 PROGRAM_ExecuteProgram(hProgram
);
160 /***********************************************************************
165 static LRESULT CALLBACK
MAIN_MainWndProc(HWND hWnd
, UINT msg
,
166 WPARAM wParam
, LPARAM lParam
)
169 printf("M %4.4x %4.4x\n", msg
, wParam
);
174 CheckMenuItem(Globals
.hOptionMenu
, PM_AUTO_ARRANGE
,
175 MF_BYCOMMAND
| (Globals
.bAutoArrange
? MF_CHECKED
: MF_UNCHECKED
));
176 CheckMenuItem(Globals
.hOptionMenu
, PM_MIN_ON_RUN
,
177 MF_BYCOMMAND
| (Globals
.bMinOnRun
? MF_CHECKED
: MF_UNCHECKED
));
178 CheckMenuItem(Globals
.hOptionMenu
, PM_SAVE_SETTINGS
,
179 MF_BYCOMMAND
| (Globals
.bSaveSettings
? MF_CHECKED
: MF_UNCHECKED
));
183 if (wParam
< PM_FIRST_CHILD
)
184 MAIN_MenuCommand(hWnd
, wParam
, lParam
);
191 return(DefFrameProc(hWnd
, Globals
.hMDIWnd
, msg
, wParam
, lParam
));
194 /***********************************************************************
199 static VOID
MAIN_MenuCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
201 HLOCAL hActiveGroup
= GROUP_ActiveGroup();
202 HLOCAL hActiveProgram
= PROGRAM_ActiveProgram(hActiveGroup
);
203 HWND hActiveGroupWnd
= GROUP_GroupWnd(hActiveGroup
);
209 switch (DIALOG_New((hActiveGroupWnd
&& !IsIconic(hActiveGroupWnd
)) ?
210 PM_NEW_PROGRAM
: PM_NEW_GROUP
))
213 if (hActiveGroup
) PROGRAM_NewProgram(hActiveGroup
);
224 PROGRAM_ExecuteProgram(hActiveProgram
);
225 else if (hActiveGroupWnd
)
226 OpenIcon(hActiveGroupWnd
);
232 PROGRAM_CopyMoveProgram(hActiveProgram
, wParam
== PM_MOVE
);
238 if (DIALOG_Delete(IDS_DELETE_PROGRAM_s
, PROGRAM_ProgramName(hActiveProgram
)))
239 PROGRAM_DeleteProgram(hActiveProgram
, TRUE
);
241 else if (hActiveGroup
)
243 if (DIALOG_Delete(IDS_DELETE_GROUP_s
, GROUP_GroupName(hActiveGroup
)))
244 GROUP_DeleteGroup(hActiveGroup
);
250 PROGRAM_ModifyProgram(hActiveProgram
);
251 else if (hActiveGroup
)
252 GROUP_ModifyGroup(hActiveGroup
);
264 case PM_AUTO_ARRANGE
:
265 Globals
.bAutoArrange
= !Globals
.bAutoArrange
;
266 CheckMenuItem(Globals
.hOptionMenu
, PM_AUTO_ARRANGE
,
267 MF_BYCOMMAND
| (Globals
.bAutoArrange
?
268 MF_CHECKED
: MF_UNCHECKED
));
269 WritePrivateProfileString("Settings", "AutoArrange",
270 Globals
.bAutoArrange
? "1" : "0",
271 Globals
.lpszIniFile
);
272 WritePrivateProfileString(NULL
,NULL
,NULL
,Globals
.lpszIniFile
); /* flush it */
276 Globals
.bMinOnRun
= !Globals
.bMinOnRun
;
277 CheckMenuItem(Globals
.hOptionMenu
, PM_MIN_ON_RUN
,
278 MF_BYCOMMAND
| (Globals
.bMinOnRun
?
279 MF_CHECKED
: MF_UNCHECKED
));
280 WritePrivateProfileString("Settings", "MinOnRun",
281 Globals
.bMinOnRun
? "1" : "0",
282 Globals
.lpszIniFile
);
283 WritePrivateProfileString(NULL
,NULL
,NULL
,Globals
.lpszIniFile
); /* flush it */
286 case PM_SAVE_SETTINGS
:
287 Globals
.bSaveSettings
= !Globals
.bSaveSettings
;
288 CheckMenuItem(Globals
.hOptionMenu
, PM_SAVE_SETTINGS
,
289 MF_BYCOMMAND
| (Globals
.bSaveSettings
?
290 MF_CHECKED
: MF_UNCHECKED
));
291 WritePrivateProfileString("Settings", "SaveSettings",
292 Globals
.bSaveSettings
? "1" : "0",
293 Globals
.lpszIniFile
);
294 WritePrivateProfileString(NULL
,NULL
,NULL
,Globals
.lpszIniFile
); /* flush it */
299 if (hActiveGroupWnd
&& !IsIconic(hActiveGroupWnd
))
300 ArrangeIconicWindows(hActiveGroupWnd
);
302 SendMessage(Globals
.hMDIWnd
, WM_MDIICONARRANGE
, 0, 0);
307 if (!WinHelp(Globals
.hMainWnd
, "progman.hlp", HELP_INDEX
, 0))
308 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR
, IDS_ERROR
, MB_OK
);
312 if (!WinHelp(Globals
.hMainWnd
, "progman.hlp", HELP_HELPONHELP
, 0))
313 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR
, IDS_ERROR
, MB_OK
);
317 WinExec("wintutor.exe", SW_SHOWNORMAL
);
321 WineLicense(Globals
.hMainWnd
, Globals
.lpszLanguage
);
325 WineWarranty(Globals
.hMainWnd
, Globals
.lpszLanguage
);
329 ShellAbout(hWnd
, "WINE", "Program Manager", 0);
333 if (wParam
>= PM_FIRST_LANGUAGE
&& wParam
<= PM_LAST_LANGUAGE
)
334 STRING_SelectLanguageByNumber(wParam
- PM_FIRST_LANGUAGE
);
336 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED
, IDS_ERROR
, MB_OK
);
341 /***********************************************************************
343 * MAIN_RegisterMainWinClass
346 static ATOM
MAIN_RegisterMainWinClass()
350 class.style
= CS_HREDRAW
| CS_VREDRAW
;
351 class.lpfnWndProc
= MAIN_MainWndProc
;
352 class.cbClsExtra
= 0;
353 class.cbWndExtra
= 0;
354 class.hInstance
= Globals
.hInstance
;
355 class.hIcon
= Globals
.hMainIcon
;
356 class.hCursor
= LoadCursor (0, IDC_ARROW
);
357 class.hbrBackground
= GetStockObject (NULL_BRUSH
);
358 class.lpszMenuName
= 0;
359 class.lpszClassName
= STRING_MAIN_WIN_CLASS_NAME
;
361 return RegisterClass(&class);
364 /***********************************************************************
366 * MAIN_CreateMainWindow
369 static VOID
MAIN_CreateMainWindow()
371 INT left
, top
, right
, bottom
, width
, height
, show
;
375 Globals
.hMainMenu
= 0;
377 /* Get the geometry of the main window */
378 GetPrivateProfileString("Settings", "Window", "",
379 buffer
, sizeof(buffer
), Globals
.lpszIniFile
);
380 if (5 == sscanf(buffer
, "%d %d %d %d %d", &left
, &top
, &right
, &bottom
, &show
))
382 width
= right
- left
;
383 height
= bottom
- top
;
387 left
= top
= width
= height
= CW_USEDEFAULT
;
388 show
= SW_SHOWNORMAL
;
391 /* Create main Window */
393 CreateWindow (STRING_MAIN_WIN_CLASS_NAME
, "",
394 WS_OVERLAPPEDWINDOW
, left
, top
, width
, height
,
395 0, 0, Globals
.hInstance
, 0);
397 ShowWindow (Globals
.hMainWnd
, show
);
398 UpdateWindow (Globals
.hMainWnd
);
401 /***********************************************************************
403 * MAIN_CreateMDIWindow
406 static VOID
MAIN_CreateMDIWindow()
408 CLIENTCREATESTRUCT ccs
;
411 /* Get the geometry of the MDI window */
412 GetClientRect(Globals
.hMainWnd
, &rect
);
414 ccs
.hWindowMenu
= Globals
.hWindowsMenu
;
415 ccs
.idFirstChild
= PM_FIRST_CHILD
;
417 /* Create MDI Window */
419 CreateWindow (STRING_MDI_WIN_CLASS_NAME
, "",
420 WS_CHILD
, rect
.left
, rect
.top
,
421 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
423 Globals
.hInstance
, &ccs
);
425 ShowWindow (Globals
.hMDIWnd
, SW_SHOW
);
426 UpdateWindow (Globals
.hMDIWnd
);
429 /**********************************************************************/
430 /***********************************************************************
434 INT
MAIN_MessageBoxIDS(UINT ids_text
, UINT ids_title
, WORD type
)
436 CHAR text
[MAX_STRING_LEN
];
437 CHAR title
[MAX_STRING_LEN
];
439 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
440 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
442 return(MessageBox(Globals
.hMainWnd
, text
, title
, type
));
445 /***********************************************************************
447 * MAIN_MessageBoxIDS_s
449 INT
MAIN_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
451 CHAR text
[MAX_STRING_LEN
];
452 CHAR title
[MAX_STRING_LEN
];
453 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATHNAME_LEN
];
455 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
456 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
457 wsprintf(newtext
, text
, str
);
459 return(MessageBox(Globals
.hMainWnd
, newtext
, title
, type
));
462 /***********************************************************************
467 VOID
MAIN_ReplaceString(HLOCAL
*handle
, LPSTR replace
)
469 HLOCAL newhandle
= LocalAlloc(LMEM_FIXED
, strlen(replace
) + 1);
472 LPSTR newstring
= LocalLock(newhandle
);
473 lstrcpy(newstring
, replace
);
477 else MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY
, IDS_ERROR
, MB_OK
);
480 /* Local Variables: */
481 /* c-file-style: "GNU" */