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)
8 * Alexander Shaposhnikov (chaez.san@gmail.com)
19 INT SelectedEnumType
= ENUM_ALL_COMPONENTS
;
20 SETTINGS_INFO SettingsInfo
;
22 ATL::CStringW szSearchPattern
;
24 class CRAppsModule
: public CComModule
29 BEGIN_OBJECT_MAP(ObjectMap
)
33 CAtlWinModule gWinModule
;
35 //void *operator new (size_t, void *buf)
40 static VOID
InitializeAtlModule(HINSTANCE hInstance
, BOOL bInitialize
)
44 gModule
.Init(ObjectMap
, hInstance
, NULL
);
53 FillDefaultSettings(PSETTINGS_INFO pSettingsInfo
)
55 ATL::CStringW szDownloadDir
;
56 pSettingsInfo
->bSaveWndPos
= TRUE
;
57 pSettingsInfo
->bUpdateAtStart
= FALSE
;
58 pSettingsInfo
->bLogEnabled
= TRUE
;
60 if (FAILED(SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, SHGFP_TYPE_CURRENT
, szDownloadDir
.GetBuffer(MAX_PATH
))))
62 szDownloadDir
.ReleaseBuffer();
63 if (!szDownloadDir
.GetEnvironmentVariableW(L
"SystemDrive"))
65 szDownloadDir
= L
"C:";
69 szDownloadDir
.ReleaseBuffer();
71 szDownloadDir
+= L
"\\RAPPS Downloads";
72 ATL::CStringW::CopyChars(pSettingsInfo
->szDownloadDir
,
73 _countof(pSettingsInfo
->szDownloadDir
),
74 szDownloadDir
.GetString(),
75 szDownloadDir
.GetLength() + 1);
77 pSettingsInfo
->bDelInstaller
= FALSE
;
78 pSettingsInfo
->Maximized
= FALSE
;
79 pSettingsInfo
->Left
= CW_USEDEFAULT
;
80 pSettingsInfo
->Top
= CW_USEDEFAULT
;
81 pSettingsInfo
->Width
= 680;
82 pSettingsInfo
->Height
= 450;
83 pSettingsInfo
->Proxy
= 0;
85 pSettingsInfo
->szProxyServer
[0] = UNICODE_NULL
;
86 pSettingsInfo
->szNoProxyFor
[0] = UNICODE_NULL
;
95 if (RegOpenKeyExW(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
97 dwSize
= sizeof(SettingsInfo
);
98 if (RegQueryValueExW(hKey
, L
"Settings", NULL
, NULL
, (LPBYTE
) &SettingsInfo
, &dwSize
) == ERROR_SUCCESS
)
111 SaveSettings(HWND hwnd
)
116 if (SettingsInfo
.bSaveWndPos
)
118 wp
.length
= sizeof(wp
);
119 GetWindowPlacement(hwnd
, &wp
);
121 SettingsInfo
.Left
= wp
.rcNormalPosition
.left
;
122 SettingsInfo
.Top
= wp
.rcNormalPosition
.top
;
123 SettingsInfo
.Width
= wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
;
124 SettingsInfo
.Height
= wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
;
125 SettingsInfo
.Maximized
= (wp
.showCmd
== SW_MAXIMIZE
|| (wp
.showCmd
== SW_SHOWMINIMIZED
&& (wp
.flags
& WPF_RESTORETOMAXIMIZED
)));
128 if (RegCreateKeyExW(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", 0, NULL
,
129 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
)
131 RegSetValueExW(hKey
, L
"Settings", 0, REG_BINARY
, (LPBYTE
) &SettingsInfo
, sizeof(SettingsInfo
));
137 wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPWSTR lpCmdLine
, int nShowCmd
)
139 WCHAR szWindowClass
[] = L
"ROSAPPMGR";
140 HANDLE hMutex
= NULL
;
144 InitializeAtlModule(hInstance
, TRUE
);
146 switch (GetUserDefaultUILanguage())
148 case MAKELANGID(LANG_HEBREW
, SUBLANG_DEFAULT
):
149 SetProcessDefaultLayout(LAYOUT_RTL
);
158 hMutex
= CreateMutexW(NULL
, FALSE
, szWindowClass
);
159 if ((!hMutex
) || (GetLastError() == ERROR_ALREADY_EXISTS
))
161 /* If already started, it is found its window */
162 HWND hWindow
= FindWindowW(szWindowClass
, NULL
);
164 /* Activate window */
165 ShowWindow(hWindow
, SW_SHOWNORMAL
);
166 SetForegroundWindow(hWindow
);
172 FillDefaultSettings(&SettingsInfo
);
177 InitCommonControls();
179 hMainWnd
= CreateMainWindow();
180 if (!hMainWnd
) goto Exit
;
182 /* Maximize it if we must */
183 ShowWindow(hMainWnd
, (SettingsInfo
.bSaveWndPos
&& SettingsInfo
.Maximized
? SW_MAXIMIZE
: nShowCmd
));
184 UpdateWindow(hMainWnd
);
186 if (SettingsInfo
.bUpdateAtStart
)
189 /* Load the menu hotkeys */
190 KeyBrd
= LoadAccelerators(NULL
, MAKEINTRESOURCE(HOTKEYS
));
193 while (GetMessage(&Msg
, NULL
, 0, 0))
195 if (!TranslateAccelerator(hMainWnd
, KeyBrd
, &Msg
))
197 TranslateMessage(&Msg
);
198 DispatchMessage(&Msg
);
206 InitializeAtlModule(hInstance
, FALSE
);