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);
39 #define BUFFER_SIZE 1000
41 /***********************************************************************
46 int PASCAL
WinMain (HINSTANCE hInstance
, HINSTANCE prev
, LPSTR cmdline
, int show
)
50 Globals
.lpszIniFile
= "progman.ini";
51 Globals
.lpszIcoFile
= "progman.ico";
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 */
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(void)
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(void)
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 (LOWORD(wParam
) < PM_FIRST_CHILD
){
184 MAIN_MenuCommand(hWnd
, LOWORD(wParam
), lParam
);
192 return(DefFrameProc(hWnd
, Globals
.hMDIWnd
, msg
, wParam
, lParam
));
195 /***********************************************************************
200 static VOID
MAIN_MenuCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
202 HLOCAL hActiveGroup
= GROUP_ActiveGroup();
203 HLOCAL hActiveProgram
= PROGRAM_ActiveProgram(hActiveGroup
);
204 HWND hActiveGroupWnd
= GROUP_GroupWnd(hActiveGroup
);
210 switch (DIALOG_New((hActiveGroupWnd
&& !IsIconic(hActiveGroupWnd
)) ?
211 PM_NEW_PROGRAM
: PM_NEW_GROUP
))
214 if (hActiveGroup
) PROGRAM_NewProgram(hActiveGroup
);
225 PROGRAM_ExecuteProgram(hActiveProgram
);
226 else if (hActiveGroupWnd
)
227 OpenIcon(hActiveGroupWnd
);
233 PROGRAM_CopyMoveProgram(hActiveProgram
, wParam
== PM_MOVE
);
239 if (DIALOG_Delete(IDS_DELETE_PROGRAM_s
, PROGRAM_ProgramName(hActiveProgram
)))
240 PROGRAM_DeleteProgram(hActiveProgram
, TRUE
);
242 else if (hActiveGroup
)
244 if (DIALOG_Delete(IDS_DELETE_GROUP_s
, GROUP_GroupName(hActiveGroup
)))
245 GROUP_DeleteGroup(hActiveGroup
);
251 PROGRAM_ModifyProgram(hActiveProgram
);
252 else if (hActiveGroup
)
253 GROUP_ModifyGroup(hActiveGroup
);
265 case PM_AUTO_ARRANGE
:
266 Globals
.bAutoArrange
= !Globals
.bAutoArrange
;
267 CheckMenuItem(Globals
.hOptionMenu
, PM_AUTO_ARRANGE
,
268 MF_BYCOMMAND
| (Globals
.bAutoArrange
?
269 MF_CHECKED
: MF_UNCHECKED
));
270 WritePrivateProfileString("Settings", "AutoArrange",
271 Globals
.bAutoArrange
? "1" : "0",
272 Globals
.lpszIniFile
);
273 WritePrivateProfileString(NULL
,NULL
,NULL
,Globals
.lpszIniFile
); /* flush it */
277 Globals
.bMinOnRun
= !Globals
.bMinOnRun
;
278 CheckMenuItem(Globals
.hOptionMenu
, PM_MIN_ON_RUN
,
279 MF_BYCOMMAND
| (Globals
.bMinOnRun
?
280 MF_CHECKED
: MF_UNCHECKED
));
281 WritePrivateProfileString("Settings", "MinOnRun",
282 Globals
.bMinOnRun
? "1" : "0",
283 Globals
.lpszIniFile
);
284 WritePrivateProfileString(NULL
,NULL
,NULL
,Globals
.lpszIniFile
); /* flush it */
287 case PM_SAVE_SETTINGS
:
288 Globals
.bSaveSettings
= !Globals
.bSaveSettings
;
289 CheckMenuItem(Globals
.hOptionMenu
, PM_SAVE_SETTINGS
,
290 MF_BYCOMMAND
| (Globals
.bSaveSettings
?
291 MF_CHECKED
: MF_UNCHECKED
));
292 WritePrivateProfileString("Settings", "SaveSettings",
293 Globals
.bSaveSettings
? "1" : "0",
294 Globals
.lpszIniFile
);
295 WritePrivateProfileString(NULL
,NULL
,NULL
,Globals
.lpszIniFile
); /* flush it */
300 SendMessageW(Globals
.hMDIWnd
, WM_MDICASCADE
, 0, 0);
303 case PM_SIDE_BY_SIDE
:
304 SendMessageW(Globals
.hMDIWnd
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
309 if (hActiveGroupWnd
&& !IsIconic(hActiveGroupWnd
))
310 ArrangeIconicWindows(hActiveGroupWnd
);
312 SendMessage(Globals
.hMDIWnd
, WM_MDIICONARRANGE
, 0, 0);
317 if (!WinHelp(Globals
.hMainWnd
, "progman.hlp", HELP_CONTENTS
, 0))
318 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR
, IDS_ERROR
, MB_OK
);
322 ShellAbout(hWnd
, "WINE", "Program Manager", 0);
326 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED
, IDS_ERROR
, MB_OK
);
331 /***********************************************************************
333 * MAIN_RegisterMainWinClass
336 static ATOM
MAIN_RegisterMainWinClass(void)
340 class.style
= CS_HREDRAW
| CS_VREDRAW
;
341 class.lpfnWndProc
= MAIN_MainWndProc
;
342 class.cbClsExtra
= 0;
343 class.cbWndExtra
= 0;
344 class.hInstance
= Globals
.hInstance
;
345 class.hIcon
= Globals
.hMainIcon
;
346 class.hCursor
= LoadCursor (0, IDC_ARROW
);
347 class.hbrBackground
= GetStockObject (NULL_BRUSH
);
348 class.lpszMenuName
= 0;
349 class.lpszClassName
= STRING_MAIN_WIN_CLASS_NAME
;
351 return RegisterClass(&class);
354 /***********************************************************************
356 * MAIN_CreateMainWindow
359 static VOID
MAIN_CreateMainWindow(void)
361 INT left
, top
, right
, bottom
, width
, height
, show
;
365 Globals
.hMainMenu
= 0;
367 /* Get the geometry of the main window */
368 GetPrivateProfileString("Settings", "Window", "",
369 buffer
, sizeof(buffer
), Globals
.lpszIniFile
);
370 if (5 == sscanf(buffer
, "%d %d %d %d %d", &left
, &top
, &right
, &bottom
, &show
))
372 width
= right
- left
;
373 height
= bottom
- top
;
377 left
= top
= width
= height
= CW_USEDEFAULT
;
378 show
= SW_SHOWNORMAL
;
381 /* Create main Window */
383 CreateWindow (STRING_MAIN_WIN_CLASS_NAME
, "",
384 WS_OVERLAPPEDWINDOW
, left
, top
, width
, height
,
385 0, 0, Globals
.hInstance
, 0);
387 ShowWindow (Globals
.hMainWnd
, show
);
388 UpdateWindow (Globals
.hMainWnd
);
391 /***********************************************************************
393 * MAIN_CreateMDIWindow
396 static VOID
MAIN_CreateMDIWindow(void)
398 CLIENTCREATESTRUCT ccs
;
401 /* Get the geometry of the MDI window */
402 GetClientRect(Globals
.hMainWnd
, &rect
);
404 ccs
.hWindowMenu
= Globals
.hWindowsMenu
;
405 ccs
.idFirstChild
= PM_FIRST_CHILD
;
407 /* Create MDI Window */
409 CreateWindow (STRING_MDI_WIN_CLASS_NAME
, "",
410 WS_CHILD
, rect
.left
, rect
.top
,
411 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
413 Globals
.hInstance
, &ccs
);
415 ShowWindow (Globals
.hMDIWnd
, SW_SHOW
);
416 UpdateWindow (Globals
.hMDIWnd
);
419 /**********************************************************************/
420 /***********************************************************************
424 INT
MAIN_MessageBoxIDS(UINT ids_text
, UINT ids_title
, WORD type
)
426 CHAR text
[MAX_STRING_LEN
];
427 CHAR title
[MAX_STRING_LEN
];
429 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
430 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
432 return(MessageBox(Globals
.hMainWnd
, text
, title
, type
));
435 /***********************************************************************
437 * MAIN_MessageBoxIDS_s
439 INT
MAIN_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
441 CHAR text
[MAX_STRING_LEN
];
442 CHAR title
[MAX_STRING_LEN
];
443 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATHNAME_LEN
];
445 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
446 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
447 wsprintf(newtext
, text
, str
);
449 return(MessageBox(Globals
.hMainWnd
, newtext
, title
, type
));
452 /***********************************************************************
457 VOID
MAIN_ReplaceString(HLOCAL
*handle
, LPSTR replace
)
459 HLOCAL newhandle
= LocalAlloc(LMEM_FIXED
, strlen(replace
) + 1);
462 LPSTR newstring
= LocalLock(newhandle
);
463 lstrcpy(newstring
, replace
);
467 else MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY
, IDS_ERROR
, MB_OK
);
470 /* Local Variables: */
471 /* c-file-style: "GNU" */