2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/mspaint/registry.cpp
5 * PURPOSE: Offering functions dealing with registry values
6 * PROGRAMMERS: Benedikt Freisen
10 /* INCLUDES *********************************************************/
17 /* FUNCTIONS ********************************************************/
18 static void ReadDWORD(CRegKey
&key
, LPCTSTR lpName
, DWORD
&dwValue
)
21 if (key
.QueryDWORDValue(lpName
, dwTemp
) == ERROR_SUCCESS
)
25 static void ReadString(CRegKey
&key
, LPCTSTR lpName
, CString
&strValue
, LPCTSTR lpDefault
= TEXT(""))
28 ULONG nChars
= MAX_PATH
;
29 LPTSTR psz
= strTemp
.GetBuffer(nChars
);
30 LONG error
= key
.QueryStringValue(lpName
, psz
, &nChars
);
31 strTemp
.ReleaseBuffer();
33 if (error
== ERROR_SUCCESS
)
39 void RegistrySettings::SetWallpaper(LPCTSTR szFileName
, RegistrySettings::WallpaperStyle style
)
42 if (desktop
.Open(HKEY_CURRENT_USER
, _T("Control Panel\\Desktop")) == ERROR_SUCCESS
)
44 desktop
.SetStringValue(_T("Wallpaper"), szFileName
);
46 desktop
.SetStringValue(_T("WallpaperStyle"), (style
== RegistrySettings::STRETCHED
) ? _T("2") : _T("0"));
47 desktop
.SetStringValue(_T("TileWallpaper"), (style
== RegistrySettings::TILED
) ? _T("1") : _T("0"));
50 SystemParametersInfo(SPI_SETDESKWALLPAPER
, 0, (PVOID
) szFileName
, SPIF_UPDATEINIFILE
| SPIF_SENDCHANGE
);
53 void RegistrySettings::LoadPresets(INT nCmdShow
)
55 BMPHeight
= GetSystemMetrics(SM_CYSCREEN
) / 2;
56 BMPWidth
= GetSystemMetrics(SM_CXSCREEN
) / 2;
69 CharSet
= DEFAULT_CHARSET
;
78 GetObject(GetStockObject(DEFAULT_GUI_FONT
), sizeof(lf
), &lf
);
79 strFontName
= lf
.lfFaceName
;
81 ZeroMemory(&WindowPlacement
, sizeof(WindowPlacement
));
82 RECT
& rc
= WindowPlacement
.rcNormalPosition
;
83 rc
.left
= rc
.top
= CW_USEDEFAULT
;
84 rc
.right
= rc
.left
+ 544;
85 rc
.bottom
= rc
.top
+ 375;
86 WindowPlacement
.showCmd
= nCmdShow
;
89 void RegistrySettings::Load(INT nCmdShow
)
91 LoadPresets(nCmdShow
);
94 if (paint
.Open(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint"), KEY_READ
) != ERROR_SUCCESS
)
98 if (view
.Open(paint
, _T("View"), KEY_READ
) == ERROR_SUCCESS
)
100 ReadDWORD(view
, _T("BMPHeight"), BMPHeight
);
101 ReadDWORD(view
, _T("BMPWidth"), BMPWidth
);
102 ReadDWORD(view
, _T("GridExtent"), GridExtent
);
103 ReadDWORD(view
, _T("NoStretching"), NoStretching
);
104 ReadDWORD(view
, _T("ShowThumbnail"), ShowThumbnail
);
105 ReadDWORD(view
, _T("SnapToGrid"), SnapToGrid
);
106 ReadDWORD(view
, _T("ThumbHeight"), ThumbHeight
);
107 ReadDWORD(view
, _T("ThumbWidth"), ThumbWidth
);
108 ReadDWORD(view
, _T("ThumbXPos"), ThumbXPos
);
109 ReadDWORD(view
, _T("ThumbYPos"), ThumbYPos
);
110 ReadDWORD(view
, _T("UnitSetting"), UnitSetting
);
111 ReadDWORD(view
, _T("ShowStatusBar"), ShowStatusBar
);
113 ULONG pnBytes
= sizeof(WINDOWPLACEMENT
);
114 view
.QueryBinaryValue(_T("WindowPlacement"), &WindowPlacement
, &pnBytes
);
118 if (files
.Open(paint
, _T("Recent File List"), KEY_READ
) == ERROR_SUCCESS
)
121 for (INT i
= 0; i
< MAX_RECENT_FILES
; ++i
)
123 wsprintf(szName
, _T("File%u"), i
+ 1);
124 ReadString(files
, szName
, strFiles
[i
]);
129 if (text
.Open(paint
, _T("Text"), KEY_READ
) == ERROR_SUCCESS
)
131 ReadDWORD(text
, _T("Bold"), Bold
);
132 ReadDWORD(text
, _T("Italic"), Italic
);
133 ReadDWORD(text
, _T("Underline"), Underline
);
134 ReadDWORD(text
, _T("CharSet"), CharSet
);
135 ReadDWORD(text
, _T("PointSize"), PointSize
);
136 ReadDWORD(text
, _T("PositionX"), FontsPositionX
);
137 ReadDWORD(text
, _T("PositionY"), FontsPositionY
);
138 ReadDWORD(text
, _T("ShowTextTool"), ShowTextTool
);
139 ReadString(text
, _T("TypeFaceName"), strFontName
, strFontName
);
143 if (bar4
.Open(paint
, _T("General-Bar4"), KEY_READ
) == ERROR_SUCCESS
)
145 ReadDWORD(bar4
, _T("Visible"), ShowPalette
);
148 // Fix the bitmap size if too large
150 BMPWidth
= (GetSystemMetrics(SM_CXSCREEN
) * 6) / 10;
151 if (BMPHeight
> 5000)
152 BMPHeight
= (GetSystemMetrics(SM_CYSCREEN
) * 6) / 10;
155 void RegistrySettings::Store()
158 if (paint
.Create(HKEY_CURRENT_USER
, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint")) != ERROR_SUCCESS
)
162 if (view
.Create(paint
, _T("View")) == ERROR_SUCCESS
)
164 view
.SetDWORDValue(_T("BMPHeight"), BMPHeight
);
165 view
.SetDWORDValue(_T("BMPWidth"), BMPWidth
);
166 view
.SetDWORDValue(_T("GridExtent"), GridExtent
);
167 view
.SetDWORDValue(_T("NoStretching"), NoStretching
);
168 view
.SetDWORDValue(_T("ShowThumbnail"), ShowThumbnail
);
169 view
.SetDWORDValue(_T("SnapToGrid"), SnapToGrid
);
170 view
.SetDWORDValue(_T("ThumbHeight"), ThumbHeight
);
171 view
.SetDWORDValue(_T("ThumbWidth"), ThumbWidth
);
172 view
.SetDWORDValue(_T("ThumbXPos"), ThumbXPos
);
173 view
.SetDWORDValue(_T("ThumbYPos"), ThumbYPos
);
174 view
.SetDWORDValue(_T("UnitSetting"), UnitSetting
);
175 view
.SetDWORDValue(_T("ShowStatusBar"), ShowStatusBar
);
177 view
.SetBinaryValue(_T("WindowPlacement"), &WindowPlacement
, sizeof(WINDOWPLACEMENT
));
181 if (files
.Create(paint
, _T("Recent File List")) == ERROR_SUCCESS
)
184 for (INT iFile
= 0; iFile
< MAX_RECENT_FILES
; ++iFile
)
186 wsprintf(szName
, _T("File%u"), iFile
+ 1);
187 files
.SetStringValue(szName
, strFiles
[iFile
]);
192 if (text
.Create(paint
, _T("Text")) == ERROR_SUCCESS
)
194 text
.SetDWORDValue(_T("Bold"), Bold
);
195 text
.SetDWORDValue(_T("Italic"), Italic
);
196 text
.SetDWORDValue(_T("Underline"), Underline
);
197 text
.SetDWORDValue(_T("CharSet"), CharSet
);
198 text
.SetDWORDValue(_T("PointSize"), PointSize
);
199 text
.SetDWORDValue(_T("PositionX"), FontsPositionX
);
200 text
.SetDWORDValue(_T("PositionY"), FontsPositionY
);
201 text
.SetDWORDValue(_T("ShowTextTool"), ShowTextTool
);
202 text
.SetStringValue(_T("TypeFaceName"), strFontName
);
206 if (bar4
.Create(paint
, _T("General-Bar4")) == ERROR_SUCCESS
)
208 bar4
.SetDWORDValue(_T("Visible"), ShowPalette
);
212 void RegistrySettings::SetMostRecentFile(LPCTSTR szPathName
)
214 // Register the file to the user's 'Recent' folder
215 if (szPathName
&& szPathName
[0])
216 SHAddToRecentDocs(SHARD_PATHW
, szPathName
);
218 // If szPathName is present in strFiles, move it to the top of the list
219 for (INT i
= MAX_RECENT_FILES
- 1, iFound
= -1; i
> 0; --i
)
221 if (iFound
< 0 && strFiles
[i
].CompareNoCase(szPathName
) == 0)
226 CString tmp
= strFiles
[i
];
227 strFiles
[i
] = strFiles
[i
- 1];
228 strFiles
[i
- 1] = tmp
;
232 // If szPathName is not the first item in strFiles, insert it at the top of the list
233 if (strFiles
[0].CompareNoCase(szPathName
) != 0)
235 for (INT i
= MAX_RECENT_FILES
- 1; i
> 0; --i
)
236 strFiles
[i
] = strFiles
[i
- 1];
238 strFiles
[0] = szPathName
;