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
, RegistrySettings::WallpaperStyle style
)
41 if (desktop
.Open(HKEY_CURRENT_USER
, _T("Control Panel\\Desktop")) == ERROR_SUCCESS
)
43 desktop
.SetStringValue(_T("Wallpaper"), szFileName
);
45 desktop
.SetStringValue(_T("WallpaperStyle"), (style
== RegistrySettings::STRETCHED
) ? _T("2") : _T("1"));
46 desktop
.SetStringValue(_T("TileWallpaper"), (style
== RegistrySettings::TILED
) ? _T("1") : _T("0"));
49 SystemParametersInfo(SPI_SETDESKWALLPAPER
, 0, (PVOID
) szFileName
, SPIF_UPDATEINIFILE
| SPIF_SENDWININICHANGE
);
52 void RegistrySettings::LoadPresets()
65 const WINDOWPLACEMENT DefaultWindowPlacement
= {
66 sizeof(WINDOWPLACEMENT
),
73 WindowPlacement
= DefaultWindowPlacement
;
76 void RegistrySettings::Load()
81 if (view
.Open(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View"), KEY_READ
) == ERROR_SUCCESS
)
83 ReadDWORD(view
, _T("BMPHeight"), BMPHeight
, TRUE
);
84 ReadDWORD(view
, _T("BMPWidth"), BMPWidth
, TRUE
);
85 ReadDWORD(view
, _T("GridExtent"), GridExtent
, FALSE
);
86 ReadDWORD(view
, _T("NoStretching"), NoStretching
, FALSE
);
87 ReadDWORD(view
, _T("ShowThumbnail"), ShowThumbnail
, FALSE
);
88 ReadDWORD(view
, _T("SnapToGrid"), SnapToGrid
, FALSE
);
89 ReadDWORD(view
, _T("ThumbHeight"), ThumbHeight
, TRUE
);
90 ReadDWORD(view
, _T("ThumbWidth"), ThumbWidth
, TRUE
);
91 ReadDWORD(view
, _T("ThumbXPos"), ThumbXPos
, TRUE
);
92 ReadDWORD(view
, _T("ThumbYPos"), ThumbYPos
, TRUE
);
93 ReadDWORD(view
, _T("UnitSetting"), UnitSetting
, FALSE
);
95 ULONG pnBytes
= sizeof(WINDOWPLACEMENT
);
96 view
.QueryBinaryValue(_T("WindowPlacement"), &WindowPlacement
, &pnBytes
);
100 if (files
.Open(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List"), KEY_READ
) == ERROR_SUCCESS
)
102 ReadFileHistory(files
, _T("File1"), strFile1
);
103 ReadFileHistory(files
, _T("File2"), strFile2
);
104 ReadFileHistory(files
, _T("File3"), strFile3
);
105 ReadFileHistory(files
, _T("File4"), strFile4
);
109 void RegistrySettings::Store()
112 if (view
.Create(HKEY_CURRENT_USER
,
113 _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View")) == ERROR_SUCCESS
)
115 view
.SetDWORDValue(_T("BMPHeight"), BMPHeight
);
116 view
.SetDWORDValue(_T("BMPWidth"), BMPWidth
);
117 view
.SetDWORDValue(_T("GridExtent"), GridExtent
);
118 view
.SetDWORDValue(_T("NoStretching"), NoStretching
);
119 view
.SetDWORDValue(_T("ShowThumbnail"), ShowThumbnail
);
120 view
.SetDWORDValue(_T("SnapToGrid"), SnapToGrid
);
121 view
.SetDWORDValue(_T("ThumbHeight"), ThumbHeight
);
122 view
.SetDWORDValue(_T("ThumbWidth"), ThumbWidth
);
123 view
.SetDWORDValue(_T("ThumbXPos"), ThumbXPos
);
124 view
.SetDWORDValue(_T("ThumbYPos"), ThumbYPos
);
125 view
.SetDWORDValue(_T("UnitSetting"), UnitSetting
);
127 view
.SetBinaryValue(_T("WindowPlacement"), &WindowPlacement
, sizeof(WINDOWPLACEMENT
));
131 if (files
.Create(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\Recent File List")) == ERROR_SUCCESS
)
133 if (!strFile1
.IsEmpty())
134 files
.SetStringValue(_T("File1"), strFile1
);
135 if (!strFile2
.IsEmpty())
136 files
.SetStringValue(_T("File2"), strFile2
);
137 if (!strFile3
.IsEmpty())
138 files
.SetStringValue(_T("File3"), strFile3
);
139 if (!strFile4
.IsEmpty())
140 files
.SetStringValue(_T("File4"), strFile4
);
144 void RegistrySettings::SetMostRecentFile(LPCTSTR szPathName
)
146 if (strFile1
== szPathName
)
150 else if (strFile2
== szPathName
)
152 CString strTemp
= strFile2
;
156 else if (strFile3
== szPathName
)
158 CString strTemp
= strFile3
;
163 else if (strFile4
== szPathName
)
165 CString strTemp
= strFile4
;
176 strFile1
= szPathName
;