/// <summary> /// /// </summary> /// <param name="m"></param> protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_DRAWCLIPBOARD: ClipChanged(); CWinApi.SendMessage(nextClipboardViewer, m.Msg, m.WParam, m.LParam); Trace.WriteLine(m.ToString() + nextClipboardViewer.ToString()); break; case WM_CHANGECBCHAIN: if (m.WParam == nextClipboardViewer) { nextClipboardViewer = m.LParam; } else { CWinApi.SendMessage(nextClipboardViewer, m.Msg, m.WParam, m.LParam); } break; default: base.WndProc(ref m); break; } }
/// <summary> /// /// </summary> /// <param name="format"></param> /// <param name="data"></param> private static void ClipboardMonitor_OnClipboardChange(ClipboardFormat format, object data) { Log.Debug("ClipboardMonitor_OnClipboardChange()"); Icon icon = null; int processId; IntPtr clipboardHandle = ClipboardMonitor.GetClipboardOwner(); if (0 < (int)clipboardHandle) { processId = CWinApi.GetProcessIdByHandle(clipboardHandle); if (0 < processId) { try { // 32비트 프로그램에서 64비트 프로그램 프로세스 접근이 안되기 때문에 // 이런식으로 Process의 실행 위치를 가져온다. const string Query = "SELECT ProcessId, ExecutablePath, CommandLine FROM Win32_Process"; var searcher = new ManagementObjectSearcher(Query); foreach (var item in searcher.Get()) { object id = item["ProcessID"]; object path = item["ExecutablePath"]; if (path != null && id.ToString() == processId.ToString()) { icon = Icon.ExtractAssociatedIcon(path.ToString()); break; } } } catch { icon = null; } } } var ms = new MemoryStream(); if (icon != null) { icon.ToBitmap().Save(ms, System.Drawing.Imaging.ImageFormat.Png); } _clipboardEntities.Add( new ClipboardEntity( ms.ToArray(), data, format, DateTime.Now.ToString())); }