OSDN Git Service

リファクタリング master
authoryuuAn <nora@yuuan.net>
Fri, 3 Feb 2017 11:35:13 +0000 (20:35 +0900)
committeryuuAn <nora@yuuan.net>
Fri, 3 Feb 2017 11:35:13 +0000 (20:35 +0900)
* 透過度適用前に現在の透過度を調査
* 必要の無い情報は取得しない

TraPutty/MainForm.cs
TraPutty/Properties/AssemblyInfo.cs
TraPutty/Setting.cs
TraPutty/SettingForm.Designer.cs
TraPutty/SettingForm.cs
TraPutty/TraPutty.csproj
TraPutty/Win32API.cs

index d0bedb9..51a4f7c 100644 (file)
@@ -8,197 +8,128 @@ using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 using System.Diagnostics;
-using System.Xml.Serialization;
-using System.IO;
 
 namespace TraPutty
 {
     public partial class MainForm : Form
     {
-               private class ProcessInfo
-               {
-                       public bool transparent = false;
-                       public IntPtr hWnd = IntPtr.Zero;
-                       public string name;
-                       public string title;
-                       public bool exists = true;
-
-                       public ProcessInfo(IntPtr hWnd, string name, string title) {
-                               this.hWnd = hWnd;
-                               this.name = name;
-                               this.title = title;
-                       }
-
-                       public ProcessInfo(Process process) {
-                               Update(process);
-                       }
-
-                       public void Update(Process process) {
-                               this.hWnd = process.MainWindowHandle;
-                               this.name = process.ProcessName;
-                               this.title = process.MainWindowTitle;
-                               this.exists = true;
-                       }
-               }
-
-               private List<ProcessInfo> processList = new List<ProcessInfo>();
-               private ApplicationSetting setting = new ApplicationSetting();
+        /// <summary>
+        /// 設定
+        /// </summary>
+        private ApplicationSetting settings = new ApplicationSetting();
+
+        /// <summary>
+        /// 設定を変更するためのフォーム
+        /// </summary>
         private SettingForm settingForm = new SettingForm();
 
-               private void SaveSetting() {
-                       try {
-                               XmlSerializer sirializer = new XmlSerializer(typeof(ApplicationSetting));
-                               FileStream stream = new FileStream("TraPutty.xml", FileMode.Create);
-                               sirializer.Serialize(stream, this.setting);
-                               stream.Close();
-                       }
-                       catch { }
-               }
-
-               private void LoadSettings() {
-                       try {
-                               XmlSerializer serializer = new XmlSerializer(typeof(ApplicationSetting));
-                               FileStream stream = new FileStream("TraPutty.xml", FileMode.Open);
-                               this.setting = (ApplicationSetting)serializer.Deserialize(stream);
-                       }
-                       catch {
-                               this.setting = new ApplicationSetting();
-                       }
-               }
-
-               private void ResetProcessesInfo() {
-                       for (int i = 0; i < processList.Count; i++) {
-                               processList[i].exists = false;
-                       }
-
-                       Process[] processes = Process.GetProcesses();
-                       foreach (Process process in processes) {
-                               if (process.MainWindowHandle != IntPtr.Zero) {
-                                       bool ng = false;
-                                       foreach (string ngword in this.setting.ngwords) {
-                                               if (process.ProcessName.Equals(ngword, StringComparison.CurrentCultureIgnoreCase)) ng = true;
-                                       }
-                                       if (!ng) {
-                                               bool exists = false;
-                                               for (int i = 0; i < processList.Count; i++) {
-                                                       ProcessInfo processInfo = processList[i];
-                                                       if (processInfo.hWnd == process.MainWindowHandle) {
-                                                               int exStyle = Win32API.GetWindowLong(processInfo.hWnd, Win32API.GWL_EXSTYLE);
-                                                               if ((exStyle & (int)Win32API.WS_EX.LAYERED) != 0) {
-                                                                       byte alpha;
-                                                                       Win32API.GetLayeredWindowAttributes(processInfo.hWnd, 0, out alpha, 0);
-                                                                       processInfo.transparent = (alpha != 255) ? true : false;
-                                                               }
-                                                               processInfo.Update(process);
-                                                               exists = true;
-                                                               break;
-                                                       }
-                                               }
-                                               if (!exists) {
-                                                       ProcessInfo pi = new ProcessInfo(process);
-                                                       this.processList.Add(pi);
-
-                                                       if (this.setting.puttysAreTransparent) {
-                                                               SetTransparentForPutty(pi, true);
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-
-                       processList.Sort(delegate(ProcessInfo x, ProcessInfo y) {
-                               return x.name.CompareTo(y.name);
-                       });
-
-                       for (int i = 0; i < processList.Count; i++ ) {
-                               if (!processList[i].exists) {
-                                       processList.Remove(processList[i]);
-                               }
-                       }
-               }
-
-               private bool SetTransparent(IntPtr hWnd, bool transparent) {
-                       if (transparent) {
-                               int exStyle = Win32API.GetWindowLong(hWnd, Win32API.GWL_EXSTYLE);
-                               Win32API.SetWindowLong(hWnd, Win32API.GWL_EXSTYLE, exStyle | (int)Win32API.WS_EX.LAYERED);
-
-                               return Win32API.SetLayeredWindowAttributes(hWnd, 0, this.setting.alphaValue, Win32API.LWA_ALPHA);
-                       }
-                       else {
-                               return Win32API.SetLayeredWindowAttributes(hWnd, 0, 255, Win32API.LWA_ALPHA);
-                       }
-               }
+        /// <summary>
+        /// 透過する PuTTY ウィンドウのリスト
+        /// </summary>
+        private WindowList putties = new WindowList();
+
+        /// <summary>
+        /// PuTTY ウィンドウを探してターゲットに追加する
+        /// </summary>
+        private void SearchPutty() {
+            this.putties.RemoveAll(window => window.NotExists);
+
+            foreach (var process in Process.GetProcesses()) {
+                if (Window.IsPuttyProcess(process)) {
+                    this.putties.FindOrCreate(process);
+                }
+            }
+        }
 
-               private void SetTransparentForAllPutty() {
-                       this.setting.puttysAreTransparent = !this.setting.puttysAreTransparent;
-                       foreach (ProcessInfo process in processList) {
-                               this.SetTransparentForPutty(process, this.setting.puttysAreTransparent);
-                       }
-               }
+        /// <summary>
+        /// PuTTY ウィンドウに透過状態を適用する
+        /// </summary>
+        private void TransparentPutty() {
+            foreach (var window in this.putties) {
+                if (! window.IsPuttyConfig || ! this.settings.notTransparentPuttySetting) {
+                    window.Transparency = this.settings.puttysAreTransparent ? Window.NOT_TRANSPARENT : this.settings.alpha;
+                }
+            }
+        }
 
-               private void SetTransparentForPutty(ProcessInfo process, bool transparent) {
-                       if (process.name.Equals("putty", StringComparison.CurrentCultureIgnoreCase)) {
-                               if (this.setting.notTransparentPuttySetting && IsSetting(process))
-                                       transparent = false;
-                               SetTransparent(process.hWnd, transparent);
-                       }
-               }
+        /// <summary>
+        /// PuTTY の透過状態を切り替える
+        /// </summary>
+        private void ToggleTransparencyOfPuttys() {
+                       this.settings.puttysAreTransparent = ! this.settings.puttysAreTransparent;
 
-               private bool IsSetting(ProcessInfo process) {
-                       if (process.title.Equals("PuTTY 設定"))
-                               return true;
-                       if (process.title.Equals("PuTTY Configuration"))
-                               return true;
-                       return false;
+            this.TransparentPutty();
                }
 
+        /// <summary>
+        /// コンストラクタ
+        /// </summary>
                public MainForm() {
                        InitializeComponent();
             this.ShowInTaskbar = false;
             this.WindowState = FormWindowState.Minimized;
                        this.Enabled = false;
 
-            LoadSettings();
-            ResetProcessesInfo();
+            this.settings = ApplicationSetting.Load();
+
+            this.SearchPutty();
 
             timer.Enabled = true;
         }
 
+        /// <summary>
+        /// 起動時
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
                private void MainForm_Load(object sender, EventArgs e) {
             this.Hide();
                }
 
+        /// <summary>
+        /// 終了前
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
                private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
-                       SaveSetting();
+                       this.settings.Save();
                }
 
+        /// <summary>
+        /// タスクトレイからメニューを開いたとき
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
                private void contextMenuStrip_Opening(object sender, CancelEventArgs e) {
                        this.Cursor = Cursors.WaitCursor;
 
             this.TopMost = false;
 
-                       ToolStripSeparator menuSep1 = new ToolStripSeparator();
-                       ToolStripSeparator menuSep2 = new ToolStripSeparator();
-                       ToolStripMenuItem menuOption = new ToolStripMenuItem("設定(&S)...");
+                       var menuSep1 = new ToolStripSeparator();
+                       var menuSep2 = new ToolStripSeparator();
+                       var menuOption = new ToolStripMenuItem("設定(&S)...");
                        menuOption.Click += new EventHandler(this.menuItemOption_Click);
-                       ToolStripMenuItem menuExit = new ToolStripMenuItem("終了(&X)");
+                       var menuExit = new ToolStripMenuItem("終了(&X)");
                        menuExit.Click += new EventHandler(this.menuItemExit_Click);
 
-                       ResetProcessesInfo();
                        contextMenuStrip.Items.Clear();
                        contextMenuStrip.ImageList = this.imageList;
 
-                       foreach (ProcessInfo process in this.processList) {
-                               if (process.exists) {
-                                       ToolStripMenuItem item = new ToolStripMenuItem(process.name);
-                                       item.ToolTipText = process.title;
-                                       item.Tag = process;
-                                       item.ImageIndex = (process.transparent) ? 1 : 0;
-                                       item.Checked = process.transparent;
-                                       item.Text += (process.transparent) ? " *" : "";
-                                       item.Click += new EventHandler(this.menuItemProcess_Click);
-                                       contextMenuStrip.Items.Add(item);
-                               }
+                       foreach (var process in Process.GetProcesses().OrderBy(p => p.ProcessName)) {
+                if (process.MainWindowHandle != IntPtr.Zero) {
+                    if (! this.settings.ngwords.Contains(process.ProcessName)) {
+                        var window = new Window(process);
+
+                        var item = new ToolStripMenuItem(process.ProcessName);
+                        item.ToolTipText = process.MainWindowTitle;
+                        item.Tag = process;
+                        item.ImageIndex = window.IsTransparents ? 1 : 0;
+                        item.Checked = window.IsTransparents;
+                        item.Text += (window.IsTransparents) ? " *" : "";
+                        item.Click += new EventHandler(this.menuItemProcess_Click);
+                        contextMenuStrip.Items.Add(item);
+                    }
+                }
                        }
 
                        contextMenuStrip.Items.Add(menuSep1);
@@ -209,45 +140,84 @@ namespace TraPutty
                        this.Cursor = Cursors.Default;
                }
 
+        /// <summary>
+        /// 設定メニュー
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
                private void menuItemOption_Click(object sender, EventArgs e) {
-            settingForm.SetSetting(this.setting);
+            settingForm.SetSetting(this.settings);
 
             if (settingForm.Visible == false) {
-                DialogResult result = settingForm.ShowDialog(this);
+                var result = settingForm.ShowDialog(this);
                            if (result == DialogResult.OK) {
-                                   this.setting = settingForm.GetSetting();
-                                   SaveSetting();
+                                   this.settings = settingForm.GetSetting();
+                                   this.settings.Save();
                            }
             }
                }
 
+        /// <summary>
+        /// 終了メニュー
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
                private void menuItemExit_Click(object sender, EventArgs e) {
                        notifyIcon.Visible = false;
             Application.Exit();
                }
 
+        /// <summary>
+        /// メニューからプロセスを選択したとき
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
                private void menuItemProcess_Click(object sender, EventArgs e) {
-                       ToolStripMenuItem item = (ToolStripMenuItem)sender;
-                       ProcessInfo processInfo = (ProcessInfo)item.Tag;
+                       var item = (ToolStripMenuItem)sender;
+                       var process = (Process)item.Tag;
+            var window = new Window(process);
 
-                       bool transparent = !processInfo.transparent;
-                       if (SetTransparent(processInfo.hWnd, transparent)) {
-                               processInfo.transparent = transparent;
-                       }
+            if (window.IsTransparents) {
+                window.Transparency = Window.NOT_TRANSPARENT;
+            }
+            else {
+                window.Transparency = this.settings.alpha;
+            }
                }
 
+        /// <summary>
+        /// ただちに PuTTY の透過状態を切り替える
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
                private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e) {
-                       SetTransparentForAllPutty();
+                       this.ToggleTransparencyOfPuttys();
                }
 
+        /// <summary>
+        /// 定期的に
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
                private void timer_Tick(object sender, EventArgs e) {
-                       ResetProcessesInfo();
+            this.SearchPutty();
+            this.TransparentPutty();
                }
 
+        /// <summary>
+        /// メインフォームのラベルをクリックしたら
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
                private void labelTitle_Click(object sender, EventArgs e) {
                        this.Hide();
                }
 
+        /// <summary>
+        /// メインフォームをクリックしたら
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void MainForm_Click(object sender, EventArgs e) {
             this.Hide();
         }
index 2218bf8..e756fbe 100644 (file)
@@ -1,16 +1,17 @@
 using System.Reflection;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
+using System.Resources;
 
 // アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
 // アセンブリに関連付けられている情報を変更するには、
 // これらの属性値を変更してください。
-[assembly: AssemblyTitle("TransparentizeWindow")]
+[assembly: AssemblyTitle("TraPutty")]
 [assembly: AssemblyDescription("")]
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("TransparentizeWindow")]
-[assembly: AssemblyCopyright("Copyright ©  2012")]
+[assembly: AssemblyProduct("TraPutty")]
+[assembly: AssemblyCopyright("yuuAn")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
 
@@ -32,5 +33,6 @@ using System.Runtime.InteropServices;
 // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を 
 // 既定値にすることができます:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("2.0.0.0")]
+[assembly: AssemblyFileVersion("2.0.0.0")]
+[assembly: NeutralResourcesLanguageAttribute("ja")]
index f34f53b..6841e06 100644 (file)
@@ -2,15 +2,45 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using System.IO;
+using System.Xml.Serialization;
 
 namespace TraPutty
 {
        public class ApplicationSetting
        {
-               [System.Xml.Serialization.XmlElement("alpha")]
-               public byte alphaValue = 210;
+               public byte alpha = 210;
                public bool puttysAreTransparent = false;
                public bool notTransparentPuttySetting = false;
-               public string[] ngwords = new string[] { "sidebar", "Saezuri" };
+               public List<string> ngwords;
+
+        /// <summary>
+        /// 設定を読み込む
+        /// </summary>
+        public static ApplicationSetting Load() {
+            try {
+                var serializer = new XmlSerializer(typeof(ApplicationSetting));
+                var stream = new FileStream("TraPutty.xml", FileMode.Open);
+                return (ApplicationSetting)serializer.Deserialize(stream);
+            }
+            catch {
+                var settings = new ApplicationSetting();
+                settings.ngwords = new List<string>() { "sidebar", "Saezuri" };
+                return settings;
+            }
+        }
+
+        /// <summary>
+        /// 設定を保存
+        /// </summary>
+        public void Save() {
+            try {
+                var sirializer = new XmlSerializer(typeof(ApplicationSetting));
+                var stream = new FileStream("TraPutty.xml", FileMode.Create);
+                sirializer.Serialize(stream, this);
+                stream.Close();
+            }
+            catch { }
+        }
        }
 }
index 837beb2..30411c8 100644 (file)
@@ -40,7 +40,7 @@
             // buttonOk
             // 
             this.buttonOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
-            this.buttonOk.Location = new System.Drawing.Point(168, 128);
+            this.buttonOk.Location = new System.Drawing.Point(216, 149);
             this.buttonOk.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
             this.buttonOk.Name = "buttonOk";
             this.buttonOk.Size = new System.Drawing.Size(103, 32);
             // 
             // label1
             // 
-            this.label1.Location = new System.Drawing.Point(8, 24);
+            this.label1.Location = new System.Drawing.Point(18, 40);
+            this.label1.Margin = new System.Windows.Forms.Padding(0);
             this.label1.Name = "label1";
-            this.label1.Size = new System.Drawing.Size(121, 30);
+            this.label1.Size = new System.Drawing.Size(182, 30);
             this.label1.TabIndex = 1;
             this.label1.Text = "透過度 (0-254) : ";
             this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -61,7 +62,7 @@
             // numTransparent
             // 
             this.numTransparent.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.numTransparent.Location = new System.Drawing.Point(295, 24);
+            this.numTransparent.Location = new System.Drawing.Point(343, 40);
             this.numTransparent.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
             this.numTransparent.Maximum = new decimal(new int[] {
             254,
@@ -69,7 +70,7 @@
             0,
             0});
             this.numTransparent.Name = "numTransparent";
-            this.numTransparent.Size = new System.Drawing.Size(65, 25);
+            this.numTransparent.Size = new System.Drawing.Size(65, 30);
             this.numTransparent.TabIndex = 2;
             this.numTransparent.Value = new decimal(new int[] {
             210,
@@ -80,9 +81,9 @@
             // chkNotTransparentPuttySetting
             // 
             this.chkNotTransparentPuttySetting.AutoSize = true;
-            this.chkNotTransparentPuttySetting.Location = new System.Drawing.Point(8, 72);
+            this.chkNotTransparentPuttySetting.Location = new System.Drawing.Point(20, 84);
             this.chkNotTransparentPuttySetting.Name = "chkNotTransparentPuttySetting";
-            this.chkNotTransparentPuttySetting.Size = new System.Drawing.Size(165, 22);
+            this.chkNotTransparentPuttySetting.Size = new System.Drawing.Size(204, 27);
             this.chkNotTransparentPuttySetting.TabIndex = 3;
             this.chkNotTransparentPuttySetting.Text = "PuTTY 設定を透過しない";
             this.chkNotTransparentPuttySetting.UseVisualStyleBackColor = true;
             this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
             this.groupBox1.Name = "groupBox1";
             this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
-            this.groupBox1.Size = new System.Drawing.Size(376, 113);
+            this.groupBox1.Size = new System.Drawing.Size(424, 134);
             this.groupBox1.TabIndex = 6;
             this.groupBox1.TabStop = false;
             this.groupBox1.Text = "設定";
             // 
             this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
             this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
-            this.buttonCancel.Location = new System.Drawing.Point(280, 128);
+            this.buttonCancel.Location = new System.Drawing.Point(328, 149);
             this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
             this.buttonCancel.Name = "buttonCancel";
             this.buttonCancel.Size = new System.Drawing.Size(103, 32);
             // 
             this.linkLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
             this.linkLabel.AutoSize = true;
-            this.linkLabel.Location = new System.Drawing.Point(8, 136);
+            this.linkLabel.Location = new System.Drawing.Point(8, 157);
             this.linkLabel.Name = "linkLabel";
-            this.linkLabel.Size = new System.Drawing.Size(129, 18);
+            this.linkLabel.Size = new System.Drawing.Size(164, 23);
             this.linkLabel.TabIndex = 9;
             this.linkLabel.TabStop = true;
-            this.linkLabel.Text = "© 2012-2014 yuuAn.";
+            this.linkLabel.Text = "© 2012-2017 yuuAn.";
             this.linkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel_LinkClicked);
             // 
             // SettingForm
             // 
             this.AcceptButton = this.buttonOk;
-            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 18F);
+            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 23F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.CancelButton = this.buttonCancel;
-            this.ClientSize = new System.Drawing.Size(394, 172);
+            this.ClientSize = new System.Drawing.Size(442, 193);
             this.Controls.Add(this.linkLabel);
             this.Controls.Add(this.buttonCancel);
             this.Controls.Add(this.groupBox1);
             this.MaximizeBox = false;
             this.MinimizeBox = false;
             this.Name = "SettingForm";
-            this.Text = "とらぷてぃ。 v.1.7";
+            this.Text = "とらぷてぃ。 v.2.0";
             this.Load += new System.EventHandler(this.SettingForm_Load);
             ((System.ComponentModel.ISupportInitialize)(this.numTransparent)).EndInit();
             this.groupBox1.ResumeLayout(false);
index 071acfc..cc5931b 100644 (file)
@@ -32,7 +32,7 @@ namespace TraPutty
                }
 
                private void SettingForm_Load(object sender, EventArgs e) {
-                       this.numTransparent.Value = (int)this.setting.alphaValue;
+                       this.numTransparent.Value = (int)this.setting.alpha;
                        this.chkNotTransparentPuttySetting.Checked = this.setting.notTransparentPuttySetting;
                }
 
@@ -42,7 +42,7 @@ namespace TraPutty
                }
 
                private void buttonOk_Click(object sender, EventArgs e) {
-                       this.setting.alphaValue = (byte)numTransparent.Value;
+                       this.setting.alpha = (byte)numTransparent.Value;
                        this.setting.notTransparentPuttySetting = chkNotTransparentPuttySetting.Checked;
                        this.DialogResult = DialogResult.OK;
                        this.Close();
index c68314c..b389616 100644 (file)
@@ -76,6 +76,7 @@
     </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Window.cs" />
     <EmbeddedResource Include="MainForm.resx">
       <DependentUpon>MainForm.cs</DependentUpon>
     </EmbeddedResource>
index b52a2c6..481f7c0 100644 (file)
@@ -8,14 +8,15 @@ namespace TraPutty
 {
        class Win32API
        {
-               public const int GWL_ID = -12;
-               public const int GWL_STYLE = -16;
-               public const int GWL_EXSTYLE = -20;
-               public const int WS_EX_LAYERED = 0x80000;
-               public const int LWA_ALPHA = 0x2;
-               public const int LWA_COLORKEY = 0x1;
+        [Flags]
+        public enum GWL: int {
+                   ID = -12,
+                   STYLE = -16,
+                   EXSTYLE = -20,
+        }
 
                // Window Styles
+        [Flags]
                public enum WS : uint {
                        OVERLAPPED = 0,
                        POPUP = 0x80000000,
@@ -43,7 +44,8 @@ namespace TraPutty
                }
 
                // Extended Window Styles
-               public enum WS_EX : uint {
+        [Flags]
+               public enum WS_EX : int {
                        DLGMODALFRAME = 0x0001,
                        NOPARENTNOTIFY = 0x0004,
                        TOPMOST = 0x0008,
@@ -72,16 +74,25 @@ namespace TraPutty
                        NOACTIVATE = 0x08000000,
                }
 
-               [DllImport("user32.dll")]
-               public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
+        [Flags]
+        public enum LWA : uint {
+            COLORKEY = 0x1,
+            ALPHA = 0x2,
+        }
 
-               [DllImport("user32.dll")]
-               public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
+        [DllImport("user32.dll")]
+        public static extern bool IsWindow(IntPtr hWnd);
+
+        [DllImport("user32.dll", SetLastError = true)]
+        public static extern int GetWindowLong(IntPtr hWnd, GWL nIndex);
 
                [DllImport("user32.dll")]
-               public static extern bool GetLayeredWindowAttributes(IntPtr hwnd, uint crKey, out byte bAlpha, uint dwFlags);
+               public static extern int SetWindowLong(IntPtr hWnd, GWL nIndex, WS_EX dwNewLong);
 
-               [DllImport("user32.dll", SetLastError = true)]
-               public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
+        [DllImport("user32.dll")]
+        public static extern bool GetLayeredWindowAttributes(IntPtr hwnd, uint crKey, out byte bAlpha, LWA dwFlags);
+
+               [DllImport("user32.dll")]
+               public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, LWA dwFlags);
        }
 }