2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/mspaint/registry.cpp
5 * PURPOSE: Offering functions dealing with registry values
6 * PROGRAMMERS: Benedikt Freisen
9 /* INCLUDES *********************************************************/
15 /* FUNCTIONS ********************************************************/
16 static DWORD
ReadDWORD(CRegKey
&key
, LPCTSTR lpName
, DWORD
&dwValue
, BOOL bCheckForDef
)
18 DWORD dwPrev
= dwValue
;
20 if (key
.QueryDWORDValue(lpName
, dwValue
) != ERROR_SUCCESS
)
23 if (bCheckForDef
&& dwValue
== 0)
29 static void ReadFileHistory(CRegKey
&key
, LPCTSTR lpName
, CString
&strFile
)
31 ULONG nChars
= MAX_PATH
;
32 LPTSTR szFile
= strFile
.GetBuffer(nChars
);
33 if (key
.QueryStringValue(lpName
, szFile
, &nChars
) != ERROR_SUCCESS
)
35 strFile
.ReleaseBuffer();
38 void RegistrySettings::SetWallpaper(LPCTSTR szFileName
, DWORD dwStyle
, DWORD dwTile
)
40 if ((dwStyle
> 2) || (dwTile
> 2))
44 if (desktop
.Open(HKEY_CURRENT_USER
, _T("Control Panel\\Desktop")) == ERROR_SUCCESS
)
46 CString strStyle
, strTile
;
48 desktop
.SetStringValue(_T("Wallpaper"), szFileName
);
50 strStyle
.Format(_T("%lu"), dwStyle
);
51 strTile
.Format(_T("%lu"), dwTile
);
53 desktop
.SetStringValue(_T("WallpaperStyle"), strStyle
);
54 desktop
.SetStringValue(_T("TileWallpaper"), strTile
);
57 SystemParametersInfo(SPI_SETDESKWALLPAPER
, 0, (PVOID
) szFileName
, SPIF_UPDATEINIFILE
| SPIF_SENDWININICHANGE
);
60 void RegistrySettings::LoadPresets()
73 const WINDOWPLACEMENT DefaultWindowPlacement
= {
74 sizeof(WINDOWPLACEMENT
),
81 WindowPlacement
= DefaultWindowPlacement
;
84 void RegistrySettings::Load()
89 if (view
.Open(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View"), KEY_READ
) == ERROR_SUCCESS
)
91 ReadDWORD(view
, _T("BMPHeight"), BMPHeight
, TRUE
);
92 ReadDWORD(view
, _T("BMPWidth"), BMPWidth
, TRUE
);
93 ReadDWORD(view
, _T("GridExtent"), GridExtent
, FALSE
);
94 ReadDWORD(view
, _T("NoStretching"), NoStretching
, FALSE
);
95 ReadDWORD(view
, _T("ShowThumbnail"), ShowThumbnail
, FALSE
);
96 ReadDWORD(view
, _T("SnapToGrid"), SnapToGrid
, FALSE
);
97 ReadDWORD(view
, _T("ThumbHeight"), ThumbHeight
, TRUE
);
98 ReadDWORD(view
, _T("ThumbWidth"), ThumbWidth
, TRUE
);
99 ReadDWORD(view
, _T("ThumbXPos"), ThumbXPos
, TRUE
);
100 ReadDWORD(view
, _T("ThumbYPos"), ThumbYPos
, TRUE
);
101 ReadDWORD(view
, _T("UnitSetting"), UnitSetting
, FALSE
);
103 ULONG pnBytes
= sizeof(WINDOWPLACEMENT
);
104 view
.QueryBinaryValue(_T("WindowPlacement"), &WindowPlacement
, &pnBytes
);
108 if (files
.Open(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List"), KEY_READ
) == ERROR_SUCCESS
)
110 ReadFileHistory(files
, _T("File1"), strFile1
);
111 ReadFileHistory(files
, _T("File2"), strFile2
);
112 ReadFileHistory(files
, _T("File3"), strFile3
);
113 ReadFileHistory(files
, _T("File4"), strFile4
);
117 void RegistrySettings::Store()
120 if (view
.Create(HKEY_CURRENT_USER
,
121 _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View")) == ERROR_SUCCESS
)
123 view
.SetDWORDValue(_T("BMPHeight"), BMPHeight
);
124 view
.SetDWORDValue(_T("BMPWidth"), BMPWidth
);
125 view
.SetDWORDValue(_T("GridExtent"), GridExtent
);
126 view
.SetDWORDValue(_T("NoStretching"), NoStretching
);
127 view
.SetDWORDValue(_T("ShowThumbnail"), ShowThumbnail
);
128 view
.SetDWORDValue(_T("SnapToGrid"), SnapToGrid
);
129 view
.SetDWORDValue(_T("ThumbHeight"), ThumbHeight
);
130 view
.SetDWORDValue(_T("ThumbWidth"), ThumbWidth
);
131 view
.SetDWORDValue(_T("ThumbXPos"), ThumbXPos
);
132 view
.SetDWORDValue(_T("ThumbYPos"), ThumbYPos
);
133 view
.SetDWORDValue(_T("UnitSetting"), UnitSetting
);
135 view
.SetBinaryValue(_T("WindowPlacement"), &WindowPlacement
, sizeof(WINDOWPLACEMENT
));
139 if (files
.Create(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List")) == ERROR_SUCCESS
)
141 if (!strFile1
.IsEmpty())
142 files
.SetStringValue(_T("File1"), strFile1
);
143 if (!strFile2
.IsEmpty())
144 files
.SetStringValue(_T("File2"), strFile2
);
145 if (!strFile3
.IsEmpty())
146 files
.SetStringValue(_T("File3"), strFile3
);
147 if (!strFile4
.IsEmpty())
148 files
.SetStringValue(_T("File4"), strFile4
);
152 void RegistrySettings::SetMostRecentFile(LPCTSTR szPathName
)
154 if (strFile1
== szPathName
)
158 else if (strFile2
== szPathName
)
160 CString strTemp
= strFile2
;
164 else if (strFile3
== szPathName
)
166 CString strTemp
= strFile3
;
171 else if (strFile4
== szPathName
)
173 CString strTemp
= strFile4
;
184 strFile1
= szPathName
;