ReactOS  0.4.14-dev-52-g6116262
winmain.cpp File Reference
#include "rapps.h"
#include "unattended.h"
#include <atlcom.h>
Include dependency graph for winmain.cpp:

Go to the source code of this file.

Classes

class  CRAppsModule
 

Functions

static VOID InitializeAtlModule (HINSTANCE hInstance, BOOL bInitialize)
 
VOID FillDefaultSettings (PSETTINGS_INFO pSettingsInfo)
 
static BOOL LoadSettings ()
 
VOID SaveSettings (HWND hwnd)
 
INT WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nShowCmd)
 

Variables

HWND hMainWnd
 
HINSTANCE hInst
 
SETTINGS_INFO SettingsInfo
 
CRAppsModule gModule
 
CAtlWinModule gWinModule
 

Function Documentation

◆ FillDefaultSettings()

VOID FillDefaultSettings ( PSETTINGS_INFO  pSettingsInfo)

Definition at line 43 of file winmain.cpp.

44 {
45  ATL::CStringW szDownloadDir;
46  ZeroMemory(pSettingsInfo, sizeof(SETTINGS_INFO));
47 
48  pSettingsInfo->bSaveWndPos = TRUE;
49  pSettingsInfo->bUpdateAtStart = FALSE;
50  pSettingsInfo->bLogEnabled = TRUE;
51 
53  {
54  szDownloadDir.ReleaseBuffer();
55  if (!szDownloadDir.GetEnvironmentVariableW(L"SystemDrive"))
56  {
57  szDownloadDir = L"C:";
58  }
59  }
60  else
61  {
62  szDownloadDir.ReleaseBuffer();
63  }
64 
65  szDownloadDir += L"\\RAPPS Downloads";
67  _countof(pSettingsInfo->szDownloadDir),
68  szDownloadDir.GetString(),
69  szDownloadDir.GetLength() + 1);
70 
71  pSettingsInfo->bDelInstaller = FALSE;
72  pSettingsInfo->Maximized = FALSE;
73  pSettingsInfo->Left = CW_USEDEFAULT;
74  pSettingsInfo->Top = CW_USEDEFAULT;
75  pSettingsInfo->Width = 680;
76  pSettingsInfo->Height = 450;
77 }
int GetLength() const
Definition: atlsimpstr.h:356
BOOL bUpdateAtStart
Definition: winmain.h:8
#define TRUE
Definition: types.h:120
#define _countof(array)
Definition: fontsub.cpp:30
INT Height
Definition: winmain.h:17
#define ZeroMemory
Definition: winbase.h:1635
BOOL Maximized
Definition: winmain.h:13
WCHAR szDownloadDir[MAX_PATH]
Definition: winmain.h:10
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:372
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
#define MAX_PATH
Definition: compat.h:26
PCXSTR GetString() const
Definition: atlsimpstr.h:361
static const WCHAR L[]
Definition: oid.c:1250
BOOL bLogEnabled
Definition: winmain.h:9
static void __cdecl CopyChars(_Out_writes_to_(nDestLen, nChars) XCHAR *pchDest, _In_ size_t nDestLen, _In_reads_opt_(nChars) const XCHAR *pchSrc, _In_ int nChars)
Definition: atlsimpstr.h:423
BOOL bDelInstaller
Definition: winmain.h:11
#define CSIDL_PERSONAL
Definition: shlobj.h:2008
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2085
BOOL bSaveWndPos
Definition: winmain.h:7

Referenced by anonymous_namespace{settingsdlg.cpp}::SettingsDlgProc(), and wWinMain().

◆ InitializeAtlModule()

static VOID InitializeAtlModule ( HINSTANCE  hInstance,
BOOL  bInitialize 
)
static

Definition at line 31 of file winmain.cpp.

32 {
33  if (bInitialize)
34  {
35  gModule.Init(ObjectMap, hInstance, NULL);
36  }
37  else
38  {
39  gModule.Term();
40  }
41 }
void Term()
Definition: atlbase.h:820
HRESULT Init(_ATL_OBJMAP_ENTRY *p, HINSTANCE, const GUID *plibid)
Definition: atlbase.h:797
HINSTANCE hInstance
Definition: charmap.c:20
smooth NULL
Definition: ftsmooth.c:416
CRAppsModule gModule
Definition: winmain.cpp:28

Referenced by wWinMain().

◆ LoadSettings()

static BOOL LoadSettings ( void  )
static

Definition at line 79 of file winmain.cpp.

80 {
81  ATL::CRegKey RegKey;
82  DWORD dwSize;
83  BOOL bResult = FALSE;
84  if (RegKey.Open(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", KEY_READ) == ERROR_SUCCESS)
85  {
86  dwSize = sizeof(SettingsInfo);
87  bResult = (RegKey.QueryBinaryValue(L"Settings", (PVOID) &SettingsInfo, &dwSize) == ERROR_SUCCESS);
88 
89  RegKey.Close();
90  }
91 
92  return bResult;
93 }
LONG QueryBinaryValue(LPCTSTR pszValueName, void *pValue, ULONG *pnBytes)
Definition: atlbase.h:1138
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG Close()
Definition: atlbase.h:1053
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired=KEY_READ|KEY_WRITE)
Definition: atlbase.h:1070
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:18

Referenced by wWinMain().

◆ SaveSettings()

VOID SaveSettings ( HWND  hwnd)

Definition at line 95 of file winmain.cpp.

96 {
97  WINDOWPLACEMENT wp;
98  ATL::CRegKey RegKey;
99 
101  {
102  wp.length = sizeof(wp);
103  GetWindowPlacement(hwnd, &wp);
104 
110  || (wp.showCmd == SW_SHOWMINIMIZED
111  && (wp.flags & WPF_RESTORETOMAXIMIZED)));
112  }
113 
114  if (RegKey.Create(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", NULL,
116  {
117  RegKey.SetBinaryValue(L"Settings", (const PVOID) &SettingsInfo, sizeof(SettingsInfo));
118  RegKey.Close();
119  }
120 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
INT Height
Definition: winmain.h:17
LONG top
Definition: windef.h:292
LONG SetBinaryValue(LPCTSTR pszValueName, const void *pValue, ULONG nBytes)
Definition: atlbase.h:1253
#define WPF_RESTORETOMAXIMIZED
Definition: winuser.h:2507
LONG left
Definition: windef.h:291
#define SW_SHOWMINIMIZED
Definition: winuser.h:765
LONG right
Definition: windef.h:293
BOOL Maximized
Definition: winmain.h:13
LONG Close()
Definition: atlbase.h:1053
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI GetWindowPlacement(_In_ HWND, _Inout_ WINDOWPLACEMENT *)
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
static const WCHAR L[]
Definition: oid.c:1250
LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName, LPTSTR lpszClass=REG_NONE, DWORD dwOptions=REG_OPTION_NON_VOLATILE, REGSAM samDesired=KEY_READ|KEY_WRITE, LPSECURITY_ATTRIBUTES lpSecAttr=NULL, LPDWORD lpdwDisposition=NULL)
Definition: atlbase.h:1091
RECT rcNormalPosition
Definition: winuser.h:3269
BOOL bSaveWndPos
Definition: winmain.h:7
LONG bottom
Definition: windef.h:294
#define SW_MAXIMIZE
Definition: winuser.h:766
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:18

◆ wWinMain()

INT WINAPI wWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPWSTR  lpCmdLine,
INT  nShowCmd 
)

Definition at line 122 of file winmain.cpp.

123 {
124  LPCWSTR szWindowClass = L"ROSAPPMGR";
125  HANDLE hMutex;
126  BOOL bIsFirstLaunch;
127 
129 
131  {
133  }
134 
135  hInst = hInstance;
136 
138  if ((!hMutex) || (GetLastError() == ERROR_ALREADY_EXISTS))
139  {
140  /* If already started, it is found its window */
141  HWND hWindow = FindWindowW(szWindowClass, NULL);
142 
143  /* Activate window */
144  ShowWindow(hWindow, SW_SHOWNORMAL);
145  SetForegroundWindow(hWindow);
146  return 1;
147  }
148  bIsFirstLaunch = !LoadSettings();
149  if (bIsFirstLaunch)
150  {
152  }
153 
154  InitLogs();
156 
157  // skip window creation if there were some keys
159  {
160  if (SettingsInfo.bUpdateAtStart || bIsFirstLaunch)
162 
163  ShowMainWindow(nShowCmd);
164  }
165 
166  if (hMutex)
168 
170 
171  return 0;
172 }
BOOL bUpdateAtStart
Definition: winmain.h:8
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: lang.c:806
#define TRUE
Definition: types.h:120
static VOID InitializeAtlModule(HINSTANCE hInstance, BOOL bInitialize)
Definition: winmain.cpp:31
#define CloseHandle
Definition: compat.h:398
VOID ShowMainWindow(INT nShowCmd)
Definition: gui.cpp:1855
#define LAYOUT_RTL
Definition: wingdi.h:1370
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define SUBLANG_DEFAULT
Definition: nls.h:168
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HINSTANCE hInst
Definition: winmain.cpp:17
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define LANG_HEBREW
Definition: nls.h:67
const TCHAR szWindowClass[]
Definition: magnifier.c:28
HINSTANCE hInstance
Definition: charmap.c:20
VOID InitLogs()
Definition: misc.cpp:186
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
Definition: winmain.cpp:43
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2013
smooth NULL
Definition: ftsmooth.c:416
HANDLE hMutex
Definition: mutex.c:11
BOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout)
Definition: window.c:1716
BOOL UseCmdParameters(LPWSTR lpCmdLine)
Definition: unattended.cpp:16
HWND WINAPI FindWindowW(_In_opt_ LPCWSTR, _In_opt_ LPCWSTR)
static const WCHAR L[]
Definition: oid.c:1250
static BOOL ForceUpdateAppsDB()
Definition: available.cpp:317
#define SW_SHOWNORMAL
Definition: winuser.h:764
static BOOL LoadSettings()
Definition: winmain.cpp:79
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:576
#define MAKELANGID(p, s)
Definition: nls.h:15
BOOL WINAPI SetForegroundWindow(_In_ HWND)
VOID WINAPI InitCommonControls(void)
Definition: commctrl.c:863
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:18

Variable Documentation

◆ gModule

CRAppsModule gModule

Definition at line 28 of file winmain.cpp.

Referenced by InitializeAtlModule().

◆ gWinModule

CAtlWinModule gWinModule

Definition at line 29 of file winmain.cpp.

◆ hInst

HINSTANCE hInst

Definition at line 17 of file winmain.cpp.

Referenced by wWinMain().

◆ hMainWnd

HWND hMainWnd

Definition at line 16 of file winmain.cpp.

◆ SettingsInfo