Skip to content

Commit

Permalink
로그오프/종료시 자동 저장 안되던 문제 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mijien0179 committed Jun 6, 2022
1 parent 7d1a3b9 commit 75e0ded
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
39 changes: 33 additions & 6 deletions pctory/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ private void InvalidateText()
dataGridView1.Rows.Clear();
dataGridView1.Rows.AddRange(viewInitializer.ProcInfoList2DVGRows(tracer.ProcInfoList));

Application.ApplicationExit += (sender, e) =>
{
closer = true;
tracer.StopTrace();
};


}
public Form1()
{
Expand All @@ -56,13 +53,42 @@ public Form1()
tsmiTracerRun_Click(null, null);
daytrace = new DayTrace(FileAutoOutput_DayChange);

Application.ApplicationExit += new EventHandler((sender, e) =>
{
closer = true;
tracer.StopTrace();
FileAutoOutput_Closing(sender, e);
});

Microsoft.Win32.SystemEvents.SessionEnded += new Microsoft.Win32.SessionEndedEventHandler((sender, e) =>
{
closer = true;
tracer.StopTrace();
FileAutoOutput_Closing(sender, e);
});

Microsoft.Win32.SystemEvents.SessionEnding += new Microsoft.Win32.SessionEndingEventHandler((sender, e) =>
{
closer = true;
tracer.StopTrace();
FileAutoOutput_Closing(sender, e);
});
}

protected override void WndProc(ref Message m)
{
if (WinApi.Message.WM_QUERYENDSESSION == m.Msg)
{
tracer.StopTrace();
FileAutoOutput_Closing(null, null);
}
base.WndProc(ref m);
}


private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (!closer) e.Cancel = true;
else FileAutoOutput_Closing(sender, e);

Hide();
}
Expand Down Expand Up @@ -159,6 +185,7 @@ private void noti_MouseDoubleClick(object sender, MouseEventArgs e)
private void OpenForm()
{
Show();
Activate();
}

private void 열기ToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down
9 changes: 8 additions & 1 deletion pctory/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;

using System.Threading;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Text;

Expand Down Expand Up @@ -45,7 +46,13 @@ static void Main(string[] args)

}else if (args[0] == "--view")
{
Application.Run(new fViewer(null));
if(isFirst) Application.Run(new fViewer(null));
else
{
IntPtr hWnd = WinApi.FindWindow(null, "Log View");
WinApi.SetForegroundWindow(hWnd);
}

}
vMutex.Close();
return;
Expand Down
6 changes: 5 additions & 1 deletion pctory/WinApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ internal class WinApi
{
public static class Message
{
public const uint WM_QUERYENDSESSION = 0x11;
public const uint WM_COPYDATA = 0x4A;

public const uint WM_SETFOCUS = 0x07;
}

public enum EventCode : int
Expand Down Expand Up @@ -121,6 +122,9 @@ public enum SetWinEventHookFlags
[DllImport("user32.dll", SetLastError = false)]
public static extern bool UnhookWinEvent(int hWinEventHook);

[DllImport("user32.dll", SetLastError = false)]
public static extern bool SetForegroundWindow(IntPtr hWnd);

// ref. https://ehdrn.tistory.com/295
public struct COPYDATASTRUCT
{
Expand Down

0 comments on commit 75e0ded

Please sign in to comment.