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 if (SUCCEEDED(SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, SHGFP_TYPE_CURRENT
, pSettingsInfo
->szDownloadDir
)))
59 StringCchCatW(pSettingsInfo
->szDownloadDir
, _countof(pSettingsInfo
->szDownloadDir
), L
"\\RAPPS Downloads");
63 ExpandEnvironmentStringsW(L
"%SystemDrive%\\RAPPS Downloads",
64 pSettingsInfo
->szDownloadDir
, _countof(pSettingsInfo
->szDownloadDir
));
67 pSettingsInfo
->bDelInstaller
= FALSE
;
69 pSettingsInfo
->Maximized
= FALSE
;
70 pSettingsInfo
->Left
= CW_USEDEFAULT
;
71 pSettingsInfo
->Top
= CW_USEDEFAULT
;
72 pSettingsInfo
->Width
= 680;
73 pSettingsInfo
->Height
= 450;
75 pSettingsInfo
->Proxy
= 0;
76 StringCbCopyW(pSettingsInfo
->szProxyServer
, sizeof(pSettingsInfo
->szProxyServer
), L
"");
77 StringCbCopyW(pSettingsInfo
->szNoProxyFor
, sizeof(pSettingsInfo
->szNoProxyFor
), L
"");
86 if (RegOpenKeyExW(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
88 dwSize
= sizeof(SettingsInfo
);
89 if (RegQueryValueExW(hKey
, L
"Settings", NULL
, NULL
, (LPBYTE
)&SettingsInfo
, &dwSize
) == ERROR_SUCCESS
)
102 SaveSettings(HWND hwnd
)
107 if (SettingsInfo
.bSaveWndPos
)
109 wp
.length
= sizeof(wp
);
110 GetWindowPlacement(hwnd
, &wp
);
112 SettingsInfo
.Left
= wp
.rcNormalPosition
.left
;
113 SettingsInfo
.Top
= wp
.rcNormalPosition
.top
;
114 SettingsInfo
.Width
= wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
;
115 SettingsInfo
.Height
= wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
;
116 SettingsInfo
.Maximized
= (wp
.showCmd
== SW_MAXIMIZE
|| (wp
.showCmd
== SW_SHOWMINIMIZED
&& (wp
.flags
& WPF_RESTORETOMAXIMIZED
)));
119 if (RegCreateKeyExW(HKEY_CURRENT_USER
, L
"Software\\ReactOS\\rapps", 0, NULL
,
120 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
)
122 RegSetValueExW(hKey
, L
"Settings", 0, REG_BINARY
, (LPBYTE
)&SettingsInfo
, sizeof(SettingsInfo
));
128 wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPWSTR lpCmdLine
, int nShowCmd
)
130 WCHAR szWindowClass
[] = L
"ROSAPPMGR";
131 HANDLE hMutex
= NULL
;
135 InitializeAtlModule(hInstance
, TRUE
);
137 switch (GetUserDefaultUILanguage())
139 case MAKELANGID(LANG_HEBREW
, SUBLANG_DEFAULT
):
140 SetProcessDefaultLayout(LAYOUT_RTL
);
149 hMutex
= CreateMutexW(NULL
, FALSE
, szWindowClass
);
150 if ((!hMutex
) || (GetLastError() == ERROR_ALREADY_EXISTS
))
152 /* If already started, it is found its window */
153 HWND hWindow
= FindWindowW(szWindowClass
, NULL
);
155 /* Activate window */
156 ShowWindow(hWindow
, SW_SHOWNORMAL
);
157 SetForegroundWindow(hWindow
);
163 FillDefaultSettings(&SettingsInfo
);
168 InitCommonControls();
170 hMainWnd
= CreateMainWindow();
171 if (!hMainWnd
) goto Exit
;
173 /* Maximize it if we must */
174 ShowWindow(hMainWnd
, (SettingsInfo
.bSaveWndPos
&& SettingsInfo
.Maximized
? SW_MAXIMIZE
: nShowCmd
));
175 UpdateWindow(hMainWnd
);
177 if (SettingsInfo
.bUpdateAtStart
)
180 /* Load the menu hotkeys */
181 KeyBrd
= LoadAccelerators(NULL
, MAKEINTRESOURCE(HOTKEYS
));
184 while (GetMessage(&Msg
, NULL
, 0, 0))
186 if (!TranslateAccelerator(hMainWnd
, KeyBrd
, &Msg
))
188 TranslateMessage(&Msg
);
189 DispatchMessage(&Msg
);
197 InitializeAtlModule(hInstance
, FALSE
);