public Win32Window() { instance = GetModuleHandle(null); enabled = true; var classStyle = WindowClassStyle.HorizontalRedraw | WindowClassStyle.VerticalRedraw | WindowClassStyle.PrivateDeviceContext; windowCount++; var className = "Window" + windowCount; MainWindowProcedureDelegate = MainWindowProcedure; var info = new WindowClassInfo() { Size = (uint)Marshal.SizeOf <WindowClassInfo>(), Style = classStyle, Procedure = MainWindowProcedureDelegate, Instance = instance, Cursor = LoadCursor(IntPtr.Zero, new IntPtr(32512)), ClassName = className }; var atom = RegisterClass(ref info); if (atom == 0) { throw new MulionException($"Unable to create window class ({GetErrorMessage(GetLastError())})"); } RegenerateStyle(); handle = CreateWindow(0, className, title, windowStyle, DefaultWindowPosition, DefaultWindowPosition, 0, 0, IntPtr.Zero, IntPtr.Zero, instance, IntPtr.Zero); if (handle == IntPtr.Zero) { throw new MulionException($"Unable to create window ({GetErrorMessage(GetLastError())})"); } var topLeft = new WinPoint(); if (!ClientToScreen(handle, ref topLeft)) { throw new MulionException($"Unable to retrieve client are for window ({GetErrorMessage(GetLastError())})"); } var bottomRight = (WinPoint)(Point)Bounds.Size; if (!ClientToScreen(handle, ref bottomRight)) { throw new MulionException($"Unable to retrieve client are for window ({GetErrorMessage(GetLastError())})"); } bounds = new Rectangle((Point)topLeft, (Size)(Point)bottomRight - (Size)(Point)topLeft); }
// // Static methods // #region Static methods // Get current cursor position public static CursorPosition GetCurrentPosition() { var cursor_point = new WinPoint(); if (!CursorWrapper.GetCursorPosition(ref cursor_point)) { return(new CursorPosition()); } else { return(new CursorPosition(cursor_point)); } }
public (bool validateResult, Exception exception) Validate(WinPoint cmd, string team1Id, string team2Id, GameStatus status) { var exceptions = new List <Exception>(); if (status == GameStatus.End) { exceptions.Add(new WinPointException("Game status has been End.", status)); } if (new[] { team1Id, team2Id }.Any(o => o == cmd.TeamId) == false) { exceptions.Add(new WinPointException("The specific team id is not exist.", cmd.TeamId)); } return(exceptions.Count == 0, new AggregateException(exceptions)); }
public void WinPoint(WinPoint cmd) { var(team1Id, team2Id) = GetAllTeamId(); if (new WinPointPolicy().Validate(cmd, team1Id, team2Id, Status) is (bool validateResult, Exception exception) && validateResult == false) { throw exception; } var team = GetTeam(cmd.TeamId, cmd.PlayerId); team.AddPoint(); var(score, status) = new ScoreService().Judge(this); RaiseEvent(new WinPointEvent(cmd.TeamId, cmd.PlayerId, score, status)); Score = score; Status = status; }
static extern IntPtr WindowFromPoint(WinPoint Point);
private static extern IntPtr WindowFromPoint(WinPoint point);
public static extern bool ClientToScreen(IntPtr window, ref WinPoint point);
public static extern bool ScreenToClient(IntPtr window, ref WinPoint point);
// Constructor - From Windows POINT structure public CursorPosition(WinPoint cPoint) { MoveToAbsolute(cPoint.mX, cPoint.mY); }
public static extern IntPtr WindowFromPoint(WinPoint p);
public static extern bool GetCursorPos(out WinPoint Point);