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();
20 void LIBWINE_Register_It();
21 void LIBWINE_Register_Ko();
22 void LIBWINE_Register_Hu();
27 static VOID
MAIN_CreateGroups(void);
28 static VOID
MAIN_MenuCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
29 static ATOM
MAIN_RegisterMainWinClass(void);
30 static VOID
MAIN_CreateMainWindow(void);
31 static VOID
MAIN_CreateMDIWindow(void);
32 static VOID
MAIN_AutoStart(void);
34 #define BUFFER_SIZE 1000
36 /***********************************************************************
41 int PASCAL
WinMain (HANDLE hInstance
, HANDLE prev
, LPSTR cmdline
, int show
)
45 #if defined(WINELIB) && !defined(HAVE_WINE_CONSTRUCTOR)
46 /* Register resources */
47 LIBWINE_Register_accel();
48 LIBWINE_Register_De();
49 LIBWINE_Register_En();
50 LIBWINE_Register_Fi();
51 LIBWINE_Register_Fr();
52 LIBWINE_Register_It();
53 LIBWINE_Register_Ko();
54 LIBWINE_Register_Hu();
58 Globals
.lpszIniFile
= "progman.ini";
59 Globals
.lpszIcoFile
= "progman.ico";
60 #else /* Configuration in `wine.ini' */
62 CHAR buffer
[MAX_PATHNAME_LEN
], *p
;
64 /* Redirect `progman.ini' */
65 PROFILE_GetWineIniString("progman", "progman.ini", "progman.ini",
66 buffer
, sizeof(buffer
));
67 Globals
.lpszIniFile
= p
= LocalLock(LocalAlloc(LMEM_FIXED
, lstrlen(buffer
)));
68 hmemcpy(p
, buffer
, 1 + lstrlen(buffer
));
70 /* Redirect `progman.ico' */
71 PROFILE_GetWineIniString("progman", "progman.ico", "progman.ico",
72 buffer
, sizeof(buffer
));
73 Globals
.lpszIcoFile
= p
= LocalLock(LocalAlloc(LMEM_FIXED
, lstrlen(buffer
)));
74 hmemcpy(p
, buffer
, 1 + lstrlen(buffer
));
80 Globals
.lpszLanguage
= Languages
[Options
.language
].name
;
82 Globals
.lpszLanguage
= "En";
85 Globals
.hInstance
= hInstance
;
87 Globals
.hActiveGroup
= 0;
89 /* Read Options from `progman.ini' */
90 Globals
.bAutoArrange
=
91 GetPrivateProfileInt("Settings", "AutoArrange", 0, Globals
.lpszIniFile
);
93 GetPrivateProfileInt("Settings", "MinOnRun", 0, Globals
.lpszIniFile
);
94 Globals
.bSaveSettings
=
95 GetPrivateProfileInt("Settings", "SaveSettings", 0, Globals
.lpszIniFile
);
97 /* Load default icons */
98 Globals
.hMainIcon
= ExtractIcon(Globals
.hInstance
, Globals
.lpszIcoFile
, 0);
99 Globals
.hGroupIcon
= ExtractIcon(Globals
.hInstance
, Globals
.lpszIcoFile
, 0);
100 Globals
.hDefaultIcon
= ExtractIcon(Globals
.hInstance
, Globals
.lpszIcoFile
, 0);
101 if (!Globals
.hMainIcon
) Globals
.hMainIcon
= LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON
));
102 if (!Globals
.hGroupIcon
) Globals
.hGroupIcon
= LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON
));
103 if (!Globals
.hDefaultIcon
) Globals
.hDefaultIcon
= LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON
));
105 /* Register classes */
108 if (!MAIN_RegisterMainWinClass()) return(FALSE
);
109 if (!GROUP_RegisterGroupWinClass()) return(FALSE
);
110 if (!PROGRAM_RegisterProgramWinClass()) return(FALSE
);
113 /* Create main window */
114 MAIN_CreateMainWindow();
115 Globals
.hAccel
= LoadAccelerators(Globals
.hInstance
, STRING_ACCEL
);
117 /* Setup menu, stringtable and resourcenames */
118 STRING_SelectLanguageByName(Globals
.lpszLanguage
);
120 MAIN_CreateMDIWindow();
122 /* Initialize groups */
125 /* Start initial applications */
129 while (GetMessage (&msg
, 0, 0, 0))
130 if (!TranslateAccelerator(Globals
.hMainWnd
, Globals
.hAccel
, &msg
))
132 TranslateMessage (&msg
);
133 DispatchMessage (&msg
);
138 /***********************************************************************
143 static VOID
MAIN_CreateGroups()
145 CHAR buffer
[BUFFER_SIZE
];
146 CHAR szPath
[MAX_PATHNAME_LEN
];
149 /* Initialize groups according the `Order' entry of `progman.ini' */
150 GetPrivateProfileString("Settings", "Order", "", buffer
, sizeof(buffer
), Globals
.lpszIniFile
);
152 while (ptr
< buffer
+ sizeof(buffer
))
155 ret
= sscanf(ptr
, "%d%n", &num
, &skip
);
157 MAIN_MessageBoxIDS_s(IDS_FILE_READ_ERROR_s
, Globals
.lpszIniFile
, IDS_ERROR
, MB_OK
);
160 sprintf(key
, "Group%d", num
);
161 GetPrivateProfileString("Groups", key
, "", szPath
,
162 sizeof(szPath
), Globals
.lpszIniFile
);
163 if (!szPath
[0]) continue;
165 GRPFILE_ReadGroupFile(szPath
);
169 /* FIXME initialize other groups, not enumerated by `Order' */
172 /***********************************************************************
177 VOID
MAIN_AutoStart()
179 CHAR buffer
[BUFFER_SIZE
];
180 HLOCAL hGroup
, hProgram
;
182 GetPrivateProfileString("Settings", "AutoStart", "Autostart", buffer
,
183 sizeof(buffer
), Globals
.lpszIniFile
);
185 for (hGroup
= GROUP_FirstGroup(); hGroup
; hGroup
= GROUP_NextGroup(hGroup
))
186 if (!lstrcmp(buffer
, GROUP_GroupName(hGroup
)))
187 for (hProgram
= PROGRAM_FirstProgram(hGroup
); hProgram
;
188 hProgram
= PROGRAM_NextProgram(hProgram
))
189 PROGRAM_ExecuteProgram(hProgram
);
192 /***********************************************************************
197 static LRESULT
MAIN_MainWndProc (HWND hWnd
, UINT msg
,
198 WPARAM wParam
, LPARAM lParam
)
201 printf("M %4.4x %4.4x\n", msg
, wParam
);
206 CheckMenuItem(Globals
.hOptionMenu
, PM_AUTO_ARRANGE
,
207 MF_BYCOMMAND
| (Globals
.bAutoArrange
? MF_CHECKED
: MF_UNCHECKED
));
208 CheckMenuItem(Globals
.hOptionMenu
, PM_MIN_ON_RUN
,
209 MF_BYCOMMAND
| (Globals
.bMinOnRun
? MF_CHECKED
: MF_UNCHECKED
));
210 CheckMenuItem(Globals
.hOptionMenu
, PM_SAVE_SETTINGS
,
211 MF_BYCOMMAND
| (Globals
.bSaveSettings
? MF_CHECKED
: MF_UNCHECKED
));
215 if (wParam
< PM_FIRST_CHILD
)
216 MAIN_MenuCommand(hWnd
, wParam
, lParam
);
223 return(DefFrameProc(hWnd
, Globals
.hMDIWnd
, msg
, wParam
, lParam
));
226 /***********************************************************************
231 static VOID
MAIN_MenuCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
233 HLOCAL hActiveGroup
= GROUP_ActiveGroup();
234 HLOCAL hActiveProgram
= PROGRAM_ActiveProgram(hActiveGroup
);
235 HWND hActiveGroupWnd
= GROUP_GroupWnd(hActiveGroup
);
241 switch (DIALOG_New((hActiveGroupWnd
&& !IsIconic(hActiveGroupWnd
)) ?
242 PM_NEW_PROGRAM
: PM_NEW_GROUP
))
245 if (hActiveGroup
) PROGRAM_NewProgram(hActiveGroup
);
256 PROGRAM_ExecuteProgram(hActiveProgram
);
257 else if (hActiveGroupWnd
)
258 OpenIcon(hActiveGroupWnd
);
264 PROGRAM_CopyMoveProgram(hActiveProgram
, wParam
== PM_MOVE
);
270 if (DIALOG_Delete(IDS_DELETE_PROGRAM_s
, PROGRAM_ProgramName(hActiveProgram
)))
271 PROGRAM_DeleteProgram(hActiveProgram
, TRUE
);
273 else if (hActiveGroup
)
275 if (DIALOG_Delete(IDS_DELETE_GROUP_s
, GROUP_GroupName(hActiveGroup
)))
276 GROUP_DeleteGroup(hActiveGroup
);
282 PROGRAM_ModifyProgram(hActiveProgram
);
283 else if (hActiveGroup
)
284 GROUP_ModifyGroup(hActiveGroup
);
296 case PM_AUTO_ARRANGE
:
297 Globals
.bAutoArrange
= !Globals
.bAutoArrange
;
298 CheckMenuItem(Globals
.hOptionMenu
, PM_AUTO_ARRANGE
,
299 MF_BYCOMMAND
| (Globals
.bAutoArrange
?
300 MF_CHECKED
: MF_UNCHECKED
));
301 WritePrivateProfileString("Settings", "AutoArrange",
302 Globals
.bAutoArrange
? "1" : "0",
303 Globals
.lpszIniFile
);
308 Globals
.bMinOnRun
= !Globals
.bMinOnRun
;
309 CheckMenuItem(Globals
.hOptionMenu
, PM_MIN_ON_RUN
,
310 MF_BYCOMMAND
| (Globals
.bMinOnRun
?
311 MF_CHECKED
: MF_UNCHECKED
));
312 WritePrivateProfileString("Settings", "MinOnRun",
313 Globals
.bMinOnRun
? "1" : "0",
314 Globals
.lpszIniFile
);
318 case PM_SAVE_SETTINGS
:
319 Globals
.bSaveSettings
= !Globals
.bSaveSettings
;
320 CheckMenuItem(Globals
.hOptionMenu
, PM_SAVE_SETTINGS
,
321 MF_BYCOMMAND
| (Globals
.bSaveSettings
?
322 MF_CHECKED
: MF_UNCHECKED
));
323 WritePrivateProfileString("Settings", "SaveSettings",
324 Globals
.bSaveSettings
? "1" : "0",
325 Globals
.lpszIniFile
);
331 if (hActiveGroupWnd
&& !IsIconic(hActiveGroupWnd
))
332 ArrangeIconicWindows(hActiveGroupWnd
);
334 SendMessage(Globals
.hMDIWnd
, WM_MDIICONARRANGE
, 0, 0);
339 if (!WinHelp(Globals
.hMainWnd
, "progman.hlp", HELP_INDEX
, 0))
340 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR
, IDS_ERROR
, MB_OK
);
344 if (!WinHelp(Globals
.hMainWnd
, "progman.hlp", HELP_HELPONHELP
, 0))
345 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR
, IDS_ERROR
, MB_OK
);
349 WinExec("wintutor.exe", SW_SHOWNORMAL
);
353 WineLicense(Globals
.hMainWnd
, Globals
.lpszLanguage
);
357 WineWarranty(Globals
.hMainWnd
, Globals
.lpszLanguage
);
361 ShellAbout(hWnd
, "WINE", "Program Manager", 0);
365 if (wParam
>= PM_FIRST_LANGUAGE
&& wParam
<= PM_LAST_LANGUAGE
)
366 STRING_SelectLanguageByNumber(wParam
- PM_FIRST_LANGUAGE
);
368 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED
, IDS_ERROR
, MB_OK
);
373 /***********************************************************************
375 * MAIN_RegisterMainWinClass
378 static ATOM
MAIN_RegisterMainWinClass()
382 class.style
= CS_HREDRAW
| CS_VREDRAW
;
383 class.lpfnWndProc
= MAIN_MainWndProc
;
384 class.cbClsExtra
= 0;
385 class.cbWndExtra
= 0;
386 class.hInstance
= Globals
.hInstance
;
387 class.hIcon
= Globals
.hMainIcon
;
388 class.hCursor
= LoadCursor (0, IDC_ARROW
);
389 class.hbrBackground
= GetStockObject (NULL_BRUSH
);
390 class.lpszMenuName
= 0;
391 class.lpszClassName
= STRING_MAIN_WIN_CLASS_NAME
;
393 return RegisterClass(&class);
396 /***********************************************************************
398 * MAIN_CreateMainWindow
401 static VOID
MAIN_CreateMainWindow()
403 INT left
, top
, right
, bottom
, width
, height
, show
;
407 Globals
.hMainMenu
= 0;
409 /* Get the geometry of the main window */
410 GetPrivateProfileString("Settings", "Window", "",
411 buffer
, sizeof(buffer
), Globals
.lpszIniFile
);
412 if (5 == sscanf(buffer
, "%d %d %d %d %d", &left
, &top
, &right
, &bottom
, &show
))
414 width
= right
- left
;
415 height
= bottom
- top
;
419 left
= top
= width
= height
= CW_USEDEFAULT
;
420 show
= SW_SHOWNORMAL
;
423 /* Create main Window */
425 CreateWindow (STRING_MAIN_WIN_CLASS_NAME
, "",
426 WS_OVERLAPPEDWINDOW
, left
, top
, width
, height
,
427 0, 0, Globals
.hInstance
, 0);
429 ShowWindow (Globals
.hMainWnd
, show
);
430 UpdateWindow (Globals
.hMainWnd
);
433 /***********************************************************************
435 * MAIN_CreateMDIWindow
438 static VOID
MAIN_CreateMDIWindow()
440 CLIENTCREATESTRUCT ccs
;
443 /* Get the geometry of the MDI window */
444 GetClientRect(Globals
.hMainWnd
, &rect
);
446 ccs
.hWindowMenu
= Globals
.hWindowsMenu
;
447 ccs
.idFirstChild
= PM_FIRST_CHILD
;
449 /* Create MDI Window */
451 CreateWindow (STRING_MDI_WIN_CLASS_NAME
, "",
452 WS_CHILD
, rect
.left
, rect
.top
,
453 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
455 Globals
.hInstance
, &ccs
);
457 ShowWindow (Globals
.hMDIWnd
, SW_SHOW
);
458 UpdateWindow (Globals
.hMDIWnd
);
461 /**********************************************************************/
462 /***********************************************************************
466 INT
MAIN_MessageBoxIDS(UINT ids_text
, UINT ids_title
, WORD type
)
468 CHAR text
[MAX_STRING_LEN
];
469 CHAR title
[MAX_STRING_LEN
];
471 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
472 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
474 return(MessageBox(Globals
.hMainWnd
, text
, title
, type
));
477 /***********************************************************************
479 * MAIN_MessageBoxIDS_s
481 INT
MAIN_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
483 CHAR text
[MAX_STRING_LEN
];
484 CHAR title
[MAX_STRING_LEN
];
485 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATHNAME_LEN
];
487 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
488 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
489 wsprintf(newtext
, text
, str
);
491 return(MessageBox(Globals
.hMainWnd
, newtext
, title
, type
));
494 /***********************************************************************
499 VOID
MAIN_ReplaceString(HLOCAL
*handle
, LPSTR replace
)
501 HLOCAL newhandle
= LocalAlloc(LMEM_FIXED
, strlen(replace
) + 1);
504 LPSTR newstring
= LocalLock(newhandle
);
505 lstrcpy(newstring
, replace
);
509 else MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY
, IDS_ERROR
, MB_OK
);
512 /* Local Variables: */
513 /* c-file-style: "GNU" */