private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam) { MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)); LgPoint point = new LgPoint(hookStruct.pt.x, hookStruct.pt.y); Config?.AddWindow(point); Console.WriteLine(hookStruct.pt.x + ", " + hookStruct.pt.y); } return CallNextHookEx(_hookID, nCode, wParam, lParam); }
/// <summary> /// Add new Window to the config from a coordinate in the screen. Usually from a mouse click. /// </summary> /// <param name="point">point in screen</param> /// <returns></returns> internal Boolean AddWindow(LgPoint point) { Boolean result = true; Process p = LgProcessManager.GetProcessAtCoordiante(point); // before adding check if it is current process if (!LgProcessManager.IsCurrentProcess(p)) { LgProcess process = LgProcess.FromProcess(p); LgRectangle rec = LgProcessManager.GetWindowRectange(process); LgWindow window = new LgWindow(rec.GetTopLeft(), rec.GetSize(), process); // add to list Windows.Add(window); Console.WriteLine(window); } else { result = false; } return(result); }
/// <summary> /// Add new Window to the config from a coordinate in the screen. Usually from a mouse click. /// </summary> /// <param name="point">point in screen</param> /// <returns></returns> internal Boolean AddWindow(LgPoint point) { Boolean result = true; Process p = LgProcessManager.GetProcessAtCoordiante(point); // before adding check if it is current process if (!LgProcessManager.IsCurrentProcess(p)) { LgProcess process = LgProcess.FromProcess(p); LgRectangle rec = LgProcessManager.GetWindowRectange(process); LgWindow window = new LgWindow(rec.GetTopLeft(), rec.GetSize(), process); // add to list Windows.Add(window); Console.WriteLine(window); }else { result = false; } return result; }
public LgWindow(LgPoint top, LgSize size, LgProcess process) { TopLeft = top; Size = size; Process = process; }
public LgWindow(LgPoint top, LgPoint bottom, LgProcess process) { TopLeft = top; Process = process; }
/// <summary> /// Get process under mouse cursor /// </summary> /// <returns></returns> public static Process GetProcessAtCoordiante(LgPoint point) { uint pid = 0; POINT ptCursor = new POINT(point.X, point.Y); IntPtr handle = WindowFromPoint(ptCursor); GetWindowThreadProcessId(handle, out pid); return Process.GetProcessById((int)pid); }