xref: /reactos/base/applications/rapps/winmain.cpp (revision 9393fc32)
1 /*
2  * PROJECT:     ReactOS Applications Manager
3  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE:     Main program
5  * COPYRIGHT:   Copyright 2009 Dmitry Chapyshev            (dmitry@reactos.org)
6  *              Copyright 2015 Ismael Ferreras Morezuelas  (swyterzone+ros@gmail.com)
7  *              Copyright 2017 Alexander Shaposhnikov      (sanchaez@reactos.org)
8  */
9 #include "rapps.h"
10 #include "unattended.h"
11 #include "winmain.h"
12 #include <atlcom.h>
13 #include <gdiplus.h>
14 #include <conutils.h>
15 
16 LPCWSTR szWindowClass = L"ROSAPPMGR";
17 
18 HWND hMainWnd;
19 HINSTANCE hInst;
20 SETTINGS_INFO SettingsInfo;
21 
22 class CRAppsModule : public CComModule
23 {
24 public:
25 };
26 
27 BEGIN_OBJECT_MAP(ObjectMap)
28 END_OBJECT_MAP()
29 
30 CRAppsModule gModule;
31 CAtlWinModule gWinModule;
32 
33 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
34 ULONG_PTR           gdiplusToken;
35 
36 
37 static VOID InitializeAtlModule(HINSTANCE hInstance, BOOL bInitialize)
38 {
39     if (bInitialize)
40     {
41         gModule.Init(ObjectMap, hInstance, NULL);
42     }
43     else
44     {
45         gModule.Term();
46     }
47 }
48 
49 VOID InitializeGDIPlus(BOOL bInitialize)
50 {
51     if (bInitialize)
52     {
53         Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
54     }
55     else
56     {
57         Gdiplus::GdiplusShutdown(gdiplusToken);
58     }
59 }
60 
61 INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nShowCmd)
62 {
63     BOOL bIsFirstLaunch;
64 
65     InitializeAtlModule(hInstance, TRUE);
66     InitializeGDIPlus(TRUE);
67 
68     if (GetUserDefaultUILanguage() == MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT))
69     {
70         SetProcessDefaultLayout(LAYOUT_RTL);
71     }
72 
73     hInst = hInstance;
74 
75     bIsFirstLaunch = !LoadSettings(&SettingsInfo);
76     if (bIsFirstLaunch)
77     {
78         FillDefaultSettings(&SettingsInfo);
79     }
80 
81     InitLogs();
82     InitCommonControls();
83 
84     // parse cmd-line and perform the corresponding operation
85     BOOL bSuccess = ParseCmdAndExecute(GetCommandLineW(), bIsFirstLaunch, SW_SHOWNORMAL);
86 
87     InitializeGDIPlus(FALSE);
88     InitializeAtlModule(GetModuleHandle(NULL), FALSE);
89 
90     return bSuccess ? 0 : 1;
91 }
92