2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/winmain.cpp
5 * PURPOSE: Main program
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
7 * Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
18 INT SelectedEnumType
= ENUM_ALL_COMPONENTS
;
19 SETTINGS_INFO SettingsInfo
;
21 WCHAR szSearchPattern
[MAX_STR_LEN
] = L
"";
23 class CRAppsModule
: public CComModule
28 BEGIN_OBJECT_MAP(ObjectMap
)
32 CAtlWinModule gWinModule
;
34 void *operator new (size_t, void *buf
)
39 static VOID
InitializeAtlModule(HINSTANCE hInstance
, BOOL bInitialize
)
43 gModule
.Init(ObjectMap
, hInstance
, NULL
);
52 FillDefaultSettings(PSETTINGS_INFO pSettingsInfo
)
54 pSettingsInfo
->bSaveWndPos
= TRUE
;
55 pSettingsInfo
->bUpdateAtStart
= FALSE
;
56 pSettingsInfo
->bLogEnabled
= TRUE
;
57 StringCbCopyW(pSettingsInfo
->szDownloadDir
,
58 sizeof(pSettingsInfo
->szDownloadDir
),
60 pSettingsInfo
->bDelInstaller
= FALSE
;
62 pSettingsInfo
->Maximized
= FALSE
;
63 pSettingsInfo
->Left
= CW_USEDEFAULT
;
64 pSettingsInfo
->Top
= CW_USEDEFAULT
;
65 pSettingsInfo
->Width
= 680;
66 pSettingsInfo
->Height
= 450;
68 pSettingsInfo
->Proxy
= 0;
69 StringCbCopyW(pSettingsInfo
->szProxyServer
, sizeof(pSettingsInfo
->szProxyServer
), L
"");
70 StringCbCopyW(pSettingsInfo
->szNoProxyFor
, sizeof(pSettingsInfo
->szNoProxyFor
), L
"");
79 if (RegOpenKeyExW(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
81 dwSize
= sizeof(SettingsInfo
);
82 if (RegQueryValueExW(hKey
, L
"Settings", NULL
, NULL
, (LPBYTE
)&SettingsInfo
, &dwSize
) == ERROR_SUCCESS
)
95 SaveSettings(HWND hwnd
)
100 if (SettingsInfo
.bSaveWndPos
)
102 wp
.length
= sizeof(wp
);
103 GetWindowPlacement(hwnd
, &wp
);
105 SettingsInfo
.Left
= wp
.rcNormalPosition
.left
;
106 SettingsInfo
.Top
= wp
.rcNormalPosition
.top
;
107 SettingsInfo
.Width
= wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
;
108 SettingsInfo
.Height
= wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
;
109 SettingsInfo
.Maximized
= (wp
.showCmd
== SW_MAXIMIZE
|| (wp
.showCmd
== SW_SHOWMINIMIZED
&& (wp
.flags
& WPF_RESTORETOMAXIMIZED
)));
112 if (RegCreateKeyExW(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", 0, NULL
,
113 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
)
115 RegSetValueExW(hKey
, L
"Settings", 0, REG_BINARY
, (LPBYTE
)&SettingsInfo
, sizeof(SettingsInfo
));
121 wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPWSTR lpCmdLine
, int nShowCmd
)
123 WCHAR szWindowClass
[] = L
"ROSAPPMGR";
124 HANDLE hMutex
= NULL
;
128 InitializeAtlModule(hInstance
, TRUE
);
130 switch (GetUserDefaultUILanguage())
132 case MAKELANGID(LANG_HEBREW
, SUBLANG_DEFAULT
):
133 SetProcessDefaultLayout(LAYOUT_RTL
);
142 hMutex
= CreateMutexW(NULL
, FALSE
, szWindowClass
);
143 if ((!hMutex
) || (GetLastError() == ERROR_ALREADY_EXISTS
))
145 /* If already started, it is found its window */
146 HWND hWindow
= FindWindowW(szWindowClass
, NULL
);
148 /* Activate window */
149 ShowWindow(hWindow
, SW_SHOWNORMAL
);
150 SetForegroundWindow(hWindow
);
156 FillDefaultSettings(&SettingsInfo
);
161 InitCommonControls();
163 hMainWnd
= CreateMainWindow();
164 if (!hMainWnd
) goto Exit
;
166 /* Maximize it if we must */
167 ShowWindow(hMainWnd
, (SettingsInfo
.bSaveWndPos
&& SettingsInfo
.Maximized
? SW_MAXIMIZE
: nShowCmd
));
168 UpdateWindow(hMainWnd
);
170 if (SettingsInfo
.bUpdateAtStart
)
173 /* Load the menu hotkeys */
174 KeyBrd
= LoadAccelerators(NULL
, MAKEINTRESOURCE(HOTKEYS
));
177 while (GetMessage(&Msg
, NULL
, 0, 0))
179 if (!TranslateAccelerator(hMainWnd
, KeyBrd
, &Msg
))
181 TranslateMessage(&Msg
);
182 DispatchMessage(&Msg
);
190 InitializeAtlModule(hInstance
, FALSE
);