commit 2a9768dd968ae1864ebb3e5a35b7afdec1551fa2 Author: mjjo Date: Sat Jul 5 15:40:21 2014 +0000 diff --git a/Form1.Designer.cs b/Form1.Designer.cs new file mode 100644 index 0000000..f8dcc48 --- /dev/null +++ b/Form1.Designer.cs @@ -0,0 +1,88 @@ +namespace TopMostWinChecker +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if(disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lvList = new System.Windows.Forms.ListView(); + this.window = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.handle = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.time = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.SuspendLayout(); + // + // lvList + // + this.lvList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lvList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.window, + this.handle, + this.time}); + this.lvList.Location = new System.Drawing.Point(12, 12); + this.lvList.Name = "lvList"; + this.lvList.Size = new System.Drawing.Size(380, 238); + this.lvList.TabIndex = 0; + this.lvList.UseCompatibleStateImageBehavior = false; + this.lvList.View = System.Windows.Forms.View.Details; + // + // window + // + this.window.Text = "Window"; + this.window.Width = 190; + // + // handle + // + this.handle.Text = "Handle"; + this.handle.Width = 65; + // + // time + // + this.time.Text = "Time"; + this.time.Width = 121; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(404, 262); + this.Controls.Add(this.lvList); + this.Name = "Form1"; + this.Text = "TopMost Window Checker"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListView lvList; + private System.Windows.Forms.ColumnHeader window; + private System.Windows.Forms.ColumnHeader handle; + private System.Windows.Forms.ColumnHeader time; + } +} + diff --git a/Form1.cs b/Form1.cs new file mode 100644 index 0000000..6617c1c --- /dev/null +++ b/Form1.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Runtime.InteropServices; +using System.IO; + +namespace TopMostWinChecker +{ + public partial class Form1 : Form + { + Timer m_timer; + int m_iHandle=0; + + + + public Form1() + { + InitializeComponent(); + + m_timer = new Timer(); + m_timer.Interval = 100; + m_timer.Tick += new EventHandler(TimerHandler); + m_timer.Start(); + } + + private void TimerHandler(object sender, EventArgs e) + { + int iHandle = GetForegroundWindow(); + + const int nChars = 256; + StringBuilder Buff = new StringBuilder(nChars); + if(GetWindowText(iHandle, Buff, nChars) > 0) + { + if(iHandle != m_iHandle) + { + string strCurTime = System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); + ListViewItem item = new ListViewItem(new string[]{ Buff.ToString(), iHandle.ToString(), strCurTime }); + lvList.Items.Add(item); + + StreamWriter fp = null; + try + { + fp = new StreamWriter("save.txt", true); + fp.WriteLine("[" + strCurTime + "] " + Buff.ToString() + " (" + iHandle.ToString() + ")"); + } + catch + { + MessageBox.Show("file save failed"); + } + finally + { + if(fp != null) + fp.Close(); + } + } + } + + m_iHandle = iHandle; + } + + + [DllImport("user32.dll")] + static extern int GetForegroundWindow(); + + [DllImport("user32.dll")] + static extern int GetWindowText(int hWnd, StringBuilder text, int count); + } +} diff --git a/Form1.resx b/Form1.resx new file mode 100644 index 0000000..29dcb1b --- /dev/null +++ b/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..37612fe --- /dev/null +++ b/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace TopMostWinChecker +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f1a9b2e --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TopMostWinChecker")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TopMostWinChecker")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("3ddcc7e3-0656-4c15-8704-d3a6bab498de")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs new file mode 100644 index 0000000..a226671 --- /dev/null +++ b/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18408 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace TopMostWinChecker.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TopMostWinChecker.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Properties/Resources.resx b/Properties/Resources.resx new file mode 100644 index 0000000..ffecec8 --- /dev/null +++ b/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs new file mode 100644 index 0000000..53b76c5 --- /dev/null +++ b/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18408 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace TopMostWinChecker.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Properties/Settings.settings b/Properties/Settings.settings new file mode 100644 index 0000000..abf36c5 --- /dev/null +++ b/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/TopMostWinChecker.csproj b/TopMostWinChecker.csproj new file mode 100644 index 0000000..a7602a6 --- /dev/null +++ b/TopMostWinChecker.csproj @@ -0,0 +1,87 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {D5D59A8C-0304-4CC3-846B-D107E27ACE3A} + WinExe + Properties + TopMostWinChecker + TopMostWinChecker + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + \ No newline at end of file diff --git a/TopMostWinChecker.sln b/TopMostWinChecker.sln new file mode 100644 index 0000000..96e1c11 --- /dev/null +++ b/TopMostWinChecker.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TopMostWinChecker", "TopMostWinChecker.csproj", "{D5D59A8C-0304-4CC3-846B-D107E27ACE3A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D5D59A8C-0304-4CC3-846B-D107E27ACE3A}.Debug|x86.ActiveCfg = Debug|x86 + {D5D59A8C-0304-4CC3-846B-D107E27ACE3A}.Debug|x86.Build.0 = Debug|x86 + {D5D59A8C-0304-4CC3-846B-D107E27ACE3A}.Release|x86.ActiveCfg = Release|x86 + {D5D59A8C-0304-4CC3-846B-D107E27ACE3A}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal