1
<html><head><META HTTP-EQUIV=
"Content-Type" CONTENT=
"text/html; CHARSET=utf-8" /><META NAME=
"save" CONTENT=
"history" /><title xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt">Save Window Placement State Sample
</title><META NAME=
"Description" CONTENT=
"
 This sample illustrates how to save the size, location, and state of a T:System.Windows.Window to ensure that the T:System.Windows.Window opens in the same position it was closed. Furthermore, this sample is multi-monitor aware. ..."></META><META NAME=
"MS.LOCALE" CONTENT=
"en-us" /><style>
3 {font-family:Verdana;font-size:medium;}
4 div#mainSection, div#header
5 {font-size:
70%;width:
100%;}
8 div#mainSection div table
9 {font-size:
100%;text-align: left;}
11 {color:#
003399;font-size:
90%;font-weight:
600;}
13 {background-color:#D4DFFF;}
15 {font-size:
120%;color:#
003399;}
17 {font-size:
100%;margin-bottom:
4;}
19 {margin-top:-
2;margin-bottom:
3;}
21 {margin-top:
10;margin-bottom:
5;}
23 {margin-top:
1;margin-bottom:
4;}
24 div#mainSection table th
25 {background-color:#EFEFF7;color:#
000066;text-align:left;}
26 div#mainSection table td
27 {background-color:#F7F7FF;}
29 {margin-top:
5px;margin-bottom: px;}
30 </style></head><body><div id=
"header"><table width=
"100%" id=
"topTable"></table></div><div id=
"mainSection"><div id=
"mainBody"><br /><font color=
"DarkGray">[This readme is a partial copy of the sample's topic in the SDK documentation.]
</font><br /><font color=
"DarkGray" xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt"></font><p xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt"></p><div class=
"introduction"><p xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt">
31 This sample illustrates how to save the size, location, and state of a
<span sdata=
"cer" target=
"T:System.Windows.Window">Window
</span> to ensure that the
<span sdata=
"cer" target=
"T:System.Windows.Window">Window
</span> opens in the same position it was closed. Furthermore, this sample is multi-monitor aware.
32 </p><p xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt">
33 This sample demonstrates a specific feature of the Windows Presentation Foundation and, consequently, does not follow application development best practices. For comprehensive coverage of Windows Presentation Foundation (WPF) and Microsoft .NET Framework application development best practices, refer to the following as appropriate:
34 </p><p xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt">
35 Accessibility -
<span sdata=
"link">Accessibility Best Practices
</span></p><p xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt">
36 Localization -
<span sdata=
"link">WPF Globalization and Localization Overview
</span></p><p xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt">
37 Performance -
<span sdata=
"link">Optimizing WPF Application Performance
</span></p><p xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt">
38 Security -
<span sdata=
"link">Windows Presentation Foundation Security
</span></p></div><h1 class=
"heading" xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt"><span onclick=
"ExpandCollapse(sectionToggle0)" style=
"cursor:default;" onkeypress=
"ExpandCollapse_CheckKey(sectionToggle0, event)" tabindex=
"0">Building the Sample
</span></h1><div id=
"sectionSection0" class=
"section"><ul xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt"><li><p>
39 Install the Windows Software Development Kit (SDK) and open its build environment command window. On the Start menu, point to All Programs, Microsoft Windows SDK, and then click CMD Shell.
41 Download the sample, usually from the software development kit (SDK) documentation, to your hard disk drive.
43 To build the sample from the build environment command window, go to the source directory of the sample. At the command prompt, type MSBUILD.
45 To build the sample in Microsoft Visual Studio, load the sample solution or project file and then press CTRL+SHIFT+B.
46 </p></li></ul></div><h1 class=
"heading" xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt"><span onclick=
"ExpandCollapse(sectionToggle1)" style=
"cursor:default;" onkeypress=
"ExpandCollapse_CheckKey(sectionToggle1, event)" tabindex=
"0">Running the Sample
</span></h1><div id=
"sectionSection1" class=
"section"><ul xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt"><li><p>
47 To run the compiled sample from the build environment command window, execute the .exe file in the Bin\Debug or Bin\Release folder contained under the sample source code folder.
49 To run the compiled sample with debugging in Visual Studio, press F5.
50 </p></li></ul></div><h1 class=
"heading" xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt"><span onclick=
"ExpandCollapse(sectionToggle2)" style=
"cursor:default;" onkeypress=
"ExpandCollapse_CheckKey(sectionToggle2, event)" tabindex=
"0">Remarks
</span></h1><div id=
"sectionSection2" class=
"section"><p xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt">
51 This sample illustrates how to save the size, location, and state of a
<span sdata=
"cer" target=
"T:System.Windows.Window">Window
</span> so the
<span sdata=
"cer" target=
"T:System.Windows.Window">Window
</span> opens in the same position it was closed. Furthermore, this sample is multi-monitor aware, which means that if the monitor on which the
<span sdata=
"cer" target=
"T:System.Windows.Window">Window
</span> was closed is disconnected, the
<span sdata=
"cer" target=
"T:System.Windows.Window">Window
</span> is shown on a connected monitor instead.
52 </p><p xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt">
53 This requires using the following Win32 APIs (from User32.dll):
54 </p><p xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt"><b>WINDOWPLACEMENT
</b>: To store window size, location, and state (see WINDOWPLACEMENT Structure).
55 </p><p xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt"><b>GetWindowPlacement
</b>: To retrieve the current WINDOWPLACEMENT data for the window before it closes (see GetWindowPlacement Function).
56 </p><p xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt"><b>SetWindowPlacement
</b>: To restore the WINDOWPLACEMENT data when the window opens (see SetWindowPlacement Function).
57 </p><p xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt">
58 The
<b>WINDOWPLACEMENT
</b> structure is physically stored on disk using the Microsoft .NET Framework support for strongly-typed application settings (see Application Settings Overview).
59 </p></div><h1 class=
"heading" xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt"><span onclick=
"ExpandCollapse(seeAlsoToggle)" style=
"cursor:default;" onkeypress=
"ExpandCollapse_CheckKey(seeAlsoToggle, event)" tabindex=
"0">See Also
</span></h1><div id=
"seeAlsoSection" class=
"section"><h4 class=
"subHeading" xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt">Reference
</h4><div class=
"seeAlsoStyle"><span sdata=
"cer" target=
"T:System.Windows.Window" xmlns:
mshelp=
"http://msdn.microsoft.com/mshelp" xmlns:
msxsl=
"urn:schemas-microsoft-com:xslt">Window
</span></div></div></div></div></body></html>