ReactOS  0.4.12-dev-18-gf469aca
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
 
INT SelectedEnumType = ENUM_ALL_INSTALLED
 
SETTINGS_INFO SettingsInfo
 
ATL::CStringW szSearchPattern
 
CRAppsModule gModule
 
CAtlWinModule gWinModule
 

Function Documentation

◆ FillDefaultSettings()

VOID FillDefaultSettings ( PSETTINGS_INFO  pSettingsInfo)

Definition at line 46 of file winmain.cpp.

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

47 {
48  ATL::CStringW szDownloadDir;
49  ZeroMemory(pSettingsInfo, sizeof(SETTINGS_INFO));
50 
51  pSettingsInfo->bSaveWndPos = TRUE;
52  pSettingsInfo->bUpdateAtStart = FALSE;
53  pSettingsInfo->bLogEnabled = TRUE;
54 
56  {
57  szDownloadDir.ReleaseBuffer();
58  if (!szDownloadDir.GetEnvironmentVariableW(L"SystemDrive"))
59  {
60  szDownloadDir = L"C:";
61  }
62  }
63  else
64  {
65  szDownloadDir.ReleaseBuffer();
66  }
67 
68  szDownloadDir += L"\\RAPPS Downloads";
70  _countof(pSettingsInfo->szDownloadDir),
71  szDownloadDir.GetString(),
72  szDownloadDir.GetLength() + 1);
73 
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 }
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:1087
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:1881
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2085
BOOL bSaveWndPos
Definition: winmain.h:7

◆ InitializeAtlModule()

static VOID InitializeAtlModule ( HINSTANCE  hInstance,
BOOL  bInitialize 
)
static

Definition at line 34 of file winmain.cpp.

Referenced by wWinMain().

35 {
36  if (bInitialize)
37  {
38  gModule.Init(ObjectMap, hInstance, NULL);
39  }
40  else
41  {
42  gModule.Term();
43  }
44 }
void Term()
Definition: atlbase.h:829
HRESULT Init(_ATL_OBJMAP_ENTRY *p, HINSTANCE, const GUID *plibid)
Definition: atlbase.h:806
smooth NULL
Definition: ftsmooth.c:416
CRAppsModule gModule
Definition: winmain.cpp:31

◆ LoadSettings()

static BOOL LoadSettings ( void  )
static

Definition at line 82 of file winmain.cpp.

Referenced by wWinMain().

83 {
84  ATL::CRegKey RegKey;
85  DWORD dwSize;
86  BOOL bResult = FALSE;
87  if (RegKey.Open(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", KEY_READ) == ERROR_SUCCESS)
88  {
89  dwSize = sizeof(SettingsInfo);
90  bResult = (RegKey.QueryBinaryValue(L"Settings", (PVOID) &SettingsInfo, &dwSize) == ERROR_SUCCESS);
91 
92  RegKey.Close();
93  }
94 
95  return bResult;
96 }
LONG QueryBinaryValue(LPCTSTR pszValueName, void *pValue, ULONG *pnBytes)
Definition: atlbase.h:1146
#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:1061
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired=KEY_READ|KEY_WRITE)
Definition: atlbase.h:1078
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1087
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:19

◆ SaveSettings()

VOID SaveSettings ( HWND  hwnd)

Definition at line 98 of file winmain.cpp.

99 {
100  WINDOWPLACEMENT wp;
101  ATL::CRegKey RegKey;
102 
104  {
105  wp.length = sizeof(wp);
106  GetWindowPlacement(hwnd, &wp);
107 
113  || (wp.showCmd == SW_SHOWMINIMIZED
114  && (wp.flags & WPF_RESTORETOMAXIMIZED)));
115  }
116 
117  if (RegKey.Create(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", NULL,
119  {
120  RegKey.SetBinaryValue(L"Settings", (const PVOID) &SettingsInfo, sizeof(SettingsInfo));
121  RegKey.Close();
122  }
123 }
#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:297
LONG SetBinaryValue(LPCTSTR pszValueName, const void *pValue, ULONG nBytes)
Definition: atlbase.h:1261
#define WPF_RESTORETOMAXIMIZED
Definition: winuser.h:2486
LONG left
Definition: windef.h:296
#define SW_SHOWMINIMIZED
Definition: winuser.h:765
LONG right
Definition: windef.h:298
BOOL Maximized
Definition: winmain.h:13
LONG Close()
Definition: atlbase.h:1061
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:1087
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:1099
RECT rcNormalPosition
Definition: winuser.h:3237
BOOL bSaveWndPos
Definition: winmain.h:7
LONG bottom
Definition: windef.h:299
#define SW_MAXIMIZE
Definition: winuser.h:766
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:19

◆ wWinMain()

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

Definition at line 125 of file winmain.cpp.

126 {
127  LPCWSTR szWindowClass = L"ROSAPPMGR";
128  HANDLE hMutex;
129  HACCEL KeyBrd;
130  MSG Msg;
131  BOOL bIsFirstLaunch;
132 
133  InitializeAtlModule(hInstance, TRUE);
134 
136  {
138  }
139 
140  hInst = hInstance;
141 
142  hMutex = CreateMutexW(NULL, FALSE, szWindowClass);
143  if ((!hMutex) || (GetLastError() == ERROR_ALREADY_EXISTS))
144  {
145  /* If already started, it is found its window */
146  HWND hWindow = FindWindowW(szWindowClass, NULL);
147 
148  /* Activate window */
149  ShowWindow(hWindow, SW_SHOWNORMAL);
150  SetForegroundWindow(hWindow);
151  return 1;
152  }
153  bIsFirstLaunch = !LoadSettings();
154  if (bIsFirstLaunch)
155  {
157  }
158 
159  InitLogs();
161 
162  // skip window creation if there were some keys
164  {
165  if (SettingsInfo.bUpdateAtStart || bIsFirstLaunch)
167 
169 
170  if (hMainWnd)
171  {
172  /* Maximize it if we must */
175 
176  /* Load the menu hotkeys */
178 
179  /* Message Loop */
180  while (GetMessageW(&Msg, NULL, 0, 0))
181  {
182  if (!TranslateAcceleratorW(hMainWnd, KeyBrd, &Msg))
183  {
184  TranslateMessage(&Msg);
185  DispatchMessageW(&Msg);
186  }
187  }
188  }
189  }
190 
191  if (hMutex)
192  CloseHandle(hMutex);
193 
194  InitializeAtlModule(hInstance, FALSE);
195 
196  return 0;
197 }
BOOL bUpdateAtStart
Definition: winmain.h:8
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: lang.c:561
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define TRUE
Definition: types.h:120
static VOID InitializeAtlModule(HINSTANCE hInstance, BOOL bInitialize)
Definition: winmain.cpp:34
#define CloseHandle
Definition: compat.h:398
#define LAYOUT_RTL
Definition: wingdi.h:1352
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define SUBLANG_DEFAULT
Definition: nls.h:168
BOOL WINAPI UpdateWindow(_In_ HWND)
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HINSTANCE hInst
Definition: winmain.cpp:17
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL Maximized
Definition: winmain.h:13
#define LANG_HEBREW
Definition: nls.h:67
struct @1571 Msg[]
const TCHAR szWindowClass[]
Definition: magnifier.c:29
HINSTANCE hInstance
Definition: charmap.c:20
VOID InitLogs()
Definition: misc.cpp:201
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
Definition: winmain.cpp:46
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2043
HACCEL WINAPI LoadAcceleratorsW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
smooth NULL
Definition: ftsmooth.c:416
HANDLE hMutex
Definition: mutex.c:11
BOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout)
Definition: window.c:1686
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL UseCmdParameters(LPWSTR lpCmdLine)
Definition: unattended.cpp:16
HWND WINAPI FindWindowW(_In_opt_ LPCWSTR, _In_opt_ LPCWSTR)
#define HOTKEYS
Definition: resource.h:208
int WINAPI TranslateAcceleratorW(_In_ HWND, _In_ HACCEL, _In_ LPMSG)
static const WCHAR L[]
Definition: oid.c:1087
static BOOL ForceUpdateAppsDB()
Definition: available.cpp:317
#define SW_SHOWNORMAL
Definition: winuser.h:764
static BOOL LoadSettings()
Definition: winmain.cpp:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:522
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
HWND hMainWnd
Definition: winmain.cpp:16
BOOL bSaveWndPos
Definition: winmain.h:7
#define MAKELANGID(p, s)
Definition: nls.h:15
BOOL WINAPI SetForegroundWindow(_In_ HWND)
VOID WINAPI InitCommonControls(void)
Definition: commctrl.c:863
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define SW_MAXIMIZE
Definition: winuser.h:766
HWND CreateMainWindow(LPCTSTR lpCaption, int nCmdShow)
Definition: mainwnd.c:920
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:19

Variable Documentation

◆ gModule

CRAppsModule gModule

Definition at line 31 of file winmain.cpp.

◆ gWinModule

CAtlWinModule gWinModule

Definition at line 32 of file winmain.cpp.

◆ hInst

HINSTANCE hInst

Definition at line 17 of file winmain.cpp.

◆ hMainWnd

HWND hMainWnd

Definition at line 16 of file winmain.cpp.

◆ SelectedEnumType

◆ SettingsInfo

◆ szSearchPattern