From 679ebe685d973faf3820c2d90af4312323f143ba Mon Sep 17 00:00:00 2001 From: suwoo Date: Tue, 23 Jul 2019 20:23:54 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=98=EB=B3=B5=20=EB=B0=A9=EB=B2=95=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD,=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KKADBlow.csproj | 20 +++-------- Properties/AssemblyInfo.cs | 8 ++--- Tray.Designer.cs | 12 +++---- Tray.cs | 68 ++++++++++++++++++++++++-------------- 4 files changed, 58 insertions(+), 50 deletions(-) diff --git a/KKADBlow.csproj b/KKADBlow.csproj index e02aa73..9232d0d 100644 --- a/KKADBlow.csproj +++ b/KKADBlow.csproj @@ -60,21 +60,10 @@ LocalIntranet - - true - - - Properties\app.manifest - - - F5845991FAEB79230E4B4BE2E534C33FEBE09AA5 - - - KKADBlow_TemporaryKey.pfx - - - true - + + + + @@ -98,7 +87,6 @@ - diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 5c20f77..46f015d 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -5,12 +5,12 @@ // 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 // 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 // 이러한 특성 값을 변경하세요. -[assembly: AssemblyTitle("kakaoADFinder")] +[assembly: AssemblyTitle("KKADBlow")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("kakaoADFinder")] -[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyCompany("myhome")] +[assembly: AssemblyProduct("KKADBlow")] +[assembly: AssemblyCopyright("Copyright © suwoo 2019")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/Tray.Designer.cs b/Tray.Designer.cs index f4219a7..c2636ee 100644 --- a/Tray.Designer.cs +++ b/Tray.Designer.cs @@ -53,33 +53,33 @@ private void InitializeComponent() this.toolStripMenuItem1, this.종료XToolStripMenuItem}); this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(139, 76); + this.contextMenuStrip1.Size = new System.Drawing.Size(181, 98); // // 자동갱신ToolStripMenuItem // this.자동갱신ToolStripMenuItem.Checked = true; this.자동갱신ToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; this.자동갱신ToolStripMenuItem.Name = "자동갱신ToolStripMenuItem"; - this.자동갱신ToolStripMenuItem.Size = new System.Drawing.Size(138, 22); + this.자동갱신ToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.자동갱신ToolStripMenuItem.Text = "자동 갱신"; - this.자동갱신ToolStripMenuItem.Click += new System.EventHandler(this.자동갱신ToolStripMenuItem_Click); + this.자동갱신ToolStripMenuItem.CheckedChanged += new System.EventHandler(this.자동갱신ToolStripMenuItem_CheckedChanged); // // 광고날리기ToolStripMenuItem // this.광고날리기ToolStripMenuItem.Name = "광고날리기ToolStripMenuItem"; - this.광고날리기ToolStripMenuItem.Size = new System.Drawing.Size(138, 22); + this.광고날리기ToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.광고날리기ToolStripMenuItem.Text = "광고 날리기"; this.광고날리기ToolStripMenuItem.Click += new System.EventHandler(this.광고날리기ToolStripMenuItem_Click); // // toolStripMenuItem1 // this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(135, 6); + this.toolStripMenuItem1.Size = new System.Drawing.Size(177, 6); // // 종료XToolStripMenuItem // this.종료XToolStripMenuItem.Name = "종료XToolStripMenuItem"; - this.종료XToolStripMenuItem.Size = new System.Drawing.Size(138, 22); + this.종료XToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.종료XToolStripMenuItem.Text = "종료(&X)"; this.종료XToolStripMenuItem.Click += new System.EventHandler(this.종료XToolStripMenuItem_Click); // diff --git a/Tray.cs b/Tray.cs index 945aa8e..ecc8686 100644 --- a/Tray.cs +++ b/Tray.cs @@ -12,42 +12,47 @@ namespace KKADBlow { public partial class Tray : Form { + private System.Timers.Timer timer; + int errorcount = 0; + static int ErrorLimit = 5; + IntPtr kakaoMainHandle; + + delegate void TimerInvoker(); + public Tray() { InitializeComponent(); + Init(); + } + + private void Init() + { WindowState = FormWindowState.Minimized; ShowInTaskbar = false; Visible = false; - notifyIcon1.Visible = true; - notifyIcon1.ContextMenuStrip = contextMenuStrip1; - ShowNotify(); - } + timer = new System.Timers.Timer(10000); - private void ShowNotify() - { - if (MessageBox.Show("프로그램이 실행되었습니다. 바로 ㄱㄱ할까요?", "기능 실행", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { + timer.Elapsed += (sender, e) => BeginInvoke(new TimerInvoker(doit)); - 광고날리기ToolStripMenuItem.PerformClick(); - } - MessageBox.Show("트레이에 아이콘을 확인해주세요.", "안내", MessageBoxButtons.OK, MessageBoxIcon.Information); + notifyIcon1.Visible = true; + notifyIcon1.ContextMenuStrip = contextMenuStrip1; + + notifyIcon1.ShowBalloonTip(5000, "실행 확인", "프로그램이 실행되었습니다.", ToolTipIcon.Info); + timer.Start(); } + //ini파일 읽고 쓰기 넣을 예정 //삭제 반복 주기 //hwnd용 클래스 임의로 넣기 - private void 자동갱신ToolStripMenuItem_Click(object sender, EventArgs e) - { - 자동갱신ToolStripMenuItem.Checked = !자동갱신ToolStripMenuItem.Checked; - } private void 종료XToolStripMenuItem_Click(object sender, EventArgs e) { @@ -56,28 +61,39 @@ private void 종료XToolStripMenuItem_Click(object sender, EventArgs e) public void doit() { - IntPtr kakaoMainHandle = FindWindow("EVA_Window_Dblclk", "카카오톡"); if (kakaoMainHandle.Equals(IntPtr.Zero)) { - MessageBox.Show("카톡 프로그램을 찾을 수 없습니다. 작업이 취소됩니다.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; + kakaoMainHandle = FindWindow("EVA_Window_Dblclk", "카카오톡"); + if (kakaoMainHandle.Equals(IntPtr.Zero)) + { + notifyIcon1.ShowBalloonTip(5000, "오류", $"카톡 프로그램을 찾을 수 없습니다. {Environment.NewLine}({errorcount++}번째 시도, {ErrorLimit}회 누적시 종료됨).", ToolTipIcon.Error); + + if (errorcount > ErrorLimit) this.Close(); + return; + } + else + { + notifyIcon1.ShowBalloonTip(5000, "성공", "카톡 창을 찾았습니다. 작업에 들어갑니다!", ToolTipIcon.Info); + errorcount = 0; + } } + IntPtr KakaoAD = FindWindowEx(kakaoMainHandle, IntPtr.Zero, "EVA_Window", null); + if (KakaoAD.Equals(IntPtr.Zero)) + kakaoMainHandle = IntPtr.Zero; + _ = ShowWindow(KakaoAD, ShowWindowCommands.Hide); // W32.EnableWindow(KakaoAD, true); RECT ADrect; + _ = GetWindowRect(KakaoAD, out ADrect); + _ = EnumChildWindows(kakaoMainHandle, EnumWindowsCommand, IntPtr.Zero); + - do - { - _ = GetWindowRect(KakaoAD, out ADrect); - _ = EnumChildWindows(kakaoMainHandle, EnumWindowsCommand, IntPtr.Zero); - } - while (자동갱신ToolStripMenuItem.Checked); bool EnumWindowsCommand(IntPtr hwnd, IntPtr lParam) @@ -116,5 +132,9 @@ private void Worker_DoWork(object sender, DoWorkEventArgs e) doit(); } + private void 자동갱신ToolStripMenuItem_CheckedChanged(object sender, EventArgs e) + { + timer.Enabled = 자동갱신ToolStripMenuItem.Checked; + } } }