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 StringCchCopyW(pSettingsInfo
->szDownloadDir
, _countof(pSettingsInfo
->szDownloadDir
), szDownloadDir
.GetString());
74 pSettingsInfo
->bDelInstaller
= FALSE
;
75 pSettingsInfo
->Maximized
= FALSE
;
76 pSettingsInfo
->Left
= CW_USEDEFAULT
;
77 pSettingsInfo
->Top
= CW_USEDEFAULT
;
78 pSettingsInfo
->Width
= 680;
79 pSettingsInfo
->Height
= 450;
80 pSettingsInfo
->Proxy
= 0;
82 StringCbCopyW(pSettingsInfo
->szProxyServer
, sizeof(pSettingsInfo
->szProxyServer
), L
"");
83 StringCbCopyW(pSettingsInfo
->szNoProxyFor
, sizeof(pSettingsInfo
->szNoProxyFor
), L
"");
92 if (RegOpenKeyExW(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
94 dwSize
= sizeof(SettingsInfo
);
95 if (RegQueryValueExW(hKey
, L
"Settings", NULL
, NULL
, (LPBYTE
) &SettingsInfo
, &dwSize
) == ERROR_SUCCESS
)
108 SaveSettings(HWND hwnd
)
113 if (SettingsInfo
.bSaveWndPos
)
115 wp
.length
= sizeof(wp
);
116 GetWindowPlacement(hwnd
, &wp
);
118 SettingsInfo
.Left
= wp
.rcNormalPosition
.left
;
119 SettingsInfo
.Top
= wp
.rcNormalPosition
.top
;
120 SettingsInfo
.Width
= wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
;
121 SettingsInfo
.Height
= wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
;
122 SettingsInfo
.Maximized
= (wp
.showCmd
== SW_MAXIMIZE
|| (wp
.showCmd
== SW_SHOWMINIMIZED
&& (wp
.flags
& WPF_RESTORETOMAXIMIZED
)));
125 if (RegCreateKeyExW(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", 0, NULL
,
126 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
)
128 RegSetValueExW(hKey
, L
"Settings", 0, REG_BINARY
, (LPBYTE
) &SettingsInfo
, sizeof(SettingsInfo
));
134 wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPWSTR lpCmdLine
, int nShowCmd
)
136 WCHAR szWindowClass
[] = L
"ROSAPPMGR";
137 HANDLE hMutex
= NULL
;
141 InitializeAtlModule(hInstance
, TRUE
);
143 switch (GetUserDefaultUILanguage())
145 case MAKELANGID(LANG_HEBREW
, SUBLANG_DEFAULT
):
146 SetProcessDefaultLayout(LAYOUT_RTL
);
155 hMutex
= CreateMutexW(NULL
, FALSE
, szWindowClass
);
156 if ((!hMutex
) || (GetLastError() == ERROR_ALREADY_EXISTS
))
158 /* If already started, it is found its window */
159 HWND hWindow
= FindWindowW(szWindowClass
, NULL
);
161 /* Activate window */
162 ShowWindow(hWindow
, SW_SHOWNORMAL
);
163 SetForegroundWindow(hWindow
);
169 FillDefaultSettings(&SettingsInfo
);
174 InitCommonControls();
176 hMainWnd
= CreateMainWindow();
177 if (!hMainWnd
) goto Exit
;
179 /* Maximize it if we must */
180 ShowWindow(hMainWnd
, (SettingsInfo
.bSaveWndPos
&& SettingsInfo
.Maximized
? SW_MAXIMIZE
: nShowCmd
));
181 UpdateWindow(hMainWnd
);
183 if (SettingsInfo
.bUpdateAtStart
)
186 /* Load the menu hotkeys */
187 KeyBrd
= LoadAccelerators(NULL
, MAKEINTRESOURCE(HOTKEYS
));
190 while (GetMessage(&Msg
, NULL
, 0, 0))
192 if (!TranslateAccelerator(hMainWnd
, KeyBrd
, &Msg
))
194 TranslateMessage(&Msg
);
195 DispatchMessage(&Msg
);
203 InitializeAtlModule(hInstance
, FALSE
);