mwinapi-commits Mailing List for Managed Windows API (Page 4)
Status: Beta
Brought to you by:
schierlm
You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
(2) |
Apr
(5) |
May
(1) |
Jun
(6) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(2) |
Feb
(2) |
Mar
(1) |
Apr
(1) |
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(5) |
Dec
|
2010 |
Jan
(2) |
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
(1) |
Dec
|
2011 |
Jan
(10) |
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2012 |
Jan
(1) |
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(4) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(8) |
Dec
|
2015 |
Jan
(2) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(7) |
2016 |
Jan
(4) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(2) |
2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(3) |
Oct
|
Nov
|
Dec
|
2024 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(3) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <sch...@us...> - 2008-06-14 20:18:56
|
Revision: 75 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=75&view=rev Author: schierlm Date: 2008-06-14 13:18:49 -0700 (Sat, 14 Jun 2008) Log Message: ----------- made a copy Added Paths: ----------- releases/0.3/ Copied: releases/0.3 (from rev 74, trunk) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sch...@us...> - 2008-06-14 19:42:35
|
Revision: 74 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=74&view=rev Author: schierlm Date: 2008-06-14 12:42:31 -0700 (Sat, 14 Jun 2008) Log Message: ----------- Prepare for 0.3 release Modified Paths: -------------- trunk/ManagedWinapi/Properties/AssemblyInfo.cs trunk/Tools/WinternalExplorer/Properties/AssemblyInfo.cs trunk/nant.build trunk/readme.txt trunk/website/index.html Modified: trunk/ManagedWinapi/Properties/AssemblyInfo.cs =================================================================== --- trunk/ManagedWinapi/Properties/AssemblyInfo.cs 2008-06-14 19:03:48 UTC (rev 73) +++ trunk/ManagedWinapi/Properties/AssemblyInfo.cs 2008-06-14 19:42:31 UTC (rev 74) @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ManagedWinapi")] -[assembly: AssemblyCopyright("Copyright © 2005, 2006, 2007 Michael Schierl")] +[assembly: AssemblyCopyright("Copyright © 2005, 2006, 2007, 2008 Michael Schierl")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -31,5 +31,5 @@ // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.2")] -[assembly: AssemblyFileVersion("0.2")] +[assembly: AssemblyVersion("0.3")] +[assembly: AssemblyFileVersion("0.3")] Modified: trunk/Tools/WinternalExplorer/Properties/AssemblyInfo.cs =================================================================== --- trunk/Tools/WinternalExplorer/Properties/AssemblyInfo.cs 2008-06-14 19:03:48 UTC (rev 73) +++ trunk/Tools/WinternalExplorer/Properties/AssemblyInfo.cs 2008-06-14 19:42:31 UTC (rev 74) @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("WinternalExplorer")] -[assembly: AssemblyCopyright("Copyright © 2007 Michael Schierl")] +[assembly: AssemblyCopyright("Copyright © 2007, 2008 Michael Schierl")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -29,5 +29,5 @@ // Build Number // Revision // -[assembly: AssemblyVersion("0.2")] -[assembly: AssemblyFileVersion("0.2")] +[assembly: AssemblyVersion("0.3")] +[assembly: AssemblyFileVersion("0.3")] Modified: trunk/nant.build =================================================================== --- trunk/nant.build 2008-06-14 19:03:48 UTC (rev 73) +++ trunk/nant.build 2008-06-14 19:42:31 UTC (rev 74) @@ -72,41 +72,7 @@ </foreach> </target> - <target name="ndoc" depends="build-dll"> - <ndoc> - <assemblies basedir="ManagedWinapi\bin\release"> - <include name="ManagedWinapi.dll" /> - </assemblies> - <documenters> - <documenter name="MSDN"> - <property name="OutputDirectory" value="build\doc\" /> - <property name="HtmlHelpName" value="ManagedWinapi" /> - <property name="Title" value="An NDoc Documented Class Library" /> - <property name="DocumentInheritedFrameworkMembers" value="False" /> - <property name="FeedbackEmailAddress" value="sch...@us..." /> - <property name="IncludeDefaultThreadSafety" value="False" /> - <property name="StaticMembersDefaultToSafe" value="False" /> - <property name="CleanIntermediates" value="True" /> - </documenter> - </documenters> - </ndoc> - <echo file="build/doc/tree.css" append="True"> - html { height: 100%; } - body { height: 95%; } - </echo> - <copy file="build/doc/ManagedWinapi.chm" todir="build/bin"/> - <mkdir dir="build/htmldoc"/> - <copy todir="build/htmldoc"> - <fileset basedir="build/doc"> - <include name="*.html" /> - <include name="*.gif" /> - <include name="*.css" /> - <include name="tree.js" /> - </fileset> - </copy> - </target> - - <target name="dist" depends="ndoc,build"> + <target name="dist" depends="build"> <mkdir dir="dist/bin"/> <mkdir dir="dist/tools"/> <mkdir dir="dist/src"/> @@ -137,7 +103,7 @@ <copy todir="dist/src"> <fileset basedir="."> <include name="COPYING"/> - <include name="ManagedWinap.ndoc"/> + <include name="ManagedWinapi.shfb"/> <include name="ManagedWinapi.sln"/> <include name="nant.build"/> <include name="readme.txt"/> Modified: trunk/readme.txt =================================================================== --- trunk/readme.txt 2008-06-14 19:03:48 UTC (rev 73) +++ trunk/readme.txt 2008-06-14 19:42:31 UTC (rev 74) @@ -1,12 +1,12 @@ -ManagedWinapi 0.2 +ManagedWinapi 0.3 ~~~~~~~~~~~~~~~~~ A collection of .NET components that wrap PInvoke calls to access native API by managed code. For documentation for these functions, look at ManagedWinapi.chm in the -binary release or generate it with ndoc from http://ndoc.sourceforge.net/ -from the source release. +binary release or generate it with Sandcastle Help File Builder available +from http://codeplex.com/SHFB from the source release. This library is licensed by the GNU Lesser General Public License. @@ -15,7 +15,7 @@ You may contact me at <sch...@us...>. -ManagedWinapi Tools 0.2 +ManagedWinapi Tools 0.3 ~~~~~~~~~~~~~~~~~~~~~~~ Started as a collection of ManagedWinapi samples, the Managed Winapi tools @@ -31,6 +31,43 @@ ~~~~~~~~~ ++++ 2008-06-14 Released Version 0.3 +++ + + +- Added AccessibleEventListener ProcessId and ThreadId members to limit + events to process or thread. [bbauer] +- Set default event for ClipboardNotifier, Crosshair and Hotkey, + Add properties Location and Size and methods IsValid and SendClose to SystemWindow. + [suggested by Frank Koch] +- Add functionality to low-level keyboard hook for translating low-level + events to typed keys. +- Added several new classes: + * Compute several kinds of machine IDs from C# + * Shutdown the system + * Set the system time + * Get list of codepoints supported by a font +- Winternal Explorer: + * added window-highlighting while dragging crosshair + * Add checkbox to disable heuristics when determining control from point + (these heuristics fail for some MDI applications like Visual Studio) + * reduce flickering when crosshair is dragged + * Fix a crash when calling TreeNodeData.Equals with an instance of a different + subclass as its parameter + * Fix refresh of tree when releasing crosshair + * Fix PossibleParents so that windows that are children of a window of a different + process (most prominent example: screensaver preview in control panel) can be + found in tree. +- bug fixes: + * Fix a problem with applications that return invalid accessible children. + [submitted by Karl Gyllstrom <karl at cs dot unc dot edu>] + * Use the managed Control#Capture property instead of calling the SetCapture + PInvoke method. + * Fix unsetting of modifier keys in LockKeyResetter + * Set proper scancode for injected keyboard events + (some applications, like MS-DOS based ones, need them). +- Use Sandcastle Help File Builder instead of NDoc for the API documentation + + +++ 2007-05-28 Released Version 0.2 +++ Modified: trunk/website/index.html =================================================================== --- trunk/website/index.html 2008-06-14 19:03:48 UTC (rev 73) +++ trunk/website/index.html 2008-06-14 19:42:31 UTC (rev 74) @@ -57,19 +57,19 @@ <h2 id="download">Where can I download those components?</h2> <p><a -href="http://prdownloads.sourceforge.net/mwinapi/managedwinapi-0.2.zip?download">Binary -download (including HTML-help documentation)</a> (Version 0.2, 272 KB)</p> +href="http://prdownloads.sourceforge.net/mwinapi/managedwinapi-0.3.zip?download">Binary +download (including HTML-help documentation)</a> (Version 0.3, 391 KB)</p> <p><a -href="http://prdownloads.sourceforge.net/mwinapi/managedwinapi-src-0.2.zip?download">Source -download</a> (Version 0.2, 568 KB)</p> +href="http://prdownloads.sourceforge.net/mwinapi/managedwinapi-src-0.3.zip?download">Source +download</a> (Version 0.3, 578 KB)</p> -<p><a href="http://prdownloads.sourceforge.net/mwinapi/managedwinapi-tools-0.2.zip?download">Tools</a> (Version 0.2, 200 KB)</p> +<p><a href="http://prdownloads.sourceforge.net/mwinapi/managedwinapi-tools-0.3.zip?download">Tools</a> (Version 0.3, 205 KB)</p> <h2 id="features">What components are included?</h2> <p>See the <a href="doc/index.html">HTML documentation</a> (generated -by <a href="http://ndoc.sourceforge.net">ndoc</a>)</p> +by <a href="http://codeplex.com/SHFB/">Sandcastle Help File Builder</a>)</p> <h2>What is the license of these components?</h2> @@ -113,7 +113,7 @@ are a developer) from subversion.</p> <p>Anonymous access: Use <br/> -<tt>svn co https://svn.sourceforge.net/svnroot/mwinapi/trunk mwinapi</tt><br/> +<tt>svn co https://mwinapi.svn.sourceforge.net/svnroot/mwinapi/trunk mwinapi</tt><br/> to check out the latest version. You can also use GUI programs like <a href="http://tortoisesvn.tigris.org">TortoiseSVN (Explorer plugin)</a> or <a href="http://ankhsvn.tigris.org">AnkhSVN (Visual Studio plugin)</a>.</p> @@ -122,7 +122,7 @@ need a sourceforge.net account for this. Or submit your changes by e-mail; then I will commit them.</p> -<p>You can also <a href="http://svn.sourceforge.net/viewvc/mwinapi/">browse +<p>You can also <a href="http://mwinapi.svn.sourceforge.net/viewvc/mwinapi/">browse the repository</a>.</p> <h2>Contact me</h2> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sch...@us...> - 2008-06-14 19:03:51
|
Revision: 73 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=73&view=rev Author: schierlm Date: 2008-06-14 12:03:48 -0700 (Sat, 14 Jun 2008) Log Message: ----------- Use Sandcastle Help File Builder instead of NDoc for the API documentation Added Paths: ----------- trunk/ManagedWinapi.shfb Removed Paths: ------------- trunk/ManagedWinapi.ndoc Deleted: trunk/ManagedWinapi.ndoc =================================================================== --- trunk/ManagedWinapi.ndoc 2008-06-14 19:02:21 UTC (rev 72) +++ trunk/ManagedWinapi.ndoc 2008-06-14 19:03:48 UTC (rev 73) @@ -1,46 +0,0 @@ -<project SchemaVersion="1.3"> - <assemblies> - <assembly location=".\ManagedWinapi\bin\Debug\ManagedWinapi.dll" documentation=".\ManagedWinapi\bin\Debug\ManagedWinapi.xml" /> - </assemblies> - <documenters> - <documenter name="VS.NET 2003"> - <property name="OutputDirectory" value=".\doc\" /> - <property name="HtmlHelpName" value="Documentation" /> - <property name="Title" value="An NDoc documented library" /> - </documenter> - <documenter name="MSDN"> - <property name="OutputDirectory" value=".\doc\" /> - <property name="HtmlHelpName" value="ManagedWinapi" /> - <property name="Title" value="An NDoc Documented Class Library" /> - <property name="DocumentInheritedMembers" value="False" /> - <property name="DocumentInheritedFrameworkMembers" value="False" /> - <property name="FeedbackEmailAddress" value="sch...@us..." /> - <property name="IncludeDefaultThreadSafety" value="False" /> - <property name="StaticMembersDefaultToSafe" value="False" /> - <property name="CleanIntermediates" value="True" /> - </documenter> - <documenter name="LaTeX"> - <property name="OutputDirectory" value=".\doc\" /> - <property name="TextFileFullName" value="Documentation.tex" /> - <property name="TexFileBaseName" value="Documentation" /> - <property name="LatexCompiler" value="latex" /> - <property name="TexFileFullPath" value=".\doc\Documentation.tex" /> - </documenter> - <documenter name="MSDN 2003"> - <property name="OutputDirectory" value=".\doc\" /> - <property name="HtmlHelpName" value="ManagedWinapi" /> - <property name="Title" value="An NDoc Documented Class Library" /> - <property name="OutputTarget" value="Web" /> - </documenter> - <documenter name="Linear Html"> - <property name="OutputDirectory" value=".\doc\" /> - <property name="Title" value="An NDoc Documented Class Library" /> - </documenter> - <documenter name="Intellisense"> - <property name="OutputDirectory" value=".\intellisense\" /> - </documenter> - <documenter name="JavaDoc"> - <property name="OutputDirectory" value=".\doc\" /> - </documenter> - </documenters> -</project> \ No newline at end of file Added: trunk/ManagedWinapi.shfb =================================================================== --- trunk/ManagedWinapi.shfb (rev 0) +++ trunk/ManagedWinapi.shfb 2008-06-14 19:03:48 UTC (rev 73) @@ -0,0 +1,49 @@ +<project schemaVersion="1.6.0.7"> + <assemblies> + <assembly assemblyPath=".\ManagedWinapi\bin\Release\ManagedWinapi.dll" xmlCommentsPath=".\ManagedWinapi\bin\Release\ManagedWinapi.xml" commentsOnly="False" /> + </assemblies> + <namespaceSummaries> + <namespaceSummaryItem name="" isDocumented="False" /> + </namespaceSummaries> + <ProjectSummary /> + <MissingTags>AutoDocumentCtors</MissingTags> + <VisibleItems>Protected, SealedProtected</VisibleItems> + <HtmlHelp1xCompilerPath path="" /> + <HtmlHelp2xCompilerPath path="" /> + <OutputPath>.\website\doc\</OutputPath> + <SandcastlePath path="D:\Progs\Sandcastle\" /> + <WorkingPath path="" /> + <CleanIntermediates>True</CleanIntermediates> + <KeepLogFile>False</KeepLogFile> + <BuildLogFile path="" /> + <HelpFileFormat>Help1xAndWebsite</HelpFileFormat> + <CppCommentsFixup>False</CppCommentsFixup> + <FrameworkVersion>2.0.50727</FrameworkVersion> + <IndentHtml>False</IndentHtml> + <Preliminary>False</Preliminary> + <RootNamespaceContainer>False</RootNamespaceContainer> + <RootNamespaceTitle /> + <HelpTitle>Managed Windows API</HelpTitle> + <HtmlHelpName>ManagedWinapi</HtmlHelpName> + <Language>en-US</Language> + <CopyrightHref /> + <CopyrightText>Copyright © 2005, 2006, 2007, 2008 Michael Schierl</CopyrightText> + <FeedbackEMailAddress>sch...@us...</FeedbackEMailAddress> + <FeedbackEMailLinkText /> + <HeaderText /> + <FooterText /> + <ProjectLinkType>Local</ProjectLinkType> + <SdkLinkType>Msdn</SdkLinkType> + <SdkLinkTarget>Blank</SdkLinkTarget> + <PresentationStyle>Prototype</PresentationStyle> + <NamingMethod>MemberName</NamingMethod> + <SyntaxFilters>CSharp</SyntaxFilters> + <ShowFeedbackControl>False</ShowFeedbackControl> + <BinaryTOC>True</BinaryTOC> + <IncludeFavorites>False</IncludeFavorites> + <CollectionTocStyle>Hierarchical</CollectionTocStyle> + <IncludeStopWordList>True</IncludeStopWordList> + <PlugInNamespaces>ms.vsipcc+, ms.vsexpresscc+</PlugInNamespaces> + <HelpFileVersion>1.0.0.0</HelpFileVersion> + <ContentPlacement>AboveNamespaces</ContentPlacement> +</project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sch...@us...> - 2008-06-14 19:02:22
|
Revision: 72 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=72&view=rev Author: schierlm Date: 2008-06-14 12:02:21 -0700 (Sat, 14 Jun 2008) Log Message: ----------- PrivilegedActions: Shutdown and set system time Modified Paths: -------------- trunk/ManagedWinapi/CodepointRange.cs trunk/ManagedWinapi/ManagedWinapi.csproj Added Paths: ----------- trunk/ManagedWinapi/PrivilegedActions.cs Modified: trunk/ManagedWinapi/CodepointRange.cs =================================================================== --- trunk/ManagedWinapi/CodepointRange.cs 2008-06-14 18:49:09 UTC (rev 71) +++ trunk/ManagedWinapi/CodepointRange.cs 2008-06-14 19:02:21 UTC (rev 72) @@ -164,6 +164,8 @@ } #region Equals and HashCode + + /// public override bool Equals(object obj) { CodepointRange cr = obj as CodepointRange; @@ -181,6 +183,7 @@ return true; } + /// public override int GetHashCode() { return 3 * codepointCount + 7 * ranges.Length + 9 * FirstCodepoint + 11 * LastCodepoint; @@ -192,10 +195,10 @@ private static extern uint GetFontUnicodeRanges(IntPtr hdc, IntPtr lpgs); [DllImport("gdi32.dll")] - private extern static IntPtr SelectObject(IntPtr hDC, IntPtr hObject); + private static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject); [DllImport("gdi32.dll")] - public static extern bool DeleteObject(IntPtr hObject); + private static extern bool DeleteObject(IntPtr hObject); #endregion } } Modified: trunk/ManagedWinapi/ManagedWinapi.csproj =================================================================== --- trunk/ManagedWinapi/ManagedWinapi.csproj 2008-06-14 18:49:09 UTC (rev 71) +++ trunk/ManagedWinapi/ManagedWinapi.csproj 2008-06-14 19:02:21 UTC (rev 72) @@ -66,6 +66,7 @@ <Compile Include="ShortcutBox.Designer.cs"> <DependentUpon>ShortcutBox.cs</DependentUpon> </Compile> + <Compile Include="PrivilegedActions.cs" /> <Compile Include="SystemAccessibleObject.cs" /> <Compile Include="ApiHelper.cs" /> <Compile Include="ClipboardNotifier.cs"> Added: trunk/ManagedWinapi/PrivilegedActions.cs =================================================================== --- trunk/ManagedWinapi/PrivilegedActions.cs (rev 0) +++ trunk/ManagedWinapi/PrivilegedActions.cs 2008-06-14 19:02:21 UTC (rev 72) @@ -0,0 +1,168 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace ManagedWinapi +{ + /// <summary> + /// Collection of miscellaneous actions that cannot be performed as + /// a non-administrative user, like shutdown or setting the system time. + /// </summary> + public static class PrivilegedActions + { + /// <summary> + /// Shutdown the system. + /// </summary> + public static void ShutDown(ShutdownAction action) + { + ShutDown(action, ShutdownForceMode.NoForce); + } + + /// <summary> + /// Shutdown the system. + /// </summary> + public static void ShutDown(ShutdownAction action, ShutdownForceMode forceMode) + { + ApiHelper.FailIfZero(ExitWindowsEx((uint)action | (uint)forceMode, SHTDN_REASON_FLAG_PLANNED)); + } + + /// <summary> + /// Get or set the system time in the local timezone. + /// </summary> + public static DateTime LocalTime + { + get + { + SYSTEMTIME st = new SYSTEMTIME(); + ApiHelper.FailIfZero(GetLocalTime(ref st)); + return st.ToDateTime(); + } + + set + { + SYSTEMTIME st = new SYSTEMTIME(value); + // Set it twice due to possible daylight savings change + ApiHelper.FailIfZero(SetLocalTime(ref st)); + ApiHelper.FailIfZero(SetLocalTime(ref st)); + } + } + + /// <summary> + /// Get or set the system time, in UTC. + /// </summary> + public static DateTime SystemTime + { + get + { + SYSTEMTIME st = new SYSTEMTIME(); + ApiHelper.FailIfZero(GetSystemTime(ref st)); + return st.ToDateTime(); + } + + set + { + SYSTEMTIME st = new SYSTEMTIME(value); + ApiHelper.FailIfZero(SetLocalTime(ref st)); + } + } + + /// <summary> + /// Actions that can be performed at shutdown. + /// </summary> + public enum ShutdownAction : uint + { + /// <summary> + /// Log off the currently logged-on user. + /// </summary> + LogOff = 0x00, + + /// <summary> + /// Shut down the system. + /// </summary> + ShutDown = 0x01, + + /// <summary> + /// Reboot the system. + /// </summary> + Reboot = 0x02, + + /// <summary> + /// Shut down the system and power it off. + /// </summary> + PowerOff = 0x08, + + /// <summary> + /// Reboot the system and restart applications that are running + /// now and support this feature. + /// </summary> + RestartApps = 0x40, + } + + /// <summary> + /// Whether shutdown should be forced if an application cancels it + /// or is hung. + /// </summary> + public enum ShutdownForceMode : uint + { + /// <summary> + /// Do not force shutdown, applications can cancel it. + /// </summary> + NoForce = 0x00, + + /// <summary> + /// Force shutdown, even if application cancels it or is hung. + /// </summary> + Force = 0x04, + + /// <summary> + /// Force shutdown if application is hung, but not if it cancels it. + /// </summary> + ForceIfHung = 0x10 + } + + #region PInvoke Declarations + + [DllImport("user32.dll", SetLastError = true)] + static extern int ExitWindowsEx(uint uFlags, uint dwReason); + + const uint SHTDN_REASON_FLAG_PLANNED = 0x80000000; + + struct SYSTEMTIME + { + internal ushort wYear, wMonth, wDayOfWeek, wDay, + wHour, wMinute, wSecond, wMilliseconds; + + internal SYSTEMTIME(DateTime time) + { + wYear = (ushort)time.Year; + wMonth = (ushort)time.Month; + wDayOfWeek = (ushort)time.DayOfWeek; + wDay = (ushort)time.Day; + wHour = (ushort)time.Hour; + wMinute = (ushort)time.Minute; + wSecond = (ushort)time.Second; + wMilliseconds = (ushort)time.Millisecond; + } + + internal DateTime ToDateTime() + { + return new DateTime(wYear, wMonth, wDay, wHour, wMinute, wSecond, wMilliseconds); + } + } + + [DllImport("kernel32.dll", SetLastError = true)] + static extern int GetSystemTime(ref SYSTEMTIME lpSystemTime); + + [DllImport("kernel32.dll", SetLastError = true)] + static extern int SetSystemTime(ref SYSTEMTIME lpSystemTime); + + [DllImport("kernel32.dll", SetLastError = true)] + static extern int GetLocalTime(ref SYSTEMTIME lpSystemTime); + + [DllImport("kernel32.dll", SetLastError = true)] + static extern int SetLocalTime(ref SYSTEMTIME lpSystemTime); + + #endregion + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sch...@us...> - 2008-06-14 18:49:10
|
Revision: 71 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=71&view=rev Author: schierlm Date: 2008-06-14 11:49:09 -0700 (Sat, 14 Jun 2008) Log Message: ----------- WinternalExplorer: Add checkbox to disable heuristics when determining control from point (these heuristics fail for some MDI applications like Visual Studio) Modified Paths: -------------- trunk/Tools/WinternalExplorer/MainForm.Designer.cs trunk/Tools/WinternalExplorer/MainForm.cs Modified: trunk/Tools/WinternalExplorer/MainForm.Designer.cs =================================================================== --- trunk/Tools/WinternalExplorer/MainForm.Designer.cs 2008-06-14 18:29:56 UTC (rev 70) +++ trunk/Tools/WinternalExplorer/MainForm.Designer.cs 2008-06-14 18:49:09 UTC (rev 71) @@ -64,6 +64,7 @@ this.selChildWindows = new System.Windows.Forms.RadioButton(); this.selToplevel = new System.Windows.Forms.RadioButton(); this.crossHair = new ManagedWinapi.Crosshair(); + this.heuristicSearch = new System.Windows.Forms.CheckBox(); this.menuStrip1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -90,7 +91,7 @@ this.toolsToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(592, 24); + this.menuStrip1.Size = new System.Drawing.Size(671, 24); this.menuStrip1.TabIndex = 2; this.menuStrip1.Text = "menuStrip1"; // @@ -311,6 +312,7 @@ // // splitContainer1.Panel2 // + this.splitContainer1.Panel2.Controls.Add(this.heuristicSearch); this.splitContainer1.Panel2.Controls.Add(this.allowChanges); this.splitContainer1.Panel2.Controls.Add(this.autoHide); this.splitContainer1.Panel2.Controls.Add(this.details); @@ -319,7 +321,7 @@ this.splitContainer1.Panel2.Controls.Add(this.selToplevel); this.splitContainer1.Panel2.Controls.Add(this.crossHair); this.splitContainer1.Panel2.Paint += new System.Windows.Forms.PaintEventHandler(this.splitContainer1_Panel2_Paint); - this.splitContainer1.Size = new System.Drawing.Size(592, 349); + this.splitContainer1.Size = new System.Drawing.Size(671, 349); this.splitContainer1.SplitterDistance = 195; this.splitContainer1.TabIndex = 4; this.splitContainer1.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(this.splitContainer1_SplitterMoved); @@ -352,7 +354,7 @@ | System.Windows.Forms.AnchorStyles.Right))); this.details.Location = new System.Drawing.Point(3, 45); this.details.Name = "details"; - this.details.Size = new System.Drawing.Size(390, 304); + this.details.Size = new System.Drawing.Size(469, 304); this.details.TabIndex = 5; this.details.TabStop = false; this.details.Text = "Details"; @@ -398,11 +400,23 @@ this.crossHair.CrosshairDragged += new System.EventHandler(this.crossHair_CrosshairDragged); this.crossHair.CrosshairDragging += new System.EventHandler(this.crossHair_CrosshairDragging); // + // heuristicSearch + // + this.heuristicSearch.AutoSize = true; + this.heuristicSearch.Checked = true; + this.heuristicSearch.CheckState = System.Windows.Forms.CheckState.Checked; + this.heuristicSearch.Location = new System.Drawing.Point(308, 22); + this.heuristicSearch.Name = "heuristicSearch"; + this.heuristicSearch.Size = new System.Drawing.Size(138, 17); + this.heuristicSearch.TabIndex = 8; + this.heuristicSearch.Text = "Heuristic Control search"; + this.heuristicSearch.UseVisualStyleBackColor = true; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(592, 373); + this.ClientSize = new System.Drawing.Size(671, 373); this.Controls.Add(this.splitContainer1); this.Controls.Add(this.menuStrip1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); @@ -457,6 +471,7 @@ private System.Windows.Forms.ToolStripMenuItem stolenOrphanWindowsToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator5; private System.Windows.Forms.ToolStripMenuItem visibleObjectsOnlyToolStripMenuItem; + private System.Windows.Forms.CheckBox heuristicSearch; } } Modified: trunk/Tools/WinternalExplorer/MainForm.cs =================================================================== --- trunk/Tools/WinternalExplorer/MainForm.cs 2008-06-14 18:29:56 UTC (rev 70) +++ trunk/Tools/WinternalExplorer/MainForm.cs 2008-06-14 18:49:09 UTC (rev 71) @@ -247,6 +247,8 @@ else { SystemWindow sw = SystemWindow.FromPointEx(lastX, lastY, selToplevel.Checked, false); + if (!heuristicSearch.Checked && !selToplevel.Checked) + sw = SystemWindow.FromPoint(lastX, lastY); if (sw != highlightedWindow) { if (highlightedWindow != null) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sch...@us...> - 2008-06-14 18:29:57
|
Revision: 70 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=70&view=rev Author: schierlm Date: 2008-06-14 11:29:56 -0700 (Sat, 14 Jun 2008) Log Message: ----------- WinternalExplorer: * Fix refresh of tree when releasing Crosshair * Fix PossibleParents so that windows that are children of a window of a different process (most prominent example: screensaver preview in control panel) can be found in tree. Modified Paths: -------------- trunk/Tools/WinternalExplorer/MainForm.cs trunk/Tools/WinternalExplorer/TreeNodeData.cs Modified: trunk/Tools/WinternalExplorer/MainForm.cs =================================================================== --- trunk/Tools/WinternalExplorer/MainForm.cs 2008-05-01 20:24:28 UTC (rev 69) +++ trunk/Tools/WinternalExplorer/MainForm.cs 2008-06-14 18:29:56 UTC (rev 70) @@ -212,28 +212,30 @@ lastX = MousePosition.X; lastY = MousePosition.Y; UpdateSelection(true); - if (highlightedWindow != null) - { - highlightedWindow.Refresh(); - highlightedWindow = null; - } + if (highlightedWindow != null) + { + highlightedWindow.Refresh(); + highlightedWindow = null; + } this.Cursor = null; } SelectableTreeNodeData lastNode = null; + bool lastIncludeTree = false; private void UpdateSelection(bool includeTree) { SelectableTreeNodeData stnd = SelectFromPoint(lastX, lastY); if (!Visible) Visible = true; - if (!stnd.Equals(lastNode)) + if (!stnd.Equals(lastNode) || includeTree != lastIncludeTree) { DoSelect(stnd, includeTree); lastNode = stnd; + lastIncludeTree = includeTree; } } - SystemWindow highlightedWindow; + SystemWindow highlightedWindow; private SelectableTreeNodeData SelectFromPoint(int lastX, int lastY) { @@ -245,19 +247,19 @@ else { SystemWindow sw = SystemWindow.FromPointEx(lastX, lastY, selToplevel.Checked, false); - if (sw != highlightedWindow) - { - if (highlightedWindow != null) - { - highlightedWindow.Refresh(); - highlightedWindow = null; - } - if (sw.HWnd != this.Handle && !sw.IsDescendantOf(new SystemWindow(this.Handle))) - { - sw.Highlight(); - highlightedWindow = sw; - } - } + if (sw != highlightedWindow) + { + if (highlightedWindow != null) + { + highlightedWindow.Refresh(); + highlightedWindow = null; + } + if (sw.HWnd != this.Handle && !sw.IsDescendantOf(new SystemWindow(this.Handle))) + { + sw.Highlight(); + highlightedWindow = sw; + } + } return new WindowData(this, sw); } } Modified: trunk/Tools/WinternalExplorer/TreeNodeData.cs =================================================================== --- trunk/Tools/WinternalExplorer/TreeNodeData.cs 2008-05-01 20:24:28 UTC (rev 69) +++ trunk/Tools/WinternalExplorer/TreeNodeData.cs 2008-06-14 18:29:56 UTC (rev 70) @@ -330,13 +330,15 @@ { List<TreeNodeData> result = new List<TreeNodeData>(); SystemWindow curr = sw; + SystemWindow last = curr; while (curr != null) { result.Add(new WindowData(mf, curr)); + last = curr; curr = curr.ParentSymmetric; } - result.Add(new ThreadData(mf, sw.Process, sw.Thread)); - result.Add(new ProcessData(mf, sw.Process)); + result.Add(new ThreadData(mf, last.Process, last.Thread)); + result.Add(new ProcessData(mf, last.Process)); return result; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sch...@us...> - 2008-05-01 20:24:35
|
Revision: 69 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=69&view=rev Author: schierlm Date: 2008-05-01 13:24:28 -0700 (Thu, 01 May 2008) Log Message: ----------- Fix a GDI object leak (which causes crashes as soon as 9999 GDI objects have been leaked) Modified Paths: -------------- trunk/ManagedWinapi/CodepointRange.cs Modified: trunk/ManagedWinapi/CodepointRange.cs =================================================================== --- trunk/ManagedWinapi/CodepointRange.cs 2008-04-28 18:41:39 UTC (rev 68) +++ trunk/ManagedWinapi/CodepointRange.cs 2008-05-01 20:24:28 UTC (rev 69) @@ -39,6 +39,7 @@ rangeList.Add(firstExcluded); } SelectObject(hdc, oldFont); + DeleteObject(hFont); Marshal.FreeHGlobal(glyphSet); g.ReleaseHdc(hdc); g.Dispose(); @@ -192,6 +193,9 @@ [DllImport("gdi32.dll")] private extern static IntPtr SelectObject(IntPtr hDC, IntPtr hObject); + + [DllImport("gdi32.dll")] + public static extern bool DeleteObject(IntPtr hObject); #endregion } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sch...@us...> - 2008-04-28 18:42:26
|
Revision: 68 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=68&view=rev Author: schierlm Date: 2008-04-28 11:41:39 -0700 (Mon, 28 Apr 2008) Log Message: ----------- CodepointRange.cs: Add helper method to get codepoint ranges of all fonts, while ignoring identical font styles within a font family. Modified Paths: -------------- trunk/ManagedWinapi/CodepointRange.cs Modified: trunk/ManagedWinapi/CodepointRange.cs =================================================================== --- trunk/ManagedWinapi/CodepointRange.cs 2008-04-27 17:52:10 UTC (rev 67) +++ trunk/ManagedWinapi/CodepointRange.cs 2008-04-28 18:41:39 UTC (rev 68) @@ -48,6 +48,57 @@ } /// <summary> + /// Returns a dictionary containing codepoint ranges of all fonts. + /// If multiple fonts of one family (bold, italic, etc.) share their + /// codepoint range, only their base font is included in this list, + /// otherwise all different variants are included. + /// </summary> + public static Dictionary<Font, CodepointRange> GetRangesForAllFonts() + { + Dictionary<Font, CodepointRange> result = new Dictionary<Font, CodepointRange>(); + foreach (FontFamily ff in FontFamily.Families) + { + Font[] fonts = new Font[16]; + CodepointRange[] range = new CodepointRange[fonts.Length]; + for (int i = 0; i < fonts.Length; i++) + { + if (ff.IsStyleAvailable((FontStyle)i)) + { + fonts[i] = new Font(ff, 10, (FontStyle)i); + range[i] = new CodepointRange(fonts[i]); + } + } + int importantBits = 0; + for (int bit = 1; bit < fonts.Length; bit <<= 1) + { + for (int i = 0; i < fonts.Length; i++) + { + if ((i & bit) != 0) continue; + if (range[i] != null && range[i | bit] != null) + { + if (!range[i].Equals(range[i | bit])) + { + importantBits |= bit; + break; + } + } + else if (range[i] != null || range[i | bit] != null) + { + importantBits |= bit; + break; + } + } + } + for (int i = 0; i < fonts.Length; i++) + { + if ((i & importantBits) != i || fonts[i] == null) continue; + result.Add(fonts[i], range[i]); + } + } + return result; + } + + /// <summary> /// The number of codepoints supported by this font. /// </summary> public int SupportedCodepointCount { get { return codepointCount; } } @@ -111,6 +162,30 @@ return sb.Append("]").ToString(); } + #region Equals and HashCode + public override bool Equals(object obj) + { + CodepointRange cr = obj as CodepointRange; + if (cr == null) + return false; + if (codepointCount != cr.codepointCount || ranges.Length != cr.ranges.Length) + return false; + for (int i = 0; i < ranges.Length; i++) + { + if (ranges[i] != cr.ranges[i]) + { + return false; + } + } + return true; + } + + public override int GetHashCode() + { + return 3 * codepointCount + 7 * ranges.Length + 9 * FirstCodepoint + 11 * LastCodepoint; + } + #endregion + #region PInvoke Declarations [DllImport("gdi32.dll")] private static extern uint GetFontUnicodeRanges(IntPtr hdc, IntPtr lpgs); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sch...@us...> - 2008-04-27 17:52:26
|
Revision: 67 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=67&view=rev Author: schierlm Date: 2008-04-27 10:52:10 -0700 (Sun, 27 Apr 2008) Log Message: ----------- CodepointRange.cs: Get codepoints supported by a font Modified Paths: -------------- trunk/ManagedWinapi/ManagedWinapi.csproj Added Paths: ----------- trunk/ManagedWinapi/CodepointRange.cs Added: trunk/ManagedWinapi/CodepointRange.cs =================================================================== --- trunk/ManagedWinapi/CodepointRange.cs (rev 0) +++ trunk/ManagedWinapi/CodepointRange.cs 2008-04-27 17:52:10 UTC (rev 67) @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; +using System.Runtime.InteropServices; + +namespace ManagedWinapi +{ + /// <summary> + /// The unicode range of codepoints supported by a font. + /// </summary> + public class CodepointRange + { + char[] ranges; + readonly int codepointCount; + + /// <summary> + /// Creates a new CodepointRange object for a font. + /// </summary> + public CodepointRange(Font font) + { + List<char> rangeList = new List<char>(); + Graphics g = Graphics.FromImage(new Bitmap(1, 1)); + IntPtr hdc = g.GetHdc(); + IntPtr hFont = font.ToHfont(); + IntPtr oldFont = SelectObject(hdc, hFont); + uint size = GetFontUnicodeRanges(hdc, IntPtr.Zero); + IntPtr glyphSet = Marshal.AllocHGlobal((int)size); + GetFontUnicodeRanges(hdc, glyphSet); + codepointCount = Marshal.ReadInt32(glyphSet, 8); + int tmp = 0; + int count = Marshal.ReadInt32(glyphSet, 12); + for (int i = 0; i < count; i++) + { + char firstIncluded = (char)Marshal.ReadInt16(glyphSet, 16 + i * 4); + char firstExcluded = (char)(firstIncluded + Marshal.ReadInt16(glyphSet, 18 + i * 4)); + tmp += firstExcluded - firstIncluded; + rangeList.Add(firstIncluded); + rangeList.Add(firstExcluded); + } + SelectObject(hdc, oldFont); + Marshal.FreeHGlobal(glyphSet); + g.ReleaseHdc(hdc); + g.Dispose(); + if (tmp != codepointCount) throw new Exception(font.FontFamily.Name); + ranges = rangeList.ToArray(); + if (ranges.Length < 2) throw new Exception(); + } + + /// <summary> + /// The number of codepoints supported by this font. + /// </summary> + public int SupportedCodepointCount { get { return codepointCount; } } + + /// <summary> + /// The first (lowest) supported codepoint. + /// </summary> + public char FirstCodepoint { get { return ranges[0]; } } + + /// <summary> + /// The last (highest) supported codepoint. + /// </summary> + public char LastCodepoint { get { return (char)(ranges[ranges.Length - 1] - 1); } } + + /// <summary> + /// Tests whether a specific codepoint is supported by this font. + /// </summary> + public bool IsSupported(char codepoint) + { + bool result = false; + foreach (char c in ranges) + { + if (c > codepoint) break; + result = !result; + } + return result; + } + + /// <summary> + /// Finds the next codepoint that is either supported or not. + /// </summary> + public char FindNext(char from, bool supported) + { + if (IsSupported(from) == supported) return from; + foreach (char c in ranges) + { + if (c > from) return c; + } + return (char)0xFFFF; + } + + /// <summary> + /// Returns a <see cref="String"/> representation of this codepoint range. + /// </summary> + public override string ToString() + { + StringBuilder sb = new StringBuilder("["); + for (int i = 0; i < ranges.Length; i++) + { + if (i % 2 == 1) + { + if (ranges[i] == ranges[i - 1] + 1) continue; + sb.Append("-"); + } + else if (i != 0) + { + sb.Append(", "); + } + sb.Append(((int)ranges[i] - i % 2).ToString("X4")); + } + return sb.Append("]").ToString(); + } + + #region PInvoke Declarations + [DllImport("gdi32.dll")] + private static extern uint GetFontUnicodeRanges(IntPtr hdc, IntPtr lpgs); + + [DllImport("gdi32.dll")] + private extern static IntPtr SelectObject(IntPtr hDC, IntPtr hObject); + #endregion + } +} Modified: trunk/ManagedWinapi/ManagedWinapi.csproj =================================================================== --- trunk/ManagedWinapi/ManagedWinapi.csproj 2008-04-06 18:49:24 UTC (rev 66) +++ trunk/ManagedWinapi/ManagedWinapi.csproj 2008-04-27 17:52:10 UTC (rev 67) @@ -46,6 +46,7 @@ </Compile> <Compile Include="Contents\AccessibleWindowParser.cs" /> <Compile Include="ExtendedFileInfo.cs" /> + <Compile Include="CodepointRange.cs" /> <Compile Include="Hook.cs"> <SubType>Component</SubType> </Compile> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sch...@us...> - 2008-04-06 18:49:27
|
Revision: 66 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=66&view=rev Author: schierlm Date: 2008-04-06 11:49:24 -0700 (Sun, 06 Apr 2008) Log Message: ----------- Cleanup: Reformat document with Visual Studio default settings Modified Paths: -------------- trunk/ManagedWinapi/SystemWindow.cs Modified: trunk/ManagedWinapi/SystemWindow.cs =================================================================== --- trunk/ManagedWinapi/SystemWindow.cs 2008-04-06 17:28:31 UTC (rev 65) +++ trunk/ManagedWinapi/SystemWindow.cs 2008-04-06 18:49:24 UTC (rev 66) @@ -29,1366 +29,1366 @@ namespace ManagedWinapi.Windows { - /// <summary> - /// Window Style Flags. The original constants started with WS_. - /// </summary> - /// <seealso cref="SystemWindow.Style"/> - [Flags] - public enum WindowStyleFlags - { - /// <summary> - /// WS_OVERLAPPED - /// </summary> - OVERLAPPED = 0x00000000, + /// <summary> + /// Window Style Flags. The original constants started with WS_. + /// </summary> + /// <seealso cref="SystemWindow.Style"/> + [Flags] + public enum WindowStyleFlags + { + /// <summary> + /// WS_OVERLAPPED + /// </summary> + OVERLAPPED = 0x00000000, - /// <summary> - /// WS_POPUP - /// </summary> - POPUP = unchecked((int)0x80000000), + /// <summary> + /// WS_POPUP + /// </summary> + POPUP = unchecked((int)0x80000000), - /// <summary> - /// WS_CHILD - /// </summary> - CHILD = 0x40000000, + /// <summary> + /// WS_CHILD + /// </summary> + CHILD = 0x40000000, - /// <summary> - /// WS_MINIMIZE - /// </summary> - MINIMIZE = 0x20000000, + /// <summary> + /// WS_MINIMIZE + /// </summary> + MINIMIZE = 0x20000000, - /// <summary> - /// WS_VISIBLE - /// </summary> - VISIBLE = 0x10000000, + /// <summary> + /// WS_VISIBLE + /// </summary> + VISIBLE = 0x10000000, - /// <summary> - /// WS_DISABLED - /// </summary> - DISABLED = 0x08000000, + /// <summary> + /// WS_DISABLED + /// </summary> + DISABLED = 0x08000000, - /// <summary> - /// WS_CLIPSIBLINGS - /// </summary> - CLIPSIBLINGS = 0x04000000, + /// <summary> + /// WS_CLIPSIBLINGS + /// </summary> + CLIPSIBLINGS = 0x04000000, - /// <summary> - /// WS_CLIPCHILDREN - /// </summary> - CLIPCHILDREN = 0x02000000, + /// <summary> + /// WS_CLIPCHILDREN + /// </summary> + CLIPCHILDREN = 0x02000000, - /// <summary> - /// WS_MAXIMIZE - /// </summary> - MAXIMIZE = 0x01000000, + /// <summary> + /// WS_MAXIMIZE + /// </summary> + MAXIMIZE = 0x01000000, - /// <summary> - /// WS_BORDER - /// </summary> - BORDER = 0x00800000, + /// <summary> + /// WS_BORDER + /// </summary> + BORDER = 0x00800000, - /// <summary> - /// WS_DLGFRAME - /// </summary> - DLGFRAME = 0x00400000, + /// <summary> + /// WS_DLGFRAME + /// </summary> + DLGFRAME = 0x00400000, - /// <summary> - /// WS_VSCROLL - /// </summary> - VSCROLL = 0x00200000, + /// <summary> + /// WS_VSCROLL + /// </summary> + VSCROLL = 0x00200000, - /// <summary> - /// WS_HSCROLL - /// </summary> - HSCROLL = 0x00100000, + /// <summary> + /// WS_HSCROLL + /// </summary> + HSCROLL = 0x00100000, - /// <summary> - /// WS_SYSMENU - /// </summary> - SYSMENU = 0x00080000, + /// <summary> + /// WS_SYSMENU + /// </summary> + SYSMENU = 0x00080000, - /// <summary> - /// WS_THICKFRAME - /// </summary> - THICKFRAME = 0x00040000, + /// <summary> + /// WS_THICKFRAME + /// </summary> + THICKFRAME = 0x00040000, - /// <summary> - /// WS_GROUP - /// </summary> - GROUP = 0x00020000, + /// <summary> + /// WS_GROUP + /// </summary> + GROUP = 0x00020000, - /// <summary> - /// WS_TABSTOP - /// </summary> - TABSTOP = 0x00010000, + /// <summary> + /// WS_TABSTOP + /// </summary> + TABSTOP = 0x00010000, - /// <summary> - /// WS_MINIMIZEBOX - /// </summary> - MINIMIZEBOX = 0x00020000, + /// <summary> + /// WS_MINIMIZEBOX + /// </summary> + MINIMIZEBOX = 0x00020000, - /// <summary> - /// WS_MAXIMIZEBOX - /// </summary> - MAXIMIZEBOX = 0x00010000, + /// <summary> + /// WS_MAXIMIZEBOX + /// </summary> + MAXIMIZEBOX = 0x00010000, - /// <summary> - /// WS_CAPTION - /// </summary> - CAPTION = BORDER | DLGFRAME, + /// <summary> + /// WS_CAPTION + /// </summary> + CAPTION = BORDER | DLGFRAME, - /// <summary> - /// WS_TILED - /// </summary> - TILED = OVERLAPPED, + /// <summary> + /// WS_TILED + /// </summary> + TILED = OVERLAPPED, - /// <summary> - /// WS_ICONIC - /// </summary> - ICONIC = MINIMIZE, + /// <summary> + /// WS_ICONIC + /// </summary> + ICONIC = MINIMIZE, - /// <summary> - /// WS_SIZEBOX - /// </summary> - SIZEBOX = THICKFRAME, + /// <summary> + /// WS_SIZEBOX + /// </summary> + SIZEBOX = THICKFRAME, - /// <summary> - /// WS_TILEDWINDOW - /// </summary> - TILEDWINDOW = OVERLAPPEDWINDOW, + /// <summary> + /// WS_TILEDWINDOW + /// </summary> + TILEDWINDOW = OVERLAPPEDWINDOW, - /// <summary> - /// WS_OVERLAPPEDWINDOW - /// </summary> - OVERLAPPEDWINDOW = OVERLAPPED | CAPTION | SYSMENU | THICKFRAME | MINIMIZEBOX | MAXIMIZEBOX, + /// <summary> + /// WS_OVERLAPPEDWINDOW + /// </summary> + OVERLAPPEDWINDOW = OVERLAPPED | CAPTION | SYSMENU | THICKFRAME | MINIMIZEBOX | MAXIMIZEBOX, - /// <summary> - /// WS_POPUPWINDOW - /// </summary> - POPUPWINDOW = POPUP | BORDER | SYSMENU, + /// <summary> + /// WS_POPUPWINDOW + /// </summary> + POPUPWINDOW = POPUP | BORDER | SYSMENU, - /// <summary> - /// WS_CHILDWINDOW - /// </summary> - CHILDWINDOW = CHILD, - } + /// <summary> + /// WS_CHILDWINDOW + /// </summary> + CHILDWINDOW = CHILD, + } - /// <summary> - /// Extended Window Style Flags. The original constants started with WS_EX_. - /// </summary> - /// <seealso cref="SystemWindow.ExtendedStyle"/> - [Flags] - public enum WindowExStyleFlags : uint - { - /// <summary> - /// Specifies that a window created with this style accepts drag-drop files. - /// </summary> - ACCEPTFILES = 0x00000010, - /// <summary> - /// Forces a top-level window onto the taskbar when the window is visible. - /// </summary> - APPWINDOW = 0x00040000, - /// <summary> - /// Specifies that a window has a border with a sunken edge. - /// </summary> - CLIENTEDGE = 0x00000200, - /// <summary> - /// Windows XP: Paints all descendants of a window in bottom-to-top painting order using double-buffering. For more information, see Remarks. This cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC. - /// </summary> - COMPOSITED = 0x02000000, - /// <summary> - /// Includes a question mark in the title bar of the window. When the user clicks the question mark, the cursor changes to a question mark with a pointer. If the user then clicks a child window, the child receives a WM_HELP message. The child window should pass the message to the parent window procedure, which should call the WinHelp function using the HELP_WM_HELP command. The Help application displays a pop-up window that typically contains help for the child window. - /// WS_EX_CONTEXTHELP cannot be used with the WS_MAXIMIZEBOX or WS_MINIMIZEBOX styles. - /// </summary> - CONTEXTHELP = 0x00000400, - /// <summary> - /// The window itself contains child windows that should take part in dialog box navigation. If this style is specified, the dialog manager recurses into children of this window when performing navigation operations such as handling the TAB key, an arrow key, or a keyboard mnemonic. - /// </summary> - CONTROLPARENT = 0x00010000, - /// <summary> - /// Creates a window that has a double border; the window can, optionally, be created with a title bar by specifying the WS_CAPTION style in the dwStyle parameter. - /// </summary> - DLGMODALFRAME = 0x00000001, - /// <summary> - /// Windows 2000/XP: Creates a layered window. Note that this cannot be used for child windows. Also, this cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC. - /// </summary> - LAYERED = 0x00080000, - /// <summary> - /// Arabic and Hebrew versions of Windows 98/Me, Windows 2000/XP: Creates a window whose horizontal origin is on the right edge. Increasing horizontal values advance to the left. - /// </summary> - LAYOUTRTL = 0x00400000, - /// <summary> - /// Creates a window that has generic left-aligned properties. This is the default. - /// </summary> - LEFT = 0x00000000, - /// <summary> - /// If the shell language is Hebrew, Arabic, or another language that supports reading order alignment, the vertical scroll bar (if present) is to the left of the client area. For other languages, the style is ignored. - /// </summary> - LEFTSCROLLBAR = 0x00004000, - /// <summary> - /// The window text is displayed using left-to-right reading-order properties. This is the default. - /// </summary> - LTRREADING = 0x00000000, - /// <summary> - /// Creates a multiple-document interface (MDI) child window. - /// </summary> - MDICHILD = 0x00000040, - /// <summary> - /// Windows 2000/XP: A top-level window created with this style does not become the foreground window when the user clicks it. The system does not bring this window to the foreground when the user minimizes or closes the foreground window. - /// To activate the window, use the SetActiveWindow or SetForegroundWindow function. - /// The window does not appear on the taskbar by default. To force the window to appear on the taskbar, use the WS_EX_APPWINDOW style. - /// </summary> - NOACTIVATE = 0x08000000, - /// <summary> - /// Windows 2000/XP: A window created with this style does not pass its window layout to its child windows. - /// </summary> - NOINHERITLAYOUT = 0x00100000, - /// <summary> - /// Specifies that a child window created with this style does not send the WM_PARENTNOTIFY message to its parent window when it is created or destroyed. - /// </summary> - NOPARENTNOTIFY = 0x00000004, - /// <summary> - /// Combines the WS_EX_CLIENTEDGE and WS_EX_WINDOWEDGE styles. - /// </summary> - OVERLAPPEDWINDOW = WINDOWEDGE | CLIENTEDGE, - /// <summary> - /// Combines the WS_EX_WINDOWEDGE, WS_EX_TOOLWINDOW, and WS_EX_TOPMOST styles. - /// </summary> - PALETTEWINDOW = WINDOWEDGE | TOOLWINDOW | TOPMOST, - /// <summary> - /// The window has generic "right-aligned" properties. This depends on the window class. This style has an effect only if the shell language is Hebrew, Arabic, or another language that supports reading-order alignment; otherwise, the style is ignored. - /// Using the WS_EX_RIGHT style for static or edit controls has the same effect as using the SS_RIGHT or ES_RIGHT style, respectively. Using this style with button controls has the same effect as using BS_RIGHT and BS_RIGHTBUTTON styles. - /// </summary> - RIGHT = 0x00001000, - /// <summary> - /// Vertical scroll bar (if present) is to the right of the client area. This is the default. - /// </summary> - RIGHTSCROLLBAR = 0x00000000, - /// <summary> - /// If the shell language is Hebrew, Arabic, or another language that supports reading-order alignment, the window text is displayed using right-to-left reading-order properties. For other languages, the style is ignored. - /// </summary> - RTLREADING = 0x00002000, - /// <summary> - /// Creates a window with a three-dimensional border style intended to be used for items that do not accept user input. - /// </summary> - STATICEDGE = 0x00020000, - /// <summary> - /// Creates a tool window; that is, a window intended to be used as a floating toolbar. A tool window has a title bar that is shorter than a normal title bar, and the window title is drawn using a smaller font. A tool window does not appear in the taskbar or in the dialog that appears when the user presses ALT+TAB. If a tool window has a system menu, its icon is not displayed on the title bar. However, you can display the system menu by right-clicking or by typing ALT+SPACE. - /// </summary> - TOOLWINDOW = 0x00000080, - /// <summary> - /// Specifies that a window created with this style should be placed above all non-topmost windows and should stay above them, even when the window is deactivated. To add or remove this style, use the SetWindowPos function. - /// </summary> - TOPMOST = 0x00000008, - /// <summary> - /// Specifies that a window created with this style should not be painted until siblings beneath the window (that were created by the same thread) have been painted. The window appears transparent because the bits of underlying sibling windows have already been painted. - /// To achieve transparency without these restrictions, use the SetWindowRgn function. - /// </summary> - TRANSPARENT = 0x00000020, - /// <summary> - /// Specifies that a window has a border with a raised edge. - /// </summary> - WINDOWEDGE = 0x00000100 - } + /// <summary> + /// Extended Window Style Flags. The original constants started with WS_EX_. + /// </summary> + /// <seealso cref="SystemWindow.ExtendedStyle"/> + [Flags] + public enum WindowExStyleFlags : uint + { + /// <summary> + /// Specifies that a window created with this style accepts drag-drop files. + /// </summary> + ACCEPTFILES = 0x00000010, + /// <summary> + /// Forces a top-level window onto the taskbar when the window is visible. + /// </summary> + APPWINDOW = 0x00040000, + /// <summary> + /// Specifies that a window has a border with a sunken edge. + /// </summary> + CLIENTEDGE = 0x00000200, + /// <summary> + /// Windows XP: Paints all descendants of a window in bottom-to-top painting order using double-buffering. For more information, see Remarks. This cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC. + /// </summary> + COMPOSITED = 0x02000000, + /// <summary> + /// Includes a question mark in the title bar of the window. When the user clicks the question mark, the cursor changes to a question mark with a pointer. If the user then clicks a child window, the child receives a WM_HELP message. The child window should pass the message to the parent window procedure, which should call the WinHelp function using the HELP_WM_HELP command. The Help application displays a pop-up window that typically contains help for the child window. + /// WS_EX_CONTEXTHELP cannot be used with the WS_MAXIMIZEBOX or WS_MINIMIZEBOX styles. + /// </summary> + CONTEXTHELP = 0x00000400, + /// <summary> + /// The window itself contains child windows that should take part in dialog box navigation. If this style is specified, the dialog manager recurses into children of this window when performing navigation operations such as handling the TAB key, an arrow key, or a keyboard mnemonic. + /// </summary> + CONTROLPARENT = 0x00010000, + /// <summary> + /// Creates a window that has a double border; the window can, optionally, be created with a title bar by specifying the WS_CAPTION style in the dwStyle parameter. + /// </summary> + DLGMODALFRAME = 0x00000001, + /// <summary> + /// Windows 2000/XP: Creates a layered window. Note that this cannot be used for child windows. Also, this cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC. + /// </summary> + LAYERED = 0x00080000, + /// <summary> + /// Arabic and Hebrew versions of Windows 98/Me, Windows 2000/XP: Creates a window whose horizontal origin is on the right edge. Increasing horizontal values advance to the left. + /// </summary> + LAYOUTRTL = 0x00400000, + /// <summary> + /// Creates a window that has generic left-aligned properties. This is the default. + /// </summary> + LEFT = 0x00000000, + /// <summary> + /// If the shell language is Hebrew, Arabic, or another language that supports reading order alignment, the vertical scroll bar (if present) is to the left of the client area. For other languages, the style is ignored. + /// </summary> + LEFTSCROLLBAR = 0x00004000, + /// <summary> + /// The window text is displayed using left-to-right reading-order properties. This is the default. + /// </summary> + LTRREADING = 0x00000000, + /// <summary> + /// Creates a multiple-document interface (MDI) child window. + /// </summary> + MDICHILD = 0x00000040, + /// <summary> + /// Windows 2000/XP: A top-level window created with this style does not become the foreground window when the user clicks it. The system does not bring this window to the foreground when the user minimizes or closes the foreground window. + /// To activate the window, use the SetActiveWindow or SetForegroundWindow function. + /// The window does not appear on the taskbar by default. To force the window to appear on the taskbar, use the WS_EX_APPWINDOW style. + /// </summary> + NOACTIVATE = 0x08000000, + /// <summary> + /// Windows 2000/XP: A window created with this style does not pass its window layout to its child windows. + /// </summary> + NOINHERITLAYOUT = 0x00100000, + /// <summary> + /// Specifies that a child window created with this style does not send the WM_PARENTNOTIFY message to its parent window when it is created or destroyed. + /// </summary> + NOPARENTNOTIFY = 0x00000004, + /// <summary> + /// Combines the WS_EX_CLIENTEDGE and WS_EX_WINDOWEDGE styles. + /// </summary> + OVERLAPPEDWINDOW = WINDOWEDGE | CLIENTEDGE, + /// <summary> + /// Combines the WS_EX_WINDOWEDGE, WS_EX_TOOLWINDOW, and WS_EX_TOPMOST styles. + /// </summary> + PALETTEWINDOW = WINDOWEDGE | TOOLWINDOW | TOPMOST, + /// <summary> + /// The window has generic "right-aligned" properties. This depends on the window class. This style has an effect only if the shell language is Hebrew, Arabic, or another language that supports reading-order alignment; otherwise, the style is ignored. + /// Using the WS_EX_RIGHT style for static or edit controls has the same effect as using the SS_RIGHT or ES_RIGHT style, respectively. Using this style with button controls has the same effect as using BS_RIGHT and BS_RIGHTBUTTON styles. + /// </summary> + RIGHT = 0x00001000, + /// <summary> + /// Vertical scroll bar (if present) is to the right of the client area. This is the default. + /// </summary> + RIGHTSCROLLBAR = 0x00000000, + /// <summary> + /// If the shell language is Hebrew, Arabic, or another language that supports reading-order alignment, the window text is displayed using right-to-left reading-order properties. For other languages, the style is ignored. + /// </summary> + RTLREADING = 0x00002000, + /// <summary> + /// Creates a window with a three-dimensional border style intended to be used for items that do not accept user input. + /// </summary> + STATICEDGE = 0x00020000, + /// <summary> + /// Creates a tool window; that is, a window intended to be used as a floating toolbar. A tool window has a title bar that is shorter than a normal title bar, and the window title is drawn using a smaller font. A tool window does not appear in the taskbar or in the dialog that appears when the user presses ALT+TAB. If a tool window has a system menu, its icon is not displayed on the title bar. However, you can display the system menu by right-clicking or by typing ALT+SPACE. + /// </summary> + TOOLWINDOW = 0x00000080, + /// <summary> + /// Specifies that a window created with this style should be placed above all non-topmost windows and should stay above them, even when the window is deactivated. To add or remove this style, use the SetWindowPos function. + /// </summary> + TOPMOST = 0x00000008, + /// <summary> + /// Specifies that a window created with this style should not be painted until siblings beneath the window (that were created by the same thread) have been painted. The window appears transparent because the bits of underlying sibling windows have already been painted. + /// To achieve transparency without these restrictions, use the SetWindowRgn function. + /// </summary> + TRANSPARENT = 0x00000020, + /// <summary> + /// Specifies that a window has a border with a raised edge. + /// </summary> + WINDOWEDGE = 0x00000100 + } - /// <summary> - /// Represents any window used by Windows, including those from other applications. - /// </summary> - public class SystemWindow - { + /// <summary> + /// Represents any window used by Windows, including those from other applications. + /// </summary> + public class SystemWindow + { - private static readonly Predicate<SystemWindow> ALL = delegate { return true; }; + private static readonly Predicate<SystemWindow> ALL = delegate { return true; }; - private IntPtr _hwnd; + private IntPtr _hwnd; - /// <summary> - /// Allows getting the current foreground window and setting it. - /// </summary> - public static SystemWindow ForegroundWindow - { - get - { - return new SystemWindow(GetForegroundWindow()); - } - set - { - SetForegroundWindow(value.HWnd); - } - } + /// <summary> + /// Allows getting the current foreground window and setting it. + /// </summary> + public static SystemWindow ForegroundWindow + { + get + { + return new SystemWindow(GetForegroundWindow()); + } + set + { + SetForegroundWindow(value.HWnd); + } + } - /// <summary> - /// The Desktop window, i. e. the window that covers the - /// complete desktop. - /// </summary> - public static SystemWindow DesktopWindow - { - get - { - return new SystemWindow(GetDesktopWindow()); - } - } + /// <summary> + /// The Desktop window, i. e. the window that covers the + /// complete desktop. + /// </summary> + public static SystemWindow DesktopWindow + { + get + { + return new SystemWindow(GetDesktopWindow()); + } + } - /// <summary> - /// Returns all available toplevel windows. - /// </summary> - public static SystemWindow[] AllToplevelWindows - { - get - { - return FilterToplevelWindows(new Predicate<SystemWindow>(ALL)); - } - } + /// <summary> + /// Returns all available toplevel windows. + /// </summary> + public static SystemWindow[] AllToplevelWindows + { + get + { + return FilterToplevelWindows(new Predicate<SystemWindow>(ALL)); + } + } - /// <summary> - /// Returns all toplevel windows that match the given predicate. - /// </summary> - /// <param name="predicate">The predicate to filter.</param> - /// <returns>The filtered toplevel windows</returns> - public static SystemWindow[] FilterToplevelWindows(Predicate<SystemWindow> predicate) - { - List<SystemWindow> wnds = new List<SystemWindow>(); - EnumWindows(new EnumWindowsProc(delegate(IntPtr hwnd, IntPtr lParam) - { - SystemWindow tmp = new SystemWindow(hwnd); - if (predicate(tmp)) - wnds.Add(tmp); - return 1; - }), new IntPtr(0)); - return wnds.ToArray(); - } + /// <summary> + /// Returns all toplevel windows that match the given predicate. + /// </summary> + /// <param name="predicate">The predicate to filter.</param> + /// <returns>The filtered toplevel windows</returns> + public static SystemWindow[] FilterToplevelWindows(Predicate<SystemWindow> predicate) + { + List<SystemWindow> wnds = new List<SystemWindow>(); + EnumWindows(new EnumWindowsProc(delegate(IntPtr hwnd, IntPtr lParam) + { + SystemWindow tmp = new SystemWindow(hwnd); + if (predicate(tmp)) + wnds.Add(tmp); + return 1; + }), new IntPtr(0)); + return wnds.ToArray(); + } - /// <summary> - /// Finds the system window below the given point. This need not be a - /// toplevel window; disabled windows are not returned either. - /// If you have problems with transparent windows that cover nontransparent - /// windows, consider using <see cref="FromPointEx"/>, since that method - /// tries hard to avoid this problem. - /// </summary> - /// <param name="x">X coordinate</param> - /// <param name="y">Y coordinate</param> - /// <returns></returns> - public static SystemWindow FromPoint(int x, int y) - { - IntPtr hwnd = WindowFromPoint(new POINT(x, y)); - if (hwnd.ToInt64() == 0) - { - return null; - } - return new SystemWindow(hwnd); - } + /// <summary> + /// Finds the system window below the given point. This need not be a + /// toplevel window; disabled windows are not returned either. + /// If you have problems with transparent windows that cover nontransparent + /// windows, consider using <see cref="FromPointEx"/>, since that method + /// tries hard to avoid this problem. + /// </summary> + /// <param name="x">X coordinate</param> + /// <param name="y">Y coordinate</param> + /// <returns></returns> + public static SystemWindow FromPoint(int x, int y) + { + IntPtr hwnd = WindowFromPoint(new POINT(x, y)); + if (hwnd.ToInt64() == 0) + { + return null; + } + return new SystemWindow(hwnd); + } - /// <summary> - /// Finds the system window below the given point. This method uses a more - /// sophisticated algorithm than <see cref="FromPoint"/>, but is slower. - /// </summary> - /// <param name="x">X coordinate</param> - /// <param name="y">Y coordinate</param> - /// <param name="toplevel">Whether to return the toplevel window.</param> - /// <param name="enabledOnly">Whether to return enabled windows only.</param> - /// <returns></returns> - public static SystemWindow FromPointEx(int x, int y, bool toplevel, bool enabledOnly) - { - SystemWindow sw = FromPoint(x, y); - if (sw == null) return null; - while (sw.ParentSymmetric != null) - sw = sw.ParentSymmetric; - if (toplevel) - return sw; - int area; - area = getArea(sw); - SystemWindow result = sw; - foreach (SystemWindow w in sw.AllDescendantWindows) - { - if (w.Visible && (w.Enabled || !enabledOnly)) - { - if (w.Rectangle.ToRectangle().Contains(x, y)) - { - int ar2 = getArea(w); - if (ar2 <= area) - { - area = ar2; - result = w; - } - } - } - } - return result; - } + /// <summary> + /// Finds the system window below the given point. This method uses a more + /// sophisticated algorithm than <see cref="FromPoint"/>, but is slower. + /// </summary> + /// <param name="x">X coordinate</param> + /// <param name="y">Y coordinate</param> + /// <param name="toplevel">Whether to return the toplevel window.</param> + /// <param name="enabledOnly">Whether to return enabled windows only.</param> + /// <returns></returns> + public static SystemWindow FromPointEx(int x, int y, bool toplevel, bool enabledOnly) + { + SystemWindow sw = FromPoint(x, y); + if (sw == null) return null; + while (sw.ParentSymmetric != null) + sw = sw.ParentSymmetric; + if (toplevel) + return sw; + int area; + area = getArea(sw); + SystemWindow result = sw; + foreach (SystemWindow w in sw.AllDescendantWindows) + { + if (w.Visible && (w.Enabled || !enabledOnly)) + { + if (w.Rectangle.ToRectangle().Contains(x, y)) + { + int ar2 = getArea(w); + if (ar2 <= area) + { + area = ar2; + result = w; + } + } + } + } + return result; + } - private static int getArea(SystemWindow sw) - { - RECT rr = sw.Rectangle; - return rr.Height * rr.Width; - } + private static int getArea(SystemWindow sw) + { + RECT rr = sw.Rectangle; + return rr.Height * rr.Width; + } - /// <summary> - /// Create a new SystemWindow instance from a window handle. - /// </summary> - /// <param name="HWnd">The window handle.</param> - public SystemWindow(IntPtr HWnd) - { - _hwnd = HWnd; - } + /// <summary> + /// Create a new SystemWindow instance from a window handle. + /// </summary> + /// <param name="HWnd">The window handle.</param> + public SystemWindow(IntPtr HWnd) + { + _hwnd = HWnd; + } - /// <summary> - /// Create a new SystemWindow instance from a Windows Forms Control. - /// </summary> - /// <param name="control">The control.</param> - public SystemWindow(Control control) - { - _hwnd = control.Handle; - } + /// <summary> + /// Create a new SystemWindow instance from a Windows Forms Control. + /// </summary> + /// <param name="control">The control.</param> + public SystemWindow(Control control) + { + _hwnd = control.Handle; + } - /// <summary> - /// Return all descendant windows (child windows and their descendants). - /// </summary> - public SystemWindow[] AllDescendantWindows - { - get - { - return FilterDescendantWindows(false, ALL); - } - } + /// <summary> + /// Return all descendant windows (child windows and their descendants). + /// </summary> + public SystemWindow[] AllDescendantWindows + { + get + { + return FilterDescendantWindows(false, ALL); + } + } - /// <summary> - /// Return all direct child windows. - /// </summary> - public SystemWindow[] AllChildWindows - { - get - { - return FilterDescendantWindows(true, ALL); - } - } + /// <summary> + /// Return all direct child windows. + /// </summary> + public SystemWindow[] AllChildWindows + { + get + { + return FilterDescendantWindows(true, ALL); + } + } - /// <summary> - /// Returns all child windows that match the given predicate. - /// </summary> - /// <param name="directOnly">Whether to include only direct children (no descendants)</param> - /// <param name="predicate">The predicate to filter.</param> - /// <returns>The list of child windows.</returns> - public SystemWindow[] FilterDescendantWindows(bool directOnly, Predicate<SystemWindow> predicate) - { - List<SystemWindow> wnds = new List<SystemWindow>(); - EnumChildWindows(_hwnd, delegate(IntPtr hwnd, IntPtr lParam) - { - SystemWindow tmp = new SystemWindow(hwnd); - bool add = true; - if (directOnly) - { - add = tmp.Parent._hwnd == _hwnd; - } - if (add && predicate(tmp)) - wnds.Add(tmp); - return 1; - }, new IntPtr(0)); - return wnds.ToArray(); - } + /// <summary> + /// Returns all child windows that match the given predicate. + /// </summary> + /// <param name="directOnly">Whether to include only direct children (no descendants)</param> + /// <param name="predicate">The predicate to filter.</param> + /// <returns>The list of child windows.</returns> + public SystemWindow[] FilterDescendantWindows(bool directOnly, Predicate<SystemWindow> predicate) + { + List<SystemWindow> wnds = new List<SystemWindow>(); + EnumChildWindows(_hwnd, delegate(IntPtr hwnd, IntPtr lParam) + { + SystemWindow tmp = new SystemWindow(hwnd); + bool add = true; + if (directOnly) + { + add = tmp.Parent._hwnd == _hwnd; + } + if (add && predicate(tmp)) + wnds.Add(tmp); + return 1; + }, new IntPtr(0)); + return wnds.ToArray(); + } - /// <summary> - /// The Window handle of this window. - /// </summary> - public IntPtr HWnd { get { return _hwnd; } } + /// <summary> + /// The Window handle of this window. + /// </summary> + public IntPtr HWnd { get { return _hwnd; } } - /// <summary> - /// The title of this window (by the <c>GetWindowText</c> API function). - /// </summary> - public string Title - { - get - { - StringBuilder sb = new StringBuilder(GetWindowTextLength(_hwnd) + 1); - GetWindowText(_hwnd, sb, sb.Capacity); - return sb.ToString(); - } + /// <summary> + /// The title of this window (by the <c>GetWindowText</c> API function). + /// </summary> + public string Title + { + get + { + StringBuilder sb = new StringBuilder(GetWindowTextLength(_hwnd) + 1); + GetWindowText(_hwnd, sb, sb.Capacity); + return sb.ToString(); + } - set - { - SetWindowText(_hwnd, value); - } - } + set + { + SetWindowText(_hwnd, value); + } + } - /// <summary> - /// The name of the window class (by the <c>GetClassName</c> API function). - /// This class has nothing to do with classes in C# or other .NET languages. - /// </summary> - public string ClassName - { - get - { - int length = 64; - while (true) - { - StringBuilder sb = new StringBuilder(length); - ApiHelper.FailIfZero(GetClassName(_hwnd, sb, sb.Capacity)); - if (sb.Length != length - 1) - { - return sb.ToString(); - } - length *= 2; - } - } - } + /// <summary> + /// The name of the window class (by the <c>GetClassName</c> API function). + /// This class has nothing to do with classes in C# or other .NET languages. + /// </summary> + public string ClassName + { + get + { + int length = 64; + while (true) + { + StringBuilder sb = new StringBuilder(length); + ApiHelper.FailIfZero(GetClassName(_hwnd, sb, sb.Capacity)); + if (sb.Length != length - 1) + { + return sb.ToString(); + } + length *= 2; + } + } + } - /// <summary> - /// Whether this window is currently visible. A window is visible if its - /// and all ancestor's visibility flags are true. - /// </summary> - public bool Visible - { - get - { - return IsWindowVisible(_hwnd); - } - } + /// <summary> + /// Whether this window is currently visible. A window is visible if its + /// and all ancestor's visibility flags are true. + /// </summary> + public bool Visible + { + get + { + return IsWindowVisible(_hwnd); + } + } - /// <summary> - /// Whether this window always appears above all other windows - /// that do not have this property set to true. - /// </summary> - public bool TopMost - { - get - { - return (ExtendedStyle & WindowExStyleFlags.TOPMOST) != 0; - } - set - { - if (value) - { - SetWindowPos(_hwnd, new IntPtr(-1), 0, 0, 0, 0, 3); - } - else - { - SetWindowPos(_hwnd, new IntPtr(-2), 0, 0, 0, 0, 3); - } - } - } + /// <summary> + /// Whether this window always appears above all other windows + /// that do not have this property set to true. + /// </summary> + public bool TopMost + { + get + { + return (ExtendedStyle & WindowExStyleFlags.TOPMOST) != 0; + } + set + { + if (value) + { + SetWindowPos(_hwnd, new IntPtr(-1), 0, 0, 0, 0, 3); + } + else + { + SetWindowPos(_hwnd, new IntPtr(-2), 0, 0, 0, 0, 3); + } + } + } - /// <summary> - /// Whether this window is currently enabled (able to accept keyboard input). - /// </summary> - public bool Enabled - { - get - { - return IsWindowEnabled(_hwnd); - } - set - { - EnableWindow(_hwnd, value); - } - } + /// <summary> + /// Whether this window is currently enabled (able to accept keyboard input). + /// </summary> + public bool Enabled + { + get + { + return IsWindowEnabled(_hwnd); + } + set + { + EnableWindow(_hwnd, value); + } + } - /// <summary> - /// Returns or sets the visibility flag. - /// </summary> - /// <seealso cref="SystemWindow.Visible"/> - public bool VisibilityFlag - { - get - { - return (Style & WindowStyleFlags.VISIBLE) != 0; - } - set - { - if (value) - { - ShowWindow(_hwnd, 5); - } - else - { - ShowWindow(_hwnd, 0); - } - } - } + /// <summary> + /// Returns or sets the visibility flag. + /// </summary> + /// <seealso cref="SystemWindow.Visible"/> + public bool VisibilityFlag + { + get + { + return (Style & WindowStyleFlags.VISIBLE) != 0; + } + set + { + if (value) + { + ShowWindow(_hwnd, 5); + } + else + { + ShowWindow(_hwnd, 0); + } + } + } - /// <summary> - /// This window's style flags. - /// </summary> - public WindowStyleFlags Style - { - get - { - return (WindowStyleFlags)GetWindowLongPtr(_hwnd, (int)(GWL.GWL_STYLE)); - } - set - { - SetWindowLong(_hwnd, (int)GWL.GWL_STYLE, (int)value); - } + /// <summary> + /// This window's style flags. + /// </summary> + public WindowStyleFlags Style + { + get + { + return (WindowStyleFlags)GetWindowLongPtr(_hwnd, (int)(GWL.GWL_STYLE)); + } + set + { + SetWindowLong(_hwnd, (int)GWL.GWL_STYLE, (int)value); + } - } + } - /// <summary> - /// This window's extended style flags. - /// </summary> - public WindowExStyleFlags ExtendedStyle - { - get - { - return (WindowExStyleFlags)GetWindowLongPtr(_hwnd, (int)(GWL.GWL_EXSTYLE)); - } - set - { - SetWindowLong(_hwnd, (int)GWL.GWL_EXSTYLE, (int)value); - } - } + /// <summary> + /// This window's extended style flags. + /// </summary> + public WindowExStyleFlags ExtendedStyle + { + get + { + return (WindowExStyleFlags)GetWindowLongPtr(_hwnd, (int)(GWL.GWL_EXSTYLE)); + } + set + { + SetWindowLong(_hwnd, (int)GWL.GWL_EXSTYLE, (int)value); + } + } - /// <summary> - /// This window's parent. A dialog's parent is its owner, a component's parent is - /// the window that contains it. - /// </summary> - public SystemWindow Parent - { - get - { - return new SystemWindow(GetParent(_hwnd)); - } - } + /// <summary> + /// This window's parent. A dialog's parent is its owner, a component's parent is + /// the window that contains it. + /// </summary> + public SystemWindow Parent + { + get + { + return new SystemWindow(GetParent(_hwnd)); + } + } - /// <summary> - /// The window's parent, but only if this window is its parent child. Some - /// parents, like dialog owners, do not have the window as its child. In that case, - /// <c>null</c> will be returned. - /// </summary> - public SystemWindow ParentSymmetric - { - get - { - SystemWindow result = Parent; - if (!this.IsDescendantOf(result)) result = null; - return result; - } - } + /// <summary> + /// The window's parent, but only if this window is its parent child. Some + /// parents, like dialog owners, do not have the window as its child. In that case, + /// <c>null</c> will be returned. + /// </summary> + public SystemWindow ParentSymmetric + { + get + { + SystemWindow result = Parent; + if (!this.IsDescendantOf(result)) result = null; + return result; + } + } - /// <summary> - /// The window's position inside its parent or on the screen. - /// </summary> - public RECT Position - { - get - { - WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); - wp.length = Marshal.SizeOf(wp); - GetWindowPlacement(_hwnd, ref wp); - return wp.rcNormalPosition; - } + /// <summary> + /// The window's position inside its parent or on the screen. + /// </summary> + public RECT Position + { + get + { + WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); + wp.length = Marshal.SizeOf(wp); + GetWindowPlacement(_hwnd, ref wp); + return wp.rcNormalPosition; + } - set - { - WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); - wp.length = Marshal.SizeOf(wp); - GetWindowPlacement(_hwnd, ref wp); - wp.rcNormalPosition = value; - SetWindowPlacement(_hwnd, ref wp); - } - } + set + { + WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); + wp.length = Marshal.SizeOf(wp); + GetWindowPlacement(_hwnd, ref wp); + wp.rcNormalPosition = value; + SetWindowPlacement(_hwnd, ref wp); + } + } - /// <summary> - /// The window's location inside its parent or on the screen. - /// </summary> - public Point Location - { - get - { - return Position.Location; - } + /// <summary> + /// The window's location inside its parent or on the screen. + /// </summary> + public Point Location + { + get + { + return Position.Location; + } - set - { - WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); - wp.length = Marshal.SizeOf(wp); - GetWindowPlacement(_hwnd, ref wp); - wp.rcNormalPosition.Bottom = value.Y + wp.rcNormalPosition.Height; - wp.rcNormalPosition.Right = value.X + wp.rcNormalPosition.Width; - wp.rcNormalPosition.Top = value.Y; - wp.rcNormalPosition.Left = value.X; - SetWindowPlacement(_hwnd, ref wp); - } - } + set + { + WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); + wp.length = Marshal.SizeOf(wp); + GetWindowPlacement(_hwnd, ref wp); + wp.rcNormalPosition.Bottom = value.Y + wp.rcNormalPosition.Height; + wp.rcNormalPosition.Right = value.X + wp.rcNormalPosition.Width; + wp.rcNormalPosition.Top = value.Y; + wp.rcNormalPosition.Left = value.X; + SetWindowPlacement(_hwnd, ref wp); + } + } - /// <summary> - /// The window's size. - /// </summary> - public Size Size - { - get - { - return Position.Size; - } + /// <summary> + /// The window's size. + /// </summary> + public Size Size + { + get + { + return Position.Size; + } - set - { - WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); - wp.length = Marshal.SizeOf(wp); - GetWindowPlacement(_hwnd, ref wp); - wp.rcNormalPosition.Right = wp.rcNormalPosition.Left + value.Width; - wp.rcNormalPosition.Bottom = wp.rcNormalPosition.Top + value.Height; - SetWindowPlacement(_hwnd, ref wp); - } - } + set + { + WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); + wp.length = Marshal.SizeOf(wp); + GetWindowPlacement(_hwnd, ref wp); + wp.rcNormalPosition.Right = wp.rcNormalPosition.Left + value.Width; + wp.rcNormalPosition.Bottom = wp.rcNormalPosition.Top + value.Height; + SetWindowPlacement(_hwnd, ref wp); + } + } - /// <summary> - /// The window's position in absolute screen coordinates. Use - /// <see cref="Position"/> if you want to use the relative position. - /// </summary> - public RECT Rectangle - { - get - { - RECT r = new RECT(); - GetWindowRect(_hwnd, out r); - return r; - } - } + /// <summary> + /// The window's position in absolute screen coordinates. Use + /// <see cref="Position"/> if you want to use the relative position. + /// </summary> + public RECT Rectangle + { + get + { + RECT r = new RECT(); + GetWindowRect(_hwnd, out r); + return r; + } + } - /// <summary> - /// Check whether this window is a descendant of <c>ancestor</c> - /// </summary> - /// <param name="ancestor">The suspected ancestor</param> - /// <returns>If this is really an ancestor</returns> - public bool IsDescendantOf(SystemWindow ancestor) - { - return IsChild(ancestor._hwnd, _hwnd); - } + /// <summary> + /// Check whether this window is a descendant of <c>ancestor</c> + /// </summary> + /// <param name="ancestor">The suspected ancestor</param> + /// <returns>If this is really an ancestor</returns> + public bool IsDescendantOf(SystemWindow ancestor) + { + return IsChild(ancestor._hwnd, _hwnd); + } - /// <summary> - /// The process which created this window. - /// </summary> - public Process Process - { - get - { - int pid; - GetWindowThreadProcessId(HWnd, out pid); - return Process.GetProcessById(pid); - } - } + /// <summary> + /// The process which created this window. + /// </summary> + public Process Process + { + get + { + int pid; + GetWindowThreadProcessId(HWnd, out pid); + return Process.GetProcessById(pid); + } + } - /// <summary> - /// The Thread which created this window. - /// </summary> - public ProcessThread Thread - { - get - { - int pid; - int tid = GetWindowThreadProcessId(HWnd, out pid); - foreach (ProcessThread t in Process.GetProcessById(pid).Threads) - { - if (t.Id == tid) return t; - } - throw new Exception("Thread not found"); - } - } + /// <summary> + /// The Thread which created this window. + /// </summary> + public ProcessThread Thread + { + get + { + int pid; + int tid = GetWindowThreadProcessId(HWnd, out pid); + foreach (ProcessThread t in Process.GetProcessById(pid).Threads) + { + if (t.Id == tid) return t; + } + throw new Exception("Thread not found"); + } + } - /// <summary> - /// Whether this window is minimized or maximized. - /// </summary> - public FormWindowState WindowState - { - get - { - WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); - wp.length = Marshal.SizeOf(wp); - GetWindowPlacement(HWnd, ref wp); - switch (wp.showCmd % 4) - { - case 2: return FormWindowState.Minimized; - case 3: return FormWindowState.Maximized; - default: return FormWindowState.Normal; - } - } - set - { - int showCommand; - switch (value) - { - case FormWindowState.Normal: - showCommand = 1; - break; - case FormWindowState.Minimized: - showCommand = 2; - break; - case FormWindowState.Maximized: - showCommand = 3; - break; - default: return; - } - ShowWindow(HWnd, showCommand); - } - } + /// <summary> + /// Whether this window is minimized or maximized. + /// </summary> + public FormWindowState WindowState + { + get + { + WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); + wp.length = Marshal.SizeOf(wp); + GetWindowPlacement(HWnd, ref wp); + switch (wp.showCmd % 4) + { + case 2: return FormWindowState.Minimized; + case 3: return FormWindowState.Maximized; + default: return FormWindowState.Normal; + } + } + set + { + int showCommand; + switch (value) + { + case FormWindowState.Normal: + showCommand = 1; + break; + case FormWindowState.Minimized: + showCommand = 2; + break; + case FormWindowState.Maximized: + showCommand = 3; + break; + default: return; + } + ShowWindow(HWnd, showCommand); + } + } - /// <summary> - /// Whether this window can be moved on the screen by the user. - /// </summary> - public bool Movable - { - get - { - return (Style & WindowStyleFlags.SYSMENU) != 0; - } - } + /// <summary> + /// Whether this window can be moved on the screen by the user. + /// </summary> + public bool Movable + { + get + { + return (Style & WindowStyleFlags.SYSMENU) != 0; + } + } - /// <summary> - /// Whether this window can be resized by the user. Resizing a window that - /// cannot be resized by the user works, but may be irritating to the user. - /// </summary> - public bool Resizable - { - get - { - return (Style & WindowStyleFlags.THICKFRAME) != 0; - } - } + /// <summary> + /// Whether this window can be resized by the user. Resizing a window that + /// cannot be resized by the user works, but may be irritating to the user. + /// </summary> + public bool Resizable + { + get + { + return (Style & WindowStyleFlags.THICKFRAME) != 0; + } + } - /// <summary> - /// An image of this window. Unlike a screen shot, this will not - /// contain parts of other windows (partially) cover this window. - /// If you want to create a screen shot, use the - /// <see cref="System.Drawing.Graphics.CopyFromScreen(System.Drawing.Point,System.Drawing.Point,System.Drawing.Size)"/> - /// function and use the <see cref="SystemWindow.Rectangle"/> property for - /// the range. - /// </summary> - public Image Image - { - get - { - Bitmap bmp = new Bitmap(Position.Width, Position.Height); - Graphics g = Graphics.FromImage(bmp); - IntPtr pTarget = g.GetHdc(); - IntPtr pSource = CreateCompatibleDC(pTarget); - IntPtr pOrig = SelectObject(pSource, bmp.GetHbitmap()); - PrintWindow(HWnd, pTarget, 0); - IntPtr pNew = SelectObject(pSource, pOrig); - DeleteObject(pOrig); - DeleteObject(pNew); - DeleteObject(pSource); - g.ReleaseHdc(pTarget); - g.Dispose(); - return bmp; - } - } + /// <summary> + /// An image of this window. Unlike a screen shot, this will not + /// contain parts of other windows (partially) cover this window. + /// If you want to create a screen shot, use the + /// <see cref="System.Drawing.Graphics.CopyFromScreen(System.Drawing.Point,System.Drawing.Point,System.Drawing.Size)"/> + /// function and use the <see cref="SystemWindow.Rectangle"/> property for + /// the range. + /// </summary> + public Image Image + { + get + { + Bitmap bmp = new Bitmap(Position.Width, Position.Height); + Graphics g = Graphics.FromImage(bmp); + IntPtr pTarget = g.GetHdc(); + IntPtr pSource = CreateCompatibleDC(pTarget); + IntPtr pOrig = SelectObject(pSource, bmp.GetHbitmap()); + PrintWindow(HWnd, pTarget, 0); + IntPtr pNew = SelectObject(pSource, pOrig); + DeleteObject(pOrig); + DeleteObject(pNew); + DeleteObject(pSource); + g.ReleaseHdc(pTarget); + g.Dispose(); + return bmp; + } + } - /// <summary> - /// The window's visible region. - /// </summary> - public Region Region - { - get - { - IntPtr rgn = CreateRectRgn(0, 0, 0, 0); - int r = GetWindowRgn(HWnd, rgn); - if (r == (int)GetWindowRegnReturnValues.ERROR) - { - return null; - } - return Region.FromHrgn(rgn); - } - set - { - Bitmap bmp = new Bitmap(1, 1); - Graphics g = Graphics.FromImage(bmp); - SetWindowRgn(HWnd, value.GetHrgn(g), true); - g.Dispose(); - } - } + /// <summary> + /// The window's visible region. + /// </summary> + public Region Region + { + get + { + IntPtr rgn = CreateRectRgn(0, 0, 0, 0); + int r = GetWindowRgn(HWnd, rgn); + if (r == (int)GetWindowRegnReturnValues.ERROR) + { + return null; + } + return Region.FromHrgn(rgn); + } + set + { + Bitmap bmp = new Bitmap(1, 1); + Graphics g = Graphics.FromImage(bmp); + SetWindowRgn(HWnd, value.GetHrgn(g), true); + g.Dispose(); + } + } - /// <summary> - /// The character used to mask passwords, if this control is - /// a text field. May be used for different purpose by other - /// controls. - /// </summary> - public char PasswordCharacter - { - get - { - return (char)SendGetMessage(EM_GETPASSWORDCHAR); - } - set - { - SendSetMessage(EM_SETPASSWORDCHAR, value); - } - } + /// <summary> + /// The character used to mask passwords, if this control is + /// a text field. May be used for different purpose by other + /// controls. + /// </summary> + public char PasswordCharacter + { + get + { + return (char)SendGetMessage(EM_GETPASSWORDCHAR); + } + set + { + SendSetMessage(EM_SETPASSWORDCHAR, value); + } + } - /// <summary> - /// The ID of a control within a dialog. This is used in - /// WM_COMMAND messages to distinguish which control sent the command. - /// </summary> - public int DialogID - { - get - { - return GetWindowLong32(_hwnd, (int)GWL.GWL_ID); - } - } + /// <summary> + /// The ID of a control within a dialog. This is used in + /// WM_COMMAND messages to distinguish which control sent the command. + /// </summary> + public int DialogID + { + get + { + return GetWindowLong32(_hwnd, (int)GWL.GWL_ID); + } + } - /// <summary> - /// Get the window that is below this window in the Z order, - /// or null if this is the lowest window. - /// </summary> - public SystemWindow WindowBelow - { - get - { - IntPtr res = GetWindow(HWnd, (uint)GetWindow_Cmd.GW_HWNDNEXT); - if (res == IntPtr.Zero) return null; - return new SystemWindow(res); - } - } + /// <summary> + /// Get the window that is below this window in the Z order, + /// or null if this is the lowest window. + /// </summary> + public SystemWindow WindowBelow + { + get + { + IntPtr res = GetWindow(HWnd, (uint)GetWindow_Cmd.GW_HWNDNEXT); + if (res == IntPtr.Zero) return null; + return new SystemWindow(res); + } + } - /// <summary> - /// Get the window that is above this window in the Z order, - /// or null, if this is the foreground window. - /// </summary> - public SystemWindow WindowAbove - { - get - { - IntPtr res = GetWindow(HWnd, (uint)GetWindow_Cmd.GW_HWNDPREV); - if (res == IntPtr.Zero) return null; - return new SystemWindow(res); - } - } + /// <summary> + /// Get the window that is above this window in the Z order, + /// or null, if this is the foreground window. + /// </summary> + public SystemWindow WindowAbove + { + get + { + IntPtr res = GetWindow(HWnd, (uint)GetWindow_Cmd.GW_HWNDPREV); + if (res == IntPtr.Zero) return null; + return new SystemWindow(res); + } + } - /// <summary> - /// Gets a device context for this window. - /// </summary> - /// <param name="clientAreaOnly">Whether to get the context for - /// the client area or for the full window.</param> - public WindowDeviceContext GetDeviceContext(bool clientAreaOnly) - { - if (clientAreaOnly) - { - return new WindowDeviceContext(this, GetDC(_hwnd)); - } - else - { - return new WindowDeviceContext(this, GetWindowDC(_hwnd)); - } - } + /// <summary> + /// Gets a device context for this window. + /// </summary> + /// <param name="clientAreaOnly">Whether to get the context for + /// the client area or for the full window.</param> + public WindowDeviceContext GetDeviceContext(bool clientAreaOnly) + { + if (clientAreaOnly) + { + return new WindowDeviceContext(this, GetDC(_hwnd)); + } + else + { + return new WindowDeviceContext(this, GetWindowDC(_hwnd)); + } + } - /// <summary> - /// The content of this window. Is only supported for some - /// kinds of controls (like text or list boxes). - /// </summary> - public WindowContent Content - { - get - { - return WindowContentParser.Parse(this); - } - } + /// <summary> + /// The content of this window. Is only supported for some + /// kinds of controls (like text or list boxes). + /// </summary> + public WindowContent Content + { + get + { + return WindowContentParser.Parse(this); + } + } - /// <summary> - /// Whether this control, which is a check box or radio button, is checked. - /// </summary> - public CheckState CheckState - { - get - { - return (CheckState)SendGetMessage(BM_GETCHECK); - } - set - { - SendSetMessage(BM_SETCHECK, (uint)value); - } - } + /// <summary> + /// Whether this control, which is a check box or radio button, is checked. + ... [truncated message content] |
From: <fra...@us...> - 2008-04-06 17:29:47
|
Revision: 65 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=65&view=rev Author: frank_koch Date: 2008-04-06 10:28:31 -0700 (Sun, 06 Apr 2008) Log Message: ----------- WinternalExplorer: added window-highlighting while dragging crosshair Modified Paths: -------------- trunk/ManagedWinapi/SystemWindow.cs trunk/Tools/WinternalExplorer/MainForm.cs Modified: trunk/ManagedWinapi/SystemWindow.cs =================================================================== --- trunk/ManagedWinapi/SystemWindow.cs 2008-04-06 14:41:30 UTC (rev 64) +++ trunk/ManagedWinapi/SystemWindow.cs 2008-04-06 17:28:31 UTC (rev 65) @@ -29,1298 +29,1366 @@ namespace ManagedWinapi.Windows { - /// <summary> - /// Window Style Flags. The original constants started with WS_. - /// </summary> - /// <seealso cref="SystemWindow.Style"/> - [Flags] - public enum WindowStyleFlags - { - /// <summary> - /// WS_OVERLAPPED - /// </summary> - OVERLAPPED = 0x00000000, + /// <summary> + /// Window Style Flags. The original constants started with WS_. + /// </summary> + /// <seealso cref="SystemWindow.Style"/> + [Flags] + public enum WindowStyleFlags + { + /// <summary> + /// WS_OVERLAPPED + /// </summary> + OVERLAPPED = 0x00000000, - /// <summary> - /// WS_POPUP - /// </summary> - POPUP = unchecked((int)0x80000000), + /// <summary> + /// WS_POPUP + /// </summary> + POPUP = unchecked((int)0x80000000), - /// <summary> - /// WS_CHILD - /// </summary> - CHILD = 0x40000000, + /// <summary> + /// WS_CHILD + /// </summary> + CHILD = 0x40000000, - /// <summary> - /// WS_MINIMIZE - /// </summary> - MINIMIZE = 0x20000000, + /// <summary> + /// WS_MINIMIZE + /// </summary> + MINIMIZE = 0x20000000, - /// <summary> - /// WS_VISIBLE - /// </summary> - VISIBLE = 0x10000000, + /// <summary> + /// WS_VISIBLE + /// </summary> + VISIBLE = 0x10000000, - /// <summary> - /// WS_DISABLED - /// </summary> - DISABLED = 0x08000000, + /// <summary> + /// WS_DISABLED + /// </summary> + DISABLED = 0x08000000, - /// <summary> - /// WS_CLIPSIBLINGS - /// </summary> - CLIPSIBLINGS = 0x04000000, + /// <summary> + /// WS_CLIPSIBLINGS + /// </summary> + CLIPSIBLINGS = 0x04000000, - /// <summary> - /// WS_CLIPCHILDREN - /// </summary> - CLIPCHILDREN = 0x02000000, + /// <summary> + /// WS_CLIPCHILDREN + /// </summary> + CLIPCHILDREN = 0x02000000, - /// <summary> - /// WS_MAXIMIZE - /// </summary> - MAXIMIZE = 0x01000000, + /// <summary> + /// WS_MAXIMIZE + /// </summary> + MAXIMIZE = 0x01000000, - /// <summary> - /// WS_BORDER - /// </summary> - BORDER = 0x00800000, + /// <summary> + /// WS_BORDER + /// </summary> + BORDER = 0x00800000, - /// <summary> - /// WS_DLGFRAME - /// </summary> - DLGFRAME = 0x00400000, + /// <summary> + /// WS_DLGFRAME + /// </summary> + DLGFRAME = 0x00400000, - /// <summary> - /// WS_VSCROLL - /// </summary> - VSCROLL = 0x00200000, + /// <summary> + /// WS_VSCROLL + /// </summary> + VSCROLL = 0x00200000, - /// <summary> - /// WS_HSCROLL - /// </summary> - HSCROLL = 0x00100000, + /// <summary> + /// WS_HSCROLL + /// </summary> + HSCROLL = 0x00100000, - /// <summary> - /// WS_SYSMENU - /// </summary> - SYSMENU = 0x00080000, + /// <summary> + /// WS_SYSMENU + /// </summary> + SYSMENU = 0x00080000, - /// <summary> - /// WS_THICKFRAME - /// </summary> - THICKFRAME = 0x00040000, + /// <summary> + /// WS_THICKFRAME + /// </summary> + THICKFRAME = 0x00040000, - /// <summary> - /// WS_GROUP - /// </summary> - GROUP = 0x00020000, + /// <summary> + /// WS_GROUP + /// </summary> + GROUP = 0x00020000, - /// <summary> - /// WS_TABSTOP - /// </summary> - TABSTOP = 0x00010000, + /// <summary> + /// WS_TABSTOP + /// </summary> + TABSTOP = 0x00010000, - /// <summary> - /// WS_MINIMIZEBOX - /// </summary> - MINIMIZEBOX = 0x00020000, + /// <summary> + /// WS_MINIMIZEBOX + /// </summary> + MINIMIZEBOX = 0x00020000, - /// <summary> - /// WS_MAXIMIZEBOX - /// </summary> - MAXIMIZEBOX = 0x00010000, + /// <summary> + /// WS_MAXIMIZEBOX + /// </summary> + MAXIMIZEBOX = 0x00010000, - /// <summary> - /// WS_CAPTION - /// </summary> - CAPTION = BORDER | DLGFRAME, + /// <summary> + /// WS_CAPTION + /// </summary> + CAPTION = BORDER | DLGFRAME, - /// <summary> - /// WS_TILED - /// </summary> - TILED = OVERLAPPED, + /// <summary> + /// WS_TILED + /// </summary> + TILED = OVERLAPPED, - /// <summary> - /// WS_ICONIC - /// </summary> - ICONIC = MINIMIZE, + /// <summary> + /// WS_ICONIC + /// </summary> + ICONIC = MINIMIZE, - /// <summary> - /// WS_SIZEBOX - /// </summary> - SIZEBOX = THICKFRAME, + /// <summary> + /// WS_SIZEBOX + /// </summary> + SIZEBOX = THICKFRAME, - /// <summary> - /// WS_TILEDWINDOW - /// </summary> - TILEDWINDOW = OVERLAPPEDWINDOW, + /// <summary> + /// WS_TILEDWINDOW + /// </summary> + TILEDWINDOW = OVERLAPPEDWINDOW, - /// <summary> - /// WS_OVERLAPPEDWINDOW - /// </summary> - OVERLAPPEDWINDOW = OVERLAPPED | CAPTION | SYSMENU | THICKFRAME | MINIMIZEBOX | MAXIMIZEBOX, + /// <summary> + /// WS_OVERLAPPEDWINDOW + /// </summary> + OVERLAPPEDWINDOW = OVERLAPPED | CAPTION | SYSMENU | THICKFRAME | MINIMIZEBOX | MAXIMIZEBOX, - /// <summary> - /// WS_POPUPWINDOW - /// </summary> - POPUPWINDOW = POPUP | BORDER | SYSMENU, + /// <summary> + /// WS_POPUPWINDOW + /// </summary> + POPUPWINDOW = POPUP | BORDER | SYSMENU, - /// <summary> - /// WS_CHILDWINDOW - /// </summary> - CHILDWINDOW = CHILD, - } + /// <summary> + /// WS_CHILDWINDOW + /// </summary> + CHILDWINDOW = CHILD, + } - /// <summary> - /// Extended Window Style Flags. The original constants started with WS_EX_. - /// </summary> - /// <seealso cref="SystemWindow.ExtendedStyle"/> - [Flags] - public enum WindowExStyleFlags : uint - { - /// <summary> - /// Specifies that a window created with this style accepts drag-drop files. - /// </summary> - ACCEPTFILES = 0x00000010, - /// <summary> - /// Forces a top-level window onto the taskbar when the window is visible. - /// </summary> - APPWINDOW = 0x00040000, - /// <summary> - /// Specifies that a window has a border with a sunken edge. - /// </summary> - CLIENTEDGE = 0x00000200, - /// <summary> - /// Windows XP: Paints all descendants of a window in bottom-to-top painting order using double-buffering. For more information, see Remarks. This cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC. - /// </summary> - COMPOSITED = 0x02000000, - /// <summary> - /// Includes a question mark in the title bar of the window. When the user clicks the question mark, the cursor changes to a question mark with a pointer. If the user then clicks a child window, the child receives a WM_HELP message. The child window should pass the message to the parent window procedure, which should call the WinHelp function using the HELP_WM_HELP command. The Help application displays a pop-up window that typically contains help for the child window. - /// WS_EX_CONTEXTHELP cannot be used with the WS_MAXIMIZEBOX or WS_MINIMIZEBOX styles. - /// </summary> - CONTEXTHELP = 0x00000400, - /// <summary> - /// The window itself contains child windows that should take part in dialog box navigation. If this style is specified, the dialog manager recurses into children of this window when performing navigation operations such as handling the TAB key, an arrow key, or a keyboard mnemonic. - /// </summary> - CONTROLPARENT = 0x00010000, - /// <summary> - /// Creates a window that has a double border; the window can, optionally, be created with a title bar by specifying the WS_CAPTION style in the dwStyle parameter. - /// </summary> - DLGMODALFRAME = 0x00000001, - /// <summary> - /// Windows 2000/XP: Creates a layered window. Note that this cannot be used for child windows. Also, this cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC. - /// </summary> - LAYERED = 0x00080000, - /// <summary> - /// Arabic and Hebrew versions of Windows 98/Me, Windows 2000/XP: Creates a window whose horizontal origin is on the right edge. Increasing horizontal values advance to the left. - /// </summary> - LAYOUTRTL = 0x00400000, - /// <summary> - /// Creates a window that has generic left-aligned properties. This is the default. - /// </summary> - LEFT = 0x00000000, - /// <summary> - /// If the shell language is Hebrew, Arabic, or another language that supports reading order alignment, the vertical scroll bar (if present) is to the left of the client area. For other languages, the style is ignored. - /// </summary> - LEFTSCROLLBAR = 0x00004000, - /// <summary> - /// The window text is displayed using left-to-right reading-order properties. This is the default. - /// </summary> - LTRREADING = 0x00000000, - /// <summary> - /// Creates a multiple-document interface (MDI) child window. - /// </summary> - MDICHILD = 0x00000040, - /// <summary> - /// Windows 2000/XP: A top-level window created with this style does not become the foreground window when the user clicks it. The system does not bring this window to the foreground when the user minimizes or closes the foreground window. - /// To activate the window, use the SetActiveWindow or SetForegroundWindow function. - /// The window does not appear on the taskbar by default. To force the window to appear on the taskbar, use the WS_EX_APPWINDOW style. - /// </summary> - NOACTIVATE = 0x08000000, - /// <summary> - /// Windows 2000/XP: A window created with this style does not pass its window layout to its child windows. - /// </summary> - NOINHERITLAYOUT = 0x00100000, - /// <summary> - /// Specifies that a child window created with this style does not send the WM_PARENTNOTIFY message to its parent window when it is created or destroyed. - /// </summary> - NOPARENTNOTIFY = 0x00000004, - /// <summary> - /// Combines the WS_EX_CLIENTEDGE and WS_EX_WINDOWEDGE styles. - /// </summary> - OVERLAPPEDWINDOW = WINDOWEDGE | CLIENTEDGE, - /// <summary> - /// Combines the WS_EX_WINDOWEDGE, WS_EX_TOOLWINDOW, and WS_EX_TOPMOST styles. - /// </summary> - PALETTEWINDOW = WINDOWEDGE | TOOLWINDOW | TOPMOST, - /// <summary> - /// The window has generic "right-aligned" properties. This depends on the window class. This style has an effect only if the shell language is Hebrew, Arabic, or another language that supports reading-order alignment; otherwise, the style is ignored. - /// Using the WS_EX_RIGHT style for static or edit controls has the same effect as using the SS_RIGHT or ES_RIGHT style, respectively. Using this style with button controls has the same effect as using BS_RIGHT and BS_RIGHTBUTTON styles. - /// </summary> - RIGHT = 0x00001000, - /// <summary> - /// Vertical scroll bar (if present) is to the right of the client area. This is the default. - /// </summary> - RIGHTSCROLLBAR = 0x00000000, - /// <summary> - /// If the shell language is Hebrew, Arabic, or another language that supports reading-order alignment, the window text is displayed using right-to-left reading-order properties. For other languages, the style is ignored. - /// </summary> - RTLREADING = 0x00002000, - /// <summary> - /// Creates a window with a three-dimensional border style intended to be used for items that do not accept user input. - /// </summary> - STATICEDGE = 0x00020000, - /// <summary> - /// Creates a tool window; that is, a window intended to be used as a floating toolbar. A tool window has a title bar that is shorter than a normal title bar, and the window title is drawn using a smaller font. A tool window does not appear in the taskbar or in the dialog that appears when the user presses ALT+TAB. If a tool window has a system menu, its icon is not displayed on the title bar. However, you can display the system menu by right-clicking or by typing ALT+SPACE. - /// </summary> - TOOLWINDOW = 0x00000080, - /// <summary> - /// Specifies that a window created with this style should be placed above all non-topmost windows and should stay above them, even when the window is deactivated. To add or remove this style, use the SetWindowPos function. - /// </summary> - TOPMOST = 0x00000008, - /// <summary> - /// Specifies that a window created with this style should not be painted until siblings beneath the window (that were created by the same thread) have been painted. The window appears transparent because the bits of underlying sibling windows have already been painted. - /// To achieve transparency without these restrictions, use the SetWindowRgn function. - /// </summary> - TRANSPARENT = 0x00000020, - /// <summary> - /// Specifies that a window has a border with a raised edge. - /// </summary> - WINDOWEDGE = 0x00000100 - } + /// <summary> + /// Extended Window Style Flags. The original constants started with WS_EX_. + /// </summary> + /// <seealso cref="SystemWindow.ExtendedStyle"/> + [Flags] + public enum WindowExStyleFlags : uint + { + /// <summary> + /// Specifies that a window created with this style accepts drag-drop files. + /// </summary> + ACCEPTFILES = 0x00000010, + /// <summary> + /// Forces a top-level window onto the taskbar when the window is visible. + /// </summary> + APPWINDOW = 0x00040000, + /// <summary> + /// Specifies that a window has a border with a sunken edge. + /// </summary> + CLIENTEDGE = 0x00000200, + /// <summary> + /// Windows XP: Paints all descendants of a window in bottom-to-top painting order using double-buffering. For more information, see Remarks. This cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC. + /// </summary> + COMPOSITED = 0x02000000, + /// <summary> + /// Includes a question mark in the title bar of the window. When the user clicks the question mark, the cursor changes to a question mark with a pointer. If the user then clicks a child window, the child receives a WM_HELP message. The child window should pass the message to the parent window procedure, which should call the WinHelp function using the HELP_WM_HELP command. The Help application displays a pop-up window that typically contains help for the child window. + /// WS_EX_CONTEXTHELP cannot be used with the WS_MAXIMIZEBOX or WS_MINIMIZEBOX styles. + /// </summary> + CONTEXTHELP = 0x00000400, + /// <summary> + /// The window itself contains child windows that should take part in dialog box navigation. If this style is specified, the dialog manager recurses into children of this window when performing navigation operations such as handling the TAB key, an arrow key, or a keyboard mnemonic. + /// </summary> + CONTROLPARENT = 0x00010000, + /// <summary> + /// Creates a window that has a double border; the window can, optionally, be created with a title bar by specifying the WS_CAPTION style in the dwStyle parameter. + /// </summary> + DLGMODALFRAME = 0x00000001, + /// <summary> + /// Windows 2000/XP: Creates a layered window. Note that this cannot be used for child windows. Also, this cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC. + /// </summary> + LAYERED = 0x00080000, + /// <summary> + /// Arabic and Hebrew versions of Windows 98/Me, Windows 2000/XP: Creates a window whose horizontal origin is on the right edge. Increasing horizontal values advance to the left. + /// </summary> + LAYOUTRTL = 0x00400000, + /// <summary> + /// Creates a window that has generic left-aligned properties. This is the default. + /// </summary> + LEFT = 0x00000000, + /// <summary> + /// If the shell language is Hebrew, Arabic, or another language that supports reading order alignment, the vertical scroll bar (if present) is to the left of the client area. For other languages, the style is ignored. + /// </summary> + LEFTSCROLLBAR = 0x00004000, + /// <summary> + /// The window text is displayed using left-to-right reading-order properties. This is the default. + /// </summary> + LTRREADING = 0x00000000, + /// <summary> + /// Creates a multiple-document interface (MDI) child window. + /// </summary> + MDICHILD = 0x00000040, + /// <summary> + /// Windows 2000/XP: A top-level window created with this style does not become the foreground window when the user clicks it. The system does not bring this window to the foreground when the user minimizes or closes the foreground window. + /// To activate the window, use the SetActiveWindow or SetForegroundWindow function. + /// The window does not appear on the taskbar by default. To force the window to appear on the taskbar, use the WS_EX_APPWINDOW style. + /// </summary> + NOACTIVATE = 0x08000000, + /// <summary> + /// Windows 2000/XP: A window created with this style does not pass its window layout to its child windows. + /// </summary> + NOINHERITLAYOUT = 0x00100000, + /// <summary> + /// Specifies that a child window created with this style does not send the WM_PARENTNOTIFY message to its parent window when it is created or destroyed. + /// </summary> + NOPARENTNOTIFY = 0x00000004, + /// <summary> + /// Combines the WS_EX_CLIENTEDGE and WS_EX_WINDOWEDGE styles. + /// </summary> + OVERLAPPEDWINDOW = WINDOWEDGE | CLIENTEDGE, + /// <summary> + /// Combines the WS_EX_WINDOWEDGE, WS_EX_TOOLWINDOW, and WS_EX_TOPMOST styles. + /// </summary> + PALETTEWINDOW = WINDOWEDGE | TOOLWINDOW | TOPMOST, + /// <summary> + /// The window has generic "right-aligned" properties. This depends on the window class. This style has an effect only if the shell language is Hebrew, Arabic, or another language that supports reading-order alignment; otherwise, the style is ignored. + /// Using the WS_EX_RIGHT style for static or edit controls has the same effect as using the SS_RIGHT or ES_RIGHT style, respectively. Using this style with button controls has the same effect as using BS_RIGHT and BS_RIGHTBUTTON styles. + /// </summary> + RIGHT = 0x00001000, + /// <summary> + /// Vertical scroll bar (if present) is to the right of the client area. This is the default. + /// </summary> + RIGHTSCROLLBAR = 0x00000000, + /// <summary> + /// If the shell language is Hebrew, Arabic, or another language that supports reading-order alignment, the window text is displayed using right-to-left reading-order properties. For other languages, the style is ignored. + /// </summary> + RTLREADING = 0x00002000, + /// <summary> + /// Creates a window with a three-dimensional border style intended to be used for items that do not accept user input. + /// </summary> + STATICEDGE = 0x00020000, + /// <summary> + /// Creates a tool window; that is, a window intended to be used as a floating toolbar. A tool window has a title bar that is shorter than a normal title bar, and the window title is drawn using a smaller font. A tool window does not appear in the taskbar or in the dialog that appears when the user presses ALT+TAB. If a tool window has a system menu, its icon is not displayed on the title bar. However, you can display the system menu by right-clicking or by typing ALT+SPACE. + /// </summary> + TOOLWINDOW = 0x00000080, + /// <summary> + /// Specifies that a window created with this style should be placed above all non-topmost windows and should stay above them, even when the window is deactivated. To add or remove this style, use the SetWindowPos function. + /// </summary> + TOPMOST = 0x00000008, + /// <summary> + /// Specifies that a window created with this style should not be painted until siblings beneath the window (that were created by the same thread) have been painted. The window appears transparent because the bits of underlying sibling windows have already been painted. + /// To achieve transparency without these restrictions, use the SetWindowRgn function. + /// </summary> + TRANSPARENT = 0x00000020, + /// <summary> + /// Specifies that a window has a border with a raised edge. + /// </summary> + WINDOWEDGE = 0x00000100 + } - /// <summary> - /// Represents any window used by Windows, including those from other applications. - /// </summary> - public class SystemWindow - { + /// <summary> + /// Represents any window used by Windows, including those from other applications. + /// </summary> + public class SystemWindow + { - private static readonly Predicate<SystemWindow> ALL = delegate { return true; }; + private static readonly Predicate<SystemWindow> ALL = delegate { return true; }; - private IntPtr _hwnd; + private IntPtr _hwnd; - /// <summary> - /// Allows getting the current foreground window and setting it. - /// </summary> - public static SystemWindow ForegroundWindow - { - get - { - return new SystemWindow(GetForegroundWindow()); - } - set - { - SetForegroundWindow(value.HWnd); - } - } + /// <summary> + /// Allows getting the current foreground window and setting it. + /// </summary> + public static SystemWindow ForegroundWindow + { + get + { + return new SystemWindow(GetForegroundWindow()); + } + set + { + SetForegroundWindow(value.HWnd); + } + } - /// <summary> - /// The Desktop window, i. e. the window that covers the - /// complete desktop. - /// </summary> - public static SystemWindow DesktopWindow - { - get - { - return new SystemWindow(GetDesktopWindow()); - } - } + /// <summary> + /// The Desktop window, i. e. the window that covers the + /// complete desktop. + /// </summary> + public static SystemWindow DesktopWindow + { + get + { + return new SystemWindow(GetDesktopWindow()); + } + } - /// <summary> - /// Returns all available toplevel windows. - /// </summary> - public static SystemWindow[] AllToplevelWindows - { - get - { - return FilterToplevelWindows(new Predicate<SystemWindow>(ALL)); - } - } + /// <summary> + /// Returns all available toplevel windows. + /// </summary> + public static SystemWindow[] AllToplevelWindows + { + get + { + return FilterToplevelWindows(new Predicate<SystemWindow>(ALL)); + } + } - /// <summary> - /// Returns all toplevel windows that match the given predicate. - /// </summary> - /// <param name="predicate">The predicate to filter.</param> - /// <returns>The filtered toplevel windows</returns> - public static SystemWindow[] FilterToplevelWindows(Predicate<SystemWindow> predicate) - { - List<SystemWindow> wnds = new List<SystemWindow>(); - EnumWindows(new EnumWindowsProc(delegate(IntPtr hwnd, IntPtr lParam) - { - SystemWindow tmp = new SystemWindow(hwnd); - if (predicate(tmp)) - wnds.Add(tmp); - return 1; - }), new IntPtr(0)); - return wnds.ToArray(); - } + /// <summary> + /// Returns all toplevel windows that match the given predicate. + /// </summary> + /// <param name="predicate">The predicate to filter.</param> + /// <returns>The filtered toplevel windows</returns> + public static SystemWindow[] FilterToplevelWindows(Predicate<SystemWindow> predicate) + { + List<SystemWindow> wnds = new List<SystemWindow>(); + EnumWindows(new EnumWindowsProc(delegate(IntPtr hwnd, IntPtr lParam) + { + SystemWindow tmp = new SystemWindow(hwnd); + if (predicate(tmp)) + wnds.Add(tmp); + return 1; + }), new IntPtr(0)); + return wnds.ToArray(); + } - /// <summary> - /// Finds the system window below the given point. This need not be a - /// toplevel window; disabled windows are not returned either. - /// If you have problems with transparent windows that cover nontransparent - /// windows, consider using <see cref="FromPointEx"/>, since that method - /// tries hard to avoid this problem. - /// </summary> - /// <param name="x">X coordinate</param> - /// <param name="y">Y coordinate</param> - /// <returns></returns> - public static SystemWindow FromPoint(int x, int y) - { - IntPtr hwnd = WindowFromPoint(new POINT(x, y)); - if (hwnd.ToInt64() == 0) - { - return null; - } - return new SystemWindow(hwnd); - } + /// <summary> + /// Finds the system window below the given point. This need not be a + /// toplevel window; disabled windows are not returned either. + /// If you have problems with transparent windows that cover nontransparent + /// windows, consider using <see cref="FromPointEx"/>, since that method + /// tries hard to avoid this problem. + /// </summary> + /// <param name="x">X coordinate</param> + /// <param name="y">Y coordinate</param> + /// <returns></returns> + public static SystemWindow FromPoint(int x, int y) + { + IntPtr hwnd = WindowFromPoint(new POINT(x, y)); + if (hwnd.ToInt64() == 0) + { + return null; + } + return new SystemWindow(hwnd); + } - /// <summary> - /// Finds the system window below the given point. This method uses a more - /// sophisticated algorithm than <see cref="FromPoint"/>, but is slower. - /// </summary> - /// <param name="x">X coordinate</param> - /// <param name="y">Y coordinate</param> - /// <param name="toplevel">Whether to return the toplevel window.</param> - /// <param name="enabledOnly">Whether to return enabled windows only.</param> - /// <returns></returns> - public static SystemWindow FromPointEx(int x, int y, bool toplevel, bool enabledOnly) { - SystemWindow sw = FromPoint(x, y); - if (sw == null) return null; - while (sw.ParentSymmetric != null) - sw = sw.ParentSymmetric; - if (toplevel) - return sw; - int area; - area = getArea(sw); - SystemWindow result = sw; - foreach(SystemWindow w in sw.AllDescendantWindows) { - if (w.Visible && (w.Enabled || !enabledOnly)) - { - if (w.Rectangle.ToRectangle().Contains(x, y)) - { - int ar2 = getArea(w); - if (ar2 <= area) - { - area = ar2; - result = w; - } - } - } - } - return result; - } + /// <summary> + /// Finds the system window below the given point. This method uses a more + /// sophisticated algorithm than <see cref="FromPoint"/>, but is slower. + /// </summary> + /// <param name="x">X coordinate</param> + /// <param name="y">Y coordinate</param> + /// <param name="toplevel">Whether to return the toplevel window.</param> + /// <param name="enabledOnly">Whether to return enabled windows only.</param> + /// <returns></returns> + public static SystemWindow FromPointEx(int x, int y, bool toplevel, bool enabledOnly) + { + SystemWindow sw = FromPoint(x, y); + if (sw == null) return null; + while (sw.ParentSymmetric != null) + sw = sw.ParentSymmetric; + if (toplevel) + return sw; + int area; + area = getArea(sw); + SystemWindow result = sw; + foreach (SystemWindow w in sw.AllDescendantWindows) + { + if (w.Visible && (w.Enabled || !enabledOnly)) + { + if (w.Rectangle.ToRectangle().Contains(x, y)) + { + int ar2 = getArea(w); + if (ar2 <= area) + { + area = ar2; + result = w; + } + } + } + } + return result; + } - private static int getArea(SystemWindow sw) - { - RECT rr = sw.Rectangle; - return rr.Height * rr.Width; - } + private static int getArea(SystemWindow sw) + { + RECT rr = sw.Rectangle; + return rr.Height * rr.Width; + } - /// <summary> - /// Create a new SystemWindow instance from a window handle. - /// </summary> - /// <param name="HWnd">The window handle.</param> - public SystemWindow(IntPtr HWnd) - { - _hwnd = HWnd; - } + /// <summary> + /// Create a new SystemWindow instance from a window handle. + /// </summary> + /// <param name="HWnd">The window handle.</param> + public SystemWindow(IntPtr HWnd) + { + _hwnd = HWnd; + } - /// <summary> - /// Create a new SystemWindow instance from a Windows Forms Control. - /// </summary> - /// <param name="control">The control.</param> - public SystemWindow(Control control) - { - _hwnd = control.Handle; - } + /// <summary> + /// Create a new SystemWindow instance from a Windows Forms Control. + /// </summary> + /// <param name="control">The control.</param> + public SystemWindow(Control control) + { + _hwnd = control.Handle; + } - /// <summary> - /// Return all descendant windows (child windows and their descendants). - /// </summary> - public SystemWindow[] AllDescendantWindows - { - get - { - return FilterDescendantWindows(false, ALL); - } - } + /// <summary> + /// Return all descendant windows (child windows and their descendants). + /// </summary> + public SystemWindow[] AllDescendantWindows + { + get + { + return FilterDescendantWindows(false, ALL); + } + } - /// <summary> - /// Return all direct child windows. - /// </summary> - public SystemWindow[] AllChildWindows - { - get - { - return FilterDescendantWindows(true, ALL); - } - } + /// <summary> + /// Return all direct child windows. + /// </summary> + public SystemWindow[] AllChildWindows + { + get + { + return FilterDescendantWindows(true, ALL); + } + } - /// <summary> - /// Returns all child windows that match the given predicate. - /// </summary> - /// <param name="directOnly">Whether to include only direct children (no descendants)</param> - /// <param name="predicate">The predicate to filter.</param> - /// <returns>The list of child windows.</returns> - public SystemWindow[] FilterDescendantWindows(bool directOnly, Predicate<SystemWindow> predicate) - { - List<SystemWindow> wnds = new List<SystemWindow>(); - EnumChildWindows(_hwnd, delegate(IntPtr hwnd, IntPtr lParam) - { - SystemWindow tmp = new SystemWindow(hwnd); - bool add = true; - if (directOnly) - { - add = tmp.Parent._hwnd == _hwnd; - } - if (add && predicate(tmp)) - wnds.Add(tmp); - return 1; - }, new IntPtr(0)); - return wnds.ToArray(); - } + /// <summary> + /// Returns all child windows that match the given predicate. + /// </summary> + /// <param name="directOnly">Whether to include only direct children (no descendants)</param> + /// <param name="predicate">The predicate to filter.</param> + /// <returns>The list of child windows.</returns> + public SystemWindow[] FilterDescendantWindows(bool directOnly, Predicate<SystemWindow> predicate) + { + List<SystemWindow> wnds = new List<SystemWindow>(); + EnumChildWindows(_hwnd, delegate(IntPtr hwnd, IntPtr lParam) + { + SystemWindow tmp = new SystemWindow(hwnd); + bool add = true; + if (directOnly) + { + add = tmp.Parent._hwnd == _hwnd; + } + if (add && predicate(tmp)) + wnds.Add(tmp); + return 1; + }, new IntPtr(0)); + return wnds.ToArray(); + } - /// <summary> - /// The Window handle of this window. - /// </summary> - public IntPtr HWnd { get { return _hwnd; } } + /// <summary> + /// The Window handle of this window. + /// </summary> + public IntPtr HWnd { get { return _hwnd; } } - /// <summary> - /// The title of this window (by the <c>GetWindowText</c> API function). - /// </summary> - public string Title - { - get - { - StringBuilder sb = new StringBuilder(GetWindowTextLength(_hwnd) + 1); - GetWindowText(_hwnd, sb, sb.Capacity); - return sb.ToString(); - } + /// <summary> + /// The title of this window (by the <c>GetWindowText</c> API function). + /// </summary> + public string Title + { + get + { + StringBuilder sb = new StringBuilder(GetWindowTextLength(_hwnd) + 1); + GetWindowText(_hwnd, sb, sb.Capacity); + return sb.ToString(); + } - set - { - SetWindowText(_hwnd, value); - } - } + set + { + SetWindowText(_hwnd, value); + } + } - /// <summary> - /// The name of the window class (by the <c>GetClassName</c> API function). - /// This class has nothing to do with classes in C# or other .NET languages. - /// </summary> - public string ClassName - { - get - { - int length = 64; - while (true) - { - StringBuilder sb = new StringBuilder(length); - ApiHelper.FailIfZero(GetClassName(_hwnd, sb, sb.Capacity)); - if (sb.Length != length - 1) - { - return sb.ToString(); - } - length *= 2; - } - } - } + /// <summary> + /// The name of the window class (by the <c>GetClassName</c> API function). + /// This class has nothing to do with classes in C# or other .NET languages. + /// </summary> + public string ClassName + { + get + { + int length = 64; + while (true) + { + StringBuilder sb = new StringBuilder(length); + ApiHelper.FailIfZero(GetClassName(_hwnd, sb, sb.Capacity)); + if (sb.Length != length - 1) + { + return sb.ToString(); + } + length *= 2; + } + } + } - /// <summary> - /// Whether this window is currently visible. A window is visible if its - /// and all ancestor's visibility flags are true. - /// </summary> - public bool Visible - { - get - { - return IsWindowVisible(_hwnd); - } - } + /// <summary> + /// Whether this window is currently visible. A window is visible if its + /// and all ancestor's visibility flags are true. + /// </summary> + public bool Visible + { + get + { + return IsWindowVisible(_hwnd); + } + } - /// <summary> - /// Whether this window always appears above all other windows - /// that do not have this property set to true. - /// </summary> - public bool TopMost - { - get - { - return (ExtendedStyle & WindowExStyleFlags.TOPMOST) != 0; - } - set - { - if (value) - { - SetWindowPos(_hwnd, new IntPtr(-1), 0, 0, 0, 0, 3); - } - else - { - SetWindowPos(_hwnd, new IntPtr(-2), 0, 0, 0, 0, 3); - } - } - } + /// <summary> + /// Whether this window always appears above all other windows + /// that do not have this property set to true. + /// </summary> + public bool TopMost + { + get + { + return (ExtendedStyle & WindowExStyleFlags.TOPMOST) != 0; + } + set + { + if (value) + { + SetWindowPos(_hwnd, new IntPtr(-1), 0, 0, 0, 0, 3); + } + else + { + SetWindowPos(_hwnd, new IntPtr(-2), 0, 0, 0, 0, 3); + } + } + } - /// <summary> - /// Whether this window is currently enabled (able to accept keyboard input). - /// </summary> - public bool Enabled - { - get - { - return IsWindowEnabled(_hwnd); - } - set - { - EnableWindow(_hwnd, value); - } - } + /// <summary> + /// Whether this window is currently enabled (able to accept keyboard input). + /// </summary> + public bool Enabled + { + get + { + return IsWindowEnabled(_hwnd); + } + set + { + EnableWindow(_hwnd, value); + } + } - /// <summary> - /// Returns or sets the visibility flag. - /// </summary> - /// <seealso cref="SystemWindow.Visible"/> - public bool VisibilityFlag - { - get - { - return (Style & WindowStyleFlags.VISIBLE) != 0; - } - set - { - if (value) - { - ShowWindow(_hwnd, 5); - } - else - { - ShowWindow(_hwnd, 0); - } - } - } + /// <summary> + /// Returns or sets the visibility flag. + /// </summary> + /// <seealso cref="SystemWindow.Visible"/> + public bool VisibilityFlag + { + get + { + return (Style & WindowStyleFlags.VISIBLE) != 0; + } + set + { + if (value) + { + ShowWindow(_hwnd, 5); + } + else + { + ShowWindow(_hwnd, 0); + } + } + } - /// <summary> - /// This window's style flags. - /// </summary> - public WindowStyleFlags Style - { - get - { - return (WindowStyleFlags)GetWindowLongPtr(_hwnd, (int)(GWL.GWL_STYLE)); - } - set - { - SetWindowLong(_hwnd, (int)GWL.GWL_STYLE, (int)value); - } + /// <summary> + /// This window's style flags. + /// </summary> + public WindowStyleFlags Style + { + get + { + return (WindowStyleFlags)GetWindowLongPtr(_hwnd, (int)(GWL.GWL_STYLE)); + } + set + { + SetWindowLong(_hwnd, (int)GWL.GWL_STYLE, (int)value); + } - } + } - /// <summary> - /// This window's extended style flags. - /// </summary> - public WindowExStyleFlags ExtendedStyle - { - get - { - return (WindowExStyleFlags)GetWindowLongPtr(_hwnd, (int)(GWL.GWL_EXSTYLE)); - } - set - { - SetWindowLong(_hwnd, (int)GWL.GWL_EXSTYLE, (int)value); - } - } + /// <summary> + /// This window's extended style flags. + /// </summary> + public WindowExStyleFlags ExtendedStyle + { + get + { + return (WindowExStyleFlags)GetWindowLongPtr(_hwnd, (int)(GWL.GWL_EXSTYLE)); + } + set + { + SetWindowLong(_hwnd, (int)GWL.GWL_EXSTYLE, (int)value); + } + } - /// <summary> - /// This window's parent. A dialog's parent is its owner, a component's parent is - /// the window that contains it. - /// </summary> - public SystemWindow Parent { - get - { - return new SystemWindow(GetParent(_hwnd)); - } - } + /// <summary> + /// This window's parent. A dialog's parent is its owner, a component's parent is + /// the window that contains it. + /// </summary> + public SystemWindow Parent + { + get + { + return new SystemWindow(GetParent(_hwnd)); + } + } - /// <summary> - /// The window's parent, but only if this window is its parent child. Some - /// parents, like dialog owners, do not have the window as its child. In that case, - /// <c>null</c> will be returned. - /// </summary> - public SystemWindow ParentSymmetric - { - get - { - SystemWindow result = Parent; - if (!this.IsDescendantOf(result)) result = null; - return result; - } - } + /// <summary> + /// The window's parent, but only if this window is its parent child. Some + /// parents, like dialog owners, do not have the window as its child. In that case, + /// <c>null</c> will be returned. + /// </summary> + public SystemWindow ParentSymmetric + { + get + { + SystemWindow result = Parent; + if (!this.IsDescendantOf(result)) result = null; + return result; + } + } - /// <summary> - /// The window's position inside its parent or on the screen. - /// </summary> - public RECT Position { - get - { - WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); - wp.length = Marshal.SizeOf(wp); - GetWindowPlacement(_hwnd, ref wp); - return wp.rcNormalPosition; - } + /// <summary> + /// The window's position inside its parent or on the screen. + /// </summary> + public RECT Position + { + get + { + WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); + wp.length = Marshal.SizeOf(wp); + GetWindowPlacement(_hwnd, ref wp); + return wp.rcNormalPosition; + } - set - { - WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); - wp.length = Marshal.SizeOf(wp); - GetWindowPlacement(_hwnd, ref wp); - wp.rcNormalPosition = value; - SetWindowPlacement(_hwnd, ref wp); - } - } + set + { + WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); + wp.length = Marshal.SizeOf(wp); + GetWindowPlacement(_hwnd, ref wp); + wp.rcNormalPosition = value; + SetWindowPlacement(_hwnd, ref wp); + } + } - /// <summary> - /// The window's location inside its parent or on the screen. - /// </summary> - public Point Location - { - get - { - return Position.Location; - } + /// <summary> + /// The window's location inside its parent or on the screen. + /// </summary> + public Point Location + { + get + { + return Position.Location; + } - set - { - WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); - wp.length = Marshal.SizeOf(wp); - GetWindowPlacement(_hwnd, ref wp); - wp.rcNormalPosition.Bottom = value.Y + wp.rcNormalPosition.Height; - wp.rcNormalPosition.Right = value.X + wp.rcNormalPosition.Width; - wp.rcNormalPosition.Top = value.Y; - wp.rcNormalPosition.Left = value.X; - SetWindowPlacement(_hwnd, ref wp); - } - } + set + { + WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); + wp.length = Marshal.SizeOf(wp); + GetWindowPlacement(_hwnd, ref wp); + wp.rcNormalPosition.Bottom = value.Y + wp.rcNormalPosition.Height; + wp.rcNormalPosition.Right = value.X + wp.rcNormalPosition.Width; + wp.rcNormalPosition.Top = value.Y; + wp.rcNormalPosition.Left = value.X; + SetWindowPlacement(_hwnd, ref wp); + } + } - /// <summary> - /// The window's size. - /// </summary> - public Size Size - { - get - { - return Position.Size; - } + /// <summary> + /// The window's size. + /// </summary> + public Size Size + { + get + { + return Position.Size; + } - set - { - WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); - wp.length = Marshal.SizeOf(wp); - GetWindowPlacement(_hwnd, ref wp); - wp.rcNormalPosition.Right = wp.rcNormalPosition.Left + value.Width; - wp.rcNormalPosition.Bottom = wp.rcNormalPosition.Top + value.Height; - SetWindowPlacement(_hwnd, ref wp); - } - } + set + { + WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); + wp.length = Marshal.SizeOf(wp); + GetWindowPlacement(_hwnd, ref wp); + wp.rcNormalPosition.Right = wp.rcNormalPosition.Left + value.Width; + wp.rcNormalPosition.Bottom = wp.rcNormalPosition.Top + value.Height; + SetWindowPlacement(_hwnd, ref wp); + } + } - /// <summary> - /// The window's position in absolute screen coordinates. Use - /// <see cref="Position"/> if you want to use the relative position. - /// </summary> - public RECT Rectangle - { - get - { - RECT r = new RECT(); - GetWindowRect(_hwnd, out r); - return r; - } - } + /// <summary> + /// The window's position in absolute screen coordinates. Use + /// <see cref="Position"/> if you want to use the relative position. + /// </summary> + public RECT Rectangle + { + get + { + RECT r = new RECT(); + GetWindowRect(_hwnd, out r); + return r; + } + } - /// <summary> - /// Check whether this window is a descendant of <c>ancestor</c> - /// </summary> - /// <param name="ancestor">The suspected ancestor</param> - /// <returns>If this is really an ancestor</returns> - public bool IsDescendantOf(SystemWindow ancestor) - { - return IsChild(ancestor._hwnd, _hwnd); - } + /// <summary> + /// Check whether this window is a descendant of <c>ancestor</c> + /// </summary> + /// <param name="ancestor">The suspected ancestor</param> + /// <returns>If this is really an ancestor</returns> + public bool IsDescendantOf(SystemWindow ancestor) + { + return IsChild(ancestor._hwnd, _hwnd); + } - /// <summary> - /// The process which created this window. - /// </summary> - public Process Process - { - get - { - int pid; - GetWindowThreadProcessId(HWnd, out pid); - return Process.GetProcessById(pid); - } - } + /// <summary> + /// The process which created this window. + /// </summary> + public Process Process + { + get + { + int pid; + GetWindowThreadProcessId(HWnd, out pid); + return Process.GetProcessById(pid); + } + } - /// <summary> - /// The Thread which created this window. - /// </summary> - public ProcessThread Thread - { - get - { - int pid; - int tid = GetWindowThreadProcessId(HWnd, out pid); - foreach (ProcessThread t in Process.GetProcessById(pid).Threads) - { - if (t.Id == tid) return t; - } - throw new Exception("Thread not found"); - } - } + /// <summary> + /// The Thread which created this window. + /// </summary> + public ProcessThread Thread + { + get + { + int pid; + int tid = GetWindowThreadProcessId(HWnd, out pid); + foreach (ProcessThread t in Process.GetProcessById(pid).Threads) + { + if (t.Id == tid) return t; + } + throw new Exception("Thread not found"); + } + } - /// <summary> - /// Whether this window is minimized or maximized. - /// </summary> - public FormWindowState WindowState - { - get { - WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); - wp.length = Marshal.SizeOf(wp); - GetWindowPlacement(HWnd, ref wp); - switch (wp.showCmd % 4) { - case 2: return FormWindowState.Minimized; - case 3: return FormWindowState.Maximized; - default: return FormWindowState.Normal; - } - } - set { - int showCommand; - switch(value) { - case FormWindowState.Normal: - showCommand = 1; - break; - case FormWindowState.Minimized: - showCommand=2; - break; - case FormWindowState.Maximized: - showCommand=3; - break; - default: return; - } - ShowWindow(HWnd, showCommand); - } - } + /// <summary> + /// Whether this window is minimized or maximized. + /// </summary> + public FormWindowState WindowState + { + get + { + WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); + wp.length = Marshal.SizeOf(wp); + GetWindowPlacement(HWnd, ref wp); + switch (wp.showCmd % 4) + { + case 2: return FormWindowState.Minimized; + case 3: return FormWindowState.Maximized; + default: return FormWindowState.Normal; + } + } + set + { + int showCommand; + switch (value) + { + case FormWindowState.Normal: + showCommand = 1; + break; + case FormWindowState.Minimized: + showCommand = 2; + break; + case FormWindowState.Maximized: + showCommand = 3; + break; + default: return; + } + ShowWindow(HWnd, showCommand); + } + } - /// <summary> - /// Whether this window can be moved on the screen by the user. - /// </summary> - public bool Movable - { - get - { - return (Style & WindowStyleFlags.SYSMENU) != 0; - } - } + /// <summary> + /// Whether this window can be moved on the screen by the user. + /// </summary> + public bool Movable + { + get + { + return (Style & WindowStyleFlags.SYSMENU) != 0; + } + } - /// <summary> - /// Whether this window can be resized by the user. Resizing a window that - /// cannot be resized by the user works, but may be irritating to the user. - /// </summary> - public bool Resizable - { - get - { - return (Style & WindowStyleFlags.THICKFRAME) != 0; - } - } + /// <summary> + /// Whether this window can be resized by the user. Resizing a window that + /// cannot be resized by the user works, but may be irritating to the user. + /// </summary> + public bool Resizable + { + get + { + return (Style & WindowStyleFlags.THICKFRAME) != 0; + } + } - /// <summary> - /// An image of this window. Unlike a screen shot, this will not - /// contain parts of other windows (partially) cover this window. - /// If you want to create a screen shot, use the - /// <see cref="System.Drawing.Graphics.CopyFromScreen(System.Drawing.Point,System.Drawing.Point,System.Drawing.Size)"/> - /// function and use the <see cref="SystemWindow.Rectangle"/> property for - /// the range. - /// </summary> - public Image Image - { - get - { - Bitmap bmp = new Bitmap(Position.Width, Position.Height); - Graphics g = Graphics.FromImage(bmp); - IntPtr pTarget = g.GetHdc(); - IntPtr pSource = CreateCompatibleDC(pTarget); - IntPtr pOrig = SelectObject(pSource, bmp.GetHbitmap()); - PrintWindow(HWnd, pTarget, 0); - IntPtr pNew = SelectObject(pSource, pOrig); - DeleteObject(pOrig); - DeleteObject(pNew); - DeleteObject(pSource); - g.ReleaseHdc(pTarget); - g.Dispose(); - return bmp; - } - } + /// <summary> + /// An image of this window. Unlike a screen shot, this will not + /// contain parts of other windows (partially) cover this window. + /// If you want to create a screen shot, use the + /// <see cref="System.Drawing.Graphics.CopyFromScreen(System.Drawing.Point,System.Drawing.Point,System.Drawing.Size)"/> + /// function and use the <see cref="SystemWindow.Rectangle"/> property for + /// the range. + /// </summary> + public Image Image + { + get + { + Bitmap bmp = new Bitmap(Position.Width, Position.Height); + Graphics g = Graphics.FromImage(bmp); + IntPtr pTarget = g.GetHdc(); + IntPtr pSource = CreateCompatibleDC(pTarget); + IntPtr pOrig = SelectObject(pSource, bmp.GetHbitmap()); + PrintWindow(HWnd, pTarget, 0); + IntPtr pNew = SelectObject(pSource, pOrig); + DeleteObject(pOrig); + DeleteObject(pNew); + DeleteObject(pSource); + g.ReleaseHdc(pTarget); + g.Dispose(); + return bmp; + } + } - /// <summary> - /// The window's visible region. - /// </summary> - public Region Region - { - get - { - IntPtr rgn = CreateRectRgn(0, 0, 0, 0); - int r = GetWindowRgn(HWnd, rgn); - if (r == (int)GetWindowRegnReturnValues.ERROR) - { - return null; - } - return Region.FromHrgn(rgn); - } - set - { - Bitmap bmp = new Bitmap(1,1); - Graphics g = Graphics.FromImage(bmp); - SetWindowRgn(HWnd, value.GetHrgn(g), true); - g.Dispose(); - } - } + /// <summary> + /// The window's visible region. + /// </summary> + public Region Region + { + get + { + IntPtr rgn = CreateRectRgn(0, 0, 0, 0); + int r = GetWindowRgn(HWnd, rgn); + if (r == (int)GetWindowRegnReturnValues.ERROR) + { + return null; + } + return Region.FromHrgn(rgn); + } + set + { + Bitmap bmp = new Bitmap(1, 1); + Graphics g = Graphics.FromImage(bmp); + SetWindowRgn(HWnd, value.GetHrgn(g), true); + g.Dispose(); + } + } - /// <summary> - /// The character used to mask passwords, if this control is - /// a text field. May be used for different purpose by other - /// controls. - /// </summary> - public char PasswordCharacter - { - get - { - return (char)SendGetMessage(EM_GETPASSWORDCHAR); - } - set - { - SendSetMessage(EM_SETPASSWORDCHAR, value); - } - } + /// <summary> + /// The character used to mask passwords, if this control is + /// a text field. May be used for different purpose by other + /// controls. + /// </summary> + public char PasswordCharacter + { + get + { + return (char)SendGetMessage(EM_GETPASSWORDCHAR); + } + set + { + SendSetMessage(EM_SETPASSWORDCHAR, value); + } + } - /// <summary> - /// The ID of a control within a dialog. This is used in - /// WM_COMMAND messages to distinguish which control sent the command. - /// </summary> - public int DialogID - { - get - { - return GetWindowLong32(_hwnd, (int)GWL.GWL_ID); - } - } + /// <summary> + /// The ID of a control within a dialog. This is used in + /// WM_COMMAND messages to distinguish which control sent the command. + /// </summary> + public int DialogID + { + get + { + return GetWindowLong32(_hwnd, (int)GWL.GWL_ID); + } + } - /// <summary> - /// Get the window that is below this window in the Z order, - /// or null if this is the lowest window. - /// </summary> - public SystemWindow WindowBelow - { - get - { - IntPtr res = GetWindow(HWnd, (uint)GetWindow_Cmd.GW_HWNDNEXT); - if (res == IntPtr.Zero) return null; - return new SystemWindow(res); - } - } + /// <summary> + /// Get the window that is below this window in the Z order, + /// or null if this is the lowest window. + /// </summary> + public SystemWindow WindowBelow + { + get + { + IntPtr res = GetWindow(HWnd, (uint)GetWindow_Cmd.GW_HWNDNEXT); + if (res == IntPtr.Zero) return null; + return new SystemWindow(res); + } + } - /// <summary> - /// Get the window that is above this window in the Z order, - /// or null, if this is the foreground window. - /// </summary> - public SystemWindow WindowAbove - { - get - { - IntPtr res = GetWindow(HWnd, (uint)GetWindow_Cmd.GW_HWNDPREV); - if (res == IntPtr.Zero) return null; - return new SystemWindow(res); - } - } + /// <summary> + /// Get the window that is above this window in the Z order, + /// or null, if this is the foreground window. + /// </summary> + public SystemWindow WindowAbove + { + get + { + IntPtr res = GetWindow(HWnd, (uint)GetWindow_Cmd.GW_HWNDPREV); + if (res == IntPtr.Zero) return null; + return new SystemWindow(res); + } + } - /// <summary> - /// Gets a device context for this window. - /// </summary> - /// <param name="clientAreaOnly">Whether to get the context for - /// the client area or for the full window.</param> - public WindowDeviceContext GetDeviceContext(bool clientAreaOnly) - { - if (clientAreaOnly) - { - return new WindowDeviceContext(this, GetDC(_hwnd)); - } - else - { - return new WindowDeviceContext(this, GetWindowDC(_hwnd)); - } - } + /// <summary> + /// Gets a device context for this window. + /// </summary> + /// <param name="clientAreaOnly">Whether to get the context for + /// the client area or for the full window.</param> + public WindowDeviceContext GetDeviceContext(bool clientAreaOnly) + { + if (clientAreaOnly) + { + return new WindowDeviceContext(this, GetDC(_hwnd)); + } + else + { + return new WindowDeviceContext(this, GetWindowDC(_hwnd)); + } + } - /// <summary> - /// The content of this window. Is only supported for some - /// kinds of controls (like text or list boxes). - /// </summary> - public WindowContent Content - { - get - { - return WindowContentParser.Parse(this); - } - } + /// <summary> + /// The content of this window. Is only supported for some + /// kinds of controls (like text or list boxes). + /// </summary> + public WindowContent Content + { + get + { + return WindowContentParser.Parse(this); + } + } - /// <summary> - /// Whether this control, which is a check box or radio button, is checked. - /// </summary> - public CheckState CheckState - { - get - { - return (CheckState)SendGetMessage(BM_GETCHECK); - } - set - { - SendSetMessage(BM_SETCHECK, (uint)value); - } - } + /// <summary> + /// Whether this control, w... [truncated message content] |
From: <sch...@us...> - 2008-04-06 14:41:35
|
Revision: 64 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=64&view=rev Author: schierlm Date: 2008-04-06 07:41:30 -0700 (Sun, 06 Apr 2008) Log Message: ----------- Fix a crash when calling TreeNodeData.Equals with an instance of a different subclass as its parameter; reduce flickering when crosshair is dragged Modified Paths: -------------- trunk/Tools/WinternalExplorer/MainForm.cs trunk/Tools/WinternalExplorer/TreeNodeData.cs Property Changed: ---------------- trunk/Tools/WinternalExplorer/ Property changes on: trunk/Tools/WinternalExplorer ___________________________________________________________________ Name: svn:ignore - bin obj *.user + bin obj *.user WinternalExplorer.suo Modified: trunk/Tools/WinternalExplorer/MainForm.cs =================================================================== --- trunk/Tools/WinternalExplorer/MainForm.cs 2008-03-29 13:45:40 UTC (rev 63) +++ trunk/Tools/WinternalExplorer/MainForm.cs 2008-04-06 14:41:30 UTC (rev 64) @@ -215,11 +215,17 @@ this.Cursor = null; } + SelectableTreeNodeData lastNode = null; + private void UpdateSelection(bool includeTree) { SelectableTreeNodeData stnd = SelectFromPoint(lastX, lastY); if (!Visible) Visible = true; - DoSelect(stnd, includeTree); + if (!stnd.Equals(lastNode)) + { + DoSelect(stnd, includeTree); + lastNode = stnd; + } } private SelectableTreeNodeData SelectFromPoint(int lastX, int lastY) @@ -482,4 +488,4 @@ } } } -} \ No newline at end of file +} Modified: trunk/Tools/WinternalExplorer/TreeNodeData.cs =================================================================== --- trunk/Tools/WinternalExplorer/TreeNodeData.cs 2008-03-29 13:45:40 UTC (rev 63) +++ trunk/Tools/WinternalExplorer/TreeNodeData.cs 2008-04-06 14:41:30 UTC (rev 64) @@ -26,7 +26,7 @@ { if (obj == null || GetType() != obj.GetType()) return false; if (mf != ((TreeNodeData)obj).mf) return false; - return Equals((TreeNodeData)obj); + return EqualsInternal((TreeNodeData)obj); } public override int GetHashCode() @@ -34,7 +34,7 @@ return 42; } - public abstract bool Equals(TreeNodeData tnd); + protected abstract bool EqualsInternal(TreeNodeData tnd); } internal abstract class SelectableTreeNodeData : TreeNodeData @@ -90,7 +90,7 @@ get { return NoneControl.Instance; } } - public override bool Equals(TreeNodeData tnd) + protected override bool EqualsInternal(TreeNodeData tnd) { return true; } @@ -198,7 +198,7 @@ get { return ProcessControl.Instance; } } - public override bool Equals(TreeNodeData tnd) + protected override bool EqualsInternal(TreeNodeData tnd) { return ((ProcessData)tnd).process.Id == process.Id; } @@ -306,7 +306,7 @@ get { return ThreadControl.Instance; } } - public override bool Equals(TreeNodeData tnd) + protected override bool EqualsInternal(TreeNodeData tnd) { return ((ThreadData)tnd).thread.Id.Equals(thread.Id); } @@ -411,7 +411,7 @@ get { return WindowControl.Instance; } } - public override bool Equals(TreeNodeData tnd) + protected override bool EqualsInternal(TreeNodeData tnd) { return ((WindowData)tnd).sw.HWnd == sw.HWnd; } @@ -601,7 +601,7 @@ get { return AccessibilityControl.Instance; } } - public override bool Equals(TreeNodeData tnd) + protected override bool EqualsInternal(TreeNodeData tnd) { return ((AccessibilityData)tnd).accobj.Equals(this.accobj); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sch...@us...> - 2008-03-29 13:45:45
|
Revision: 63 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=63&view=rev Author: schierlm Date: 2008-03-29 06:45:40 -0700 (Sat, 29 Mar 2008) Log Message: ----------- Oops: Exchange X and Y in Location property Modified Paths: -------------- trunk/ManagedWinapi/SystemWindow.cs Modified: trunk/ManagedWinapi/SystemWindow.cs =================================================================== --- trunk/ManagedWinapi/SystemWindow.cs 2008-03-25 22:38:59 UTC (rev 62) +++ trunk/ManagedWinapi/SystemWindow.cs 2008-03-29 13:45:40 UTC (rev 63) @@ -694,10 +694,10 @@ WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); wp.length = Marshal.SizeOf(wp); GetWindowPlacement(_hwnd, ref wp); - wp.rcNormalPosition.Bottom = value.X + wp.rcNormalPosition.Height; - wp.rcNormalPosition.Right = value.Y + wp.rcNormalPosition.Width; - wp.rcNormalPosition.Top = value.X; - wp.rcNormalPosition.Left = value.Y; + wp.rcNormalPosition.Bottom = value.Y + wp.rcNormalPosition.Height; + wp.rcNormalPosition.Right = value.X + wp.rcNormalPosition.Width; + wp.rcNormalPosition.Top = value.Y; + wp.rcNormalPosition.Left = value.X; SetWindowPlacement(_hwnd, ref wp); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sch...@us...> - 2008-03-25 22:39:01
|
Revision: 62 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=62&view=rev Author: schierlm Date: 2008-03-25 15:38:59 -0700 (Tue, 25 Mar 2008) Log Message: ----------- Set default event for ClipboardNotifier, Crosshair and Hotkey, Add properties Location and Size and methods IsValid and SendClose to SystemWindow. [suggested by Frank Koch] Modified Paths: -------------- trunk/ManagedWinapi/ClipboardNotifier.cs trunk/ManagedWinapi/Crosshair.cs trunk/ManagedWinapi/Hotkey.cs trunk/ManagedWinapi/SystemWindow.cs Modified: trunk/ManagedWinapi/ClipboardNotifier.cs =================================================================== --- trunk/ManagedWinapi/ClipboardNotifier.cs 2008-03-04 19:47:03 UTC (rev 61) +++ trunk/ManagedWinapi/ClipboardNotifier.cs 2008-03-25 22:38:59 UTC (rev 62) @@ -31,6 +31,7 @@ /// <summary> /// Specifies a component that monitors the system clipboard for changes. /// </summary> + [DefaultEvent("ClipboardChanged")] public class ClipboardNotifier : Component { Modified: trunk/ManagedWinapi/Crosshair.cs =================================================================== --- trunk/ManagedWinapi/Crosshair.cs 2008-03-04 19:47:03 UTC (rev 61) +++ trunk/ManagedWinapi/Crosshair.cs 2008-03-25 22:38:59 UTC (rev 62) @@ -14,6 +14,7 @@ /// on screen. This is useful to select other programs by dragging the crosshair /// to a program window. /// </summary> + [DefaultEvent("CrosshairDragged")] public partial class Crosshair : UserControl { Image myImage; Modified: trunk/ManagedWinapi/Hotkey.cs =================================================================== --- trunk/ManagedWinapi/Hotkey.cs 2008-03-04 19:47:03 UTC (rev 61) +++ trunk/ManagedWinapi/Hotkey.cs 2008-03-25 22:38:59 UTC (rev 62) @@ -31,6 +31,7 @@ /// <summary> /// Specifies a component that creates a global keyboard hotkey. /// </summary> + [DefaultEvent("HotkeyPressed")] public class Hotkey : Component { Modified: trunk/ManagedWinapi/SystemWindow.cs =================================================================== --- trunk/ManagedWinapi/SystemWindow.cs 2008-03-04 19:47:03 UTC (rev 61) +++ trunk/ManagedWinapi/SystemWindow.cs 2008-03-25 22:38:59 UTC (rev 62) @@ -680,6 +680,50 @@ } /// <summary> + /// The window's location inside its parent or on the screen. + /// </summary> + public Point Location + { + get + { + return Position.Location; + } + + set + { + WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); + wp.length = Marshal.SizeOf(wp); + GetWindowPlacement(_hwnd, ref wp); + wp.rcNormalPosition.Bottom = value.X + wp.rcNormalPosition.Height; + wp.rcNormalPosition.Right = value.Y + wp.rcNormalPosition.Width; + wp.rcNormalPosition.Top = value.X; + wp.rcNormalPosition.Left = value.Y; + SetWindowPlacement(_hwnd, ref wp); + } + } + + /// <summary> + /// The window's size. + /// </summary> + public Size Size + { + get + { + return Position.Size; + } + + set + { + WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); + wp.length = Marshal.SizeOf(wp); + GetWindowPlacement(_hwnd, ref wp); + wp.rcNormalPosition.Right = wp.rcNormalPosition.Left + value.Width; + wp.rcNormalPosition.Bottom = wp.rcNormalPosition.Top + value.Height; + SetWindowPlacement(_hwnd, ref wp); + } + } + + /// <summary> /// The window's position in absolute screen coordinates. Use /// <see cref="Position"/> if you want to use the relative position. /// </summary> @@ -942,6 +986,25 @@ } } + /// <summary> + /// Whether this SystemWindow represents a valid window that existed + /// when this SystemWindow instance was created. To check if a window + /// still exists, better check its <see cref="ClassName"/> property. + /// </summary> + public bool IsValid() + { + return _hwnd != IntPtr.Zero; + } + + /// <summary> + /// Send a message to this window that it should close. This is equivalent + /// to clicking the "X" in the upper right corner or pressing Alt+F4. + /// </summary> + public void SendClose() + { + SendSetMessage(WM_CLOSE, 0); + } + internal int SendGetMessage(uint message) { return SendGetMessage(message, 0); @@ -1202,6 +1265,8 @@ [DllImport("user32.dll")] static extern IntPtr GetDC(IntPtr hWnd); + private const int WM_CLOSE = 16; + private enum GetWindow_Cmd { GW_HWNDFIRST = 0, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |