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 (HANDLE hInstance
, HANDLE 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 hmemcpy16(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 hmemcpy16(p
, buffer
, 1 + lstrlen(buffer
));
63 Globals
.lpszLanguage
= Languages
[Options
.language
].name
;
65 Globals
.lpszLanguage
= "En";
68 Globals
.hInstance
= hInstance
;
70 Globals
.hActiveGroup
= 0;
72 /* Read Options from `progman.ini' */
73 Globals
.bAutoArrange
=
74 GetPrivateProfileInt("Settings", "AutoArrange", 0, Globals
.lpszIniFile
);
76 GetPrivateProfileInt("Settings", "MinOnRun", 0, Globals
.lpszIniFile
);
77 Globals
.bSaveSettings
=
78 GetPrivateProfileInt("Settings", "SaveSettings", 0, Globals
.lpszIniFile
);
80 /* Load default icons */
81 Globals
.hMainIcon
= ExtractIcon(Globals
.hInstance
, Globals
.lpszIcoFile
, 0);
82 Globals
.hGroupIcon
= ExtractIcon(Globals
.hInstance
, Globals
.lpszIcoFile
, 0);
83 Globals
.hDefaultIcon
= ExtractIcon(Globals
.hInstance
, Globals
.lpszIcoFile
, 0);
84 if (!Globals
.hMainIcon
) Globals
.hMainIcon
= LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON
));
85 if (!Globals
.hGroupIcon
) Globals
.hGroupIcon
= LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON
));
86 if (!Globals
.hDefaultIcon
) Globals
.hDefaultIcon
= LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON
));
88 /* Register classes */
91 if (!MAIN_RegisterMainWinClass()) return(FALSE
);
92 if (!GROUP_RegisterGroupWinClass()) return(FALSE
);
93 if (!PROGRAM_RegisterProgramWinClass()) return(FALSE
);
96 /* Create main window */
97 MAIN_CreateMainWindow();
98 Globals
.hAccel
= LoadAccelerators(Globals
.hInstance
, STRING_ACCEL
);
100 /* Setup menu, stringtable and resourcenames */
101 STRING_SelectLanguageByName(Globals
.lpszLanguage
);
103 MAIN_CreateMDIWindow();
105 /* Initialize groups */
108 /* Start initial applications */
112 while (GetMessage (&msg
, 0, 0, 0))
113 if (!TranslateAccelerator(Globals
.hMainWnd
, Globals
.hAccel
, &msg
))
115 TranslateMessage (&msg
);
116 DispatchMessage (&msg
);
121 /***********************************************************************
126 static VOID
MAIN_CreateGroups()
128 CHAR buffer
[BUFFER_SIZE
];
129 CHAR szPath
[MAX_PATHNAME_LEN
];
132 /* Initialize groups according the `Order' entry of `progman.ini' */
133 GetPrivateProfileString("Settings", "Order", "", buffer
, sizeof(buffer
), Globals
.lpszIniFile
);
135 while (ptr
< buffer
+ sizeof(buffer
))
138 ret
= sscanf(ptr
, "%d%n", &num
, &skip
);
140 MAIN_MessageBoxIDS_s(IDS_FILE_READ_ERROR_s
, Globals
.lpszIniFile
, IDS_ERROR
, MB_OK
);
143 sprintf(key
, "Group%d", num
);
144 GetPrivateProfileString("Groups", key
, "", szPath
,
145 sizeof(szPath
), Globals
.lpszIniFile
);
146 if (!szPath
[0]) continue;
148 GRPFILE_ReadGroupFile(szPath
);
152 /* FIXME initialize other groups, not enumerated by `Order' */
155 /***********************************************************************
160 VOID
MAIN_AutoStart()
162 CHAR buffer
[BUFFER_SIZE
];
163 HLOCAL hGroup
, hProgram
;
165 GetPrivateProfileString("Settings", "AutoStart", "Autostart", buffer
,
166 sizeof(buffer
), Globals
.lpszIniFile
);
168 for (hGroup
= GROUP_FirstGroup(); hGroup
; hGroup
= GROUP_NextGroup(hGroup
))
169 if (!lstrcmp(buffer
, GROUP_GroupName(hGroup
)))
170 for (hProgram
= PROGRAM_FirstProgram(hGroup
); hProgram
;
171 hProgram
= PROGRAM_NextProgram(hProgram
))
172 PROGRAM_ExecuteProgram(hProgram
);
175 /***********************************************************************
180 static LRESULT
MAIN_MainWndProc (HWND hWnd
, UINT msg
,
181 WPARAM wParam
, LPARAM lParam
)
184 printf("M %4.4x %4.4x\n", msg
, wParam
);
189 CheckMenuItem(Globals
.hOptionMenu
, PM_AUTO_ARRANGE
,
190 MF_BYCOMMAND
| (Globals
.bAutoArrange
? MF_CHECKED
: MF_UNCHECKED
));
191 CheckMenuItem(Globals
.hOptionMenu
, PM_MIN_ON_RUN
,
192 MF_BYCOMMAND
| (Globals
.bMinOnRun
? MF_CHECKED
: MF_UNCHECKED
));
193 CheckMenuItem(Globals
.hOptionMenu
, PM_SAVE_SETTINGS
,
194 MF_BYCOMMAND
| (Globals
.bSaveSettings
? MF_CHECKED
: MF_UNCHECKED
));
198 if (wParam
< PM_FIRST_CHILD
)
199 MAIN_MenuCommand(hWnd
, wParam
, lParam
);
206 return(DefFrameProc(hWnd
, Globals
.hMDIWnd
, msg
, wParam
, lParam
));
209 /***********************************************************************
214 static VOID
MAIN_MenuCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
216 HLOCAL hActiveGroup
= GROUP_ActiveGroup();
217 HLOCAL hActiveProgram
= PROGRAM_ActiveProgram(hActiveGroup
);
218 HWND hActiveGroupWnd
= GROUP_GroupWnd(hActiveGroup
);
224 switch (DIALOG_New((hActiveGroupWnd
&& !IsIconic(hActiveGroupWnd
)) ?
225 PM_NEW_PROGRAM
: PM_NEW_GROUP
))
228 if (hActiveGroup
) PROGRAM_NewProgram(hActiveGroup
);
239 PROGRAM_ExecuteProgram(hActiveProgram
);
240 else if (hActiveGroupWnd
)
241 OpenIcon(hActiveGroupWnd
);
247 PROGRAM_CopyMoveProgram(hActiveProgram
, wParam
== PM_MOVE
);
253 if (DIALOG_Delete(IDS_DELETE_PROGRAM_s
, PROGRAM_ProgramName(hActiveProgram
)))
254 PROGRAM_DeleteProgram(hActiveProgram
, TRUE
);
256 else if (hActiveGroup
)
258 if (DIALOG_Delete(IDS_DELETE_GROUP_s
, GROUP_GroupName(hActiveGroup
)))
259 GROUP_DeleteGroup(hActiveGroup
);
265 PROGRAM_ModifyProgram(hActiveProgram
);
266 else if (hActiveGroup
)
267 GROUP_ModifyGroup(hActiveGroup
);
279 case PM_AUTO_ARRANGE
:
280 Globals
.bAutoArrange
= !Globals
.bAutoArrange
;
281 CheckMenuItem(Globals
.hOptionMenu
, PM_AUTO_ARRANGE
,
282 MF_BYCOMMAND
| (Globals
.bAutoArrange
?
283 MF_CHECKED
: MF_UNCHECKED
));
284 WritePrivateProfileString("Settings", "AutoArrange",
285 Globals
.bAutoArrange
? "1" : "0",
286 Globals
.lpszIniFile
);
287 WriteOutProfiles16();
291 Globals
.bMinOnRun
= !Globals
.bMinOnRun
;
292 CheckMenuItem(Globals
.hOptionMenu
, PM_MIN_ON_RUN
,
293 MF_BYCOMMAND
| (Globals
.bMinOnRun
?
294 MF_CHECKED
: MF_UNCHECKED
));
295 WritePrivateProfileString("Settings", "MinOnRun",
296 Globals
.bMinOnRun
? "1" : "0",
297 Globals
.lpszIniFile
);
298 WriteOutProfiles16();
301 case PM_SAVE_SETTINGS
:
302 Globals
.bSaveSettings
= !Globals
.bSaveSettings
;
303 CheckMenuItem(Globals
.hOptionMenu
, PM_SAVE_SETTINGS
,
304 MF_BYCOMMAND
| (Globals
.bSaveSettings
?
305 MF_CHECKED
: MF_UNCHECKED
));
306 WritePrivateProfileString("Settings", "SaveSettings",
307 Globals
.bSaveSettings
? "1" : "0",
308 Globals
.lpszIniFile
);
309 WriteOutProfiles16();
314 if (hActiveGroupWnd
&& !IsIconic(hActiveGroupWnd
))
315 ArrangeIconicWindows(hActiveGroupWnd
);
317 SendMessage(Globals
.hMDIWnd
, WM_MDIICONARRANGE
, 0, 0);
322 if (!WinHelp(Globals
.hMainWnd
, "progman.hlp", HELP_INDEX
, 0))
323 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR
, IDS_ERROR
, MB_OK
);
327 if (!WinHelp(Globals
.hMainWnd
, "progman.hlp", HELP_HELPONHELP
, 0))
328 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR
, IDS_ERROR
, MB_OK
);
332 WinExec("wintutor.exe", SW_SHOWNORMAL
);
336 WineLicense(Globals
.hMainWnd
, Globals
.lpszLanguage
);
340 WineWarranty(Globals
.hMainWnd
, Globals
.lpszLanguage
);
344 ShellAbout(hWnd
, "WINE", "Program Manager", 0);
348 if (wParam
>= PM_FIRST_LANGUAGE
&& wParam
<= PM_LAST_LANGUAGE
)
349 STRING_SelectLanguageByNumber(wParam
- PM_FIRST_LANGUAGE
);
351 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED
, IDS_ERROR
, MB_OK
);
356 /***********************************************************************
358 * MAIN_RegisterMainWinClass
361 static ATOM
MAIN_RegisterMainWinClass()
365 class.style
= CS_HREDRAW
| CS_VREDRAW
;
366 class.lpfnWndProc
= MAIN_MainWndProc
;
367 class.cbClsExtra
= 0;
368 class.cbWndExtra
= 0;
369 class.hInstance
= Globals
.hInstance
;
370 class.hIcon
= Globals
.hMainIcon
;
371 class.hCursor
= LoadCursor (0, IDC_ARROW
);
372 class.hbrBackground
= GetStockObject (NULL_BRUSH
);
373 class.lpszMenuName
= 0;
374 class.lpszClassName
= STRING_MAIN_WIN_CLASS_NAME
;
376 return RegisterClass(&class);
379 /***********************************************************************
381 * MAIN_CreateMainWindow
384 static VOID
MAIN_CreateMainWindow()
386 INT left
, top
, right
, bottom
, width
, height
, show
;
390 Globals
.hMainMenu
= 0;
392 /* Get the geometry of the main window */
393 GetPrivateProfileString("Settings", "Window", "",
394 buffer
, sizeof(buffer
), Globals
.lpszIniFile
);
395 if (5 == sscanf(buffer
, "%d %d %d %d %d", &left
, &top
, &right
, &bottom
, &show
))
397 width
= right
- left
;
398 height
= bottom
- top
;
402 left
= top
= width
= height
= CW_USEDEFAULT
;
403 show
= SW_SHOWNORMAL
;
406 /* Create main Window */
408 CreateWindow (STRING_MAIN_WIN_CLASS_NAME
, "",
409 WS_OVERLAPPEDWINDOW
, left
, top
, width
, height
,
410 0, 0, Globals
.hInstance
, 0);
412 ShowWindow (Globals
.hMainWnd
, show
);
413 UpdateWindow (Globals
.hMainWnd
);
416 /***********************************************************************
418 * MAIN_CreateMDIWindow
421 static VOID
MAIN_CreateMDIWindow()
423 CLIENTCREATESTRUCT ccs
;
426 /* Get the geometry of the MDI window */
427 GetClientRect(Globals
.hMainWnd
, &rect
);
429 ccs
.hWindowMenu
= Globals
.hWindowsMenu
;
430 ccs
.idFirstChild
= PM_FIRST_CHILD
;
432 /* Create MDI Window */
434 CreateWindow (STRING_MDI_WIN_CLASS_NAME
, "",
435 WS_CHILD
, rect
.left
, rect
.top
,
436 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
438 Globals
.hInstance
, &ccs
);
440 ShowWindow (Globals
.hMDIWnd
, SW_SHOW
);
441 UpdateWindow (Globals
.hMDIWnd
);
444 /**********************************************************************/
445 /***********************************************************************
449 INT
MAIN_MessageBoxIDS(UINT ids_text
, UINT ids_title
, WORD type
)
451 CHAR text
[MAX_STRING_LEN
];
452 CHAR title
[MAX_STRING_LEN
];
454 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
455 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
457 return(MessageBox(Globals
.hMainWnd
, text
, title
, type
));
460 /***********************************************************************
462 * MAIN_MessageBoxIDS_s
464 INT
MAIN_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
466 CHAR text
[MAX_STRING_LEN
];
467 CHAR title
[MAX_STRING_LEN
];
468 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATHNAME_LEN
];
470 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
471 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
472 wsprintf(newtext
, text
, str
);
474 return(MessageBox(Globals
.hMainWnd
, newtext
, title
, type
));
477 /***********************************************************************
482 VOID
MAIN_ReplaceString(HLOCAL
*handle
, LPSTR replace
)
484 HLOCAL newhandle
= LocalAlloc(LMEM_FIXED
, strlen(replace
) + 1);
487 LPSTR newstring
= LocalLock(newhandle
);
488 lstrcpy(newstring
, replace
);
492 else MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY
, IDS_ERROR
, MB_OK
);
495 /* Local Variables: */
496 /* c-file-style: "GNU" */