/// <summary> /// Обычный конструктор /// </summary> public ApplicationMessageBinding(ApplicationMessage message, Keys mainKey, WindowMessage messageType) { Message = message; Title = EnumFriendlyName<ApplicationMessage>.GetString(message); this.mainKey = mainKey; this.messageType = messageType; }
public override void SendWindowMsg(WindowMessage msg, params object[] args) { base.SendWindowMsg(msg, args); switch (msg) { case WindowMessage.eWindow_BeAttacked: //受击者被攻击 BattleRoleItem script = this.BeAttackedRoleGo.GetComponent<BattleRoleItem>(); script.SetBeAttackTargetPos((Vector3)args[0]); script.BeAttackedStart(); break; case WindowMessage.eWindow_BattleStart: SetAttackBothSide((RoleType)args[0]); BattleStart(); break; case WindowMessage.eWindow_CurRoundOver: BeforeNextRound(); if (BattleMgr.Instance.IsBattleOver()) { BattleMgr.Instance.CurBattleStatus = BattleStatus.Invalid; return; } BattleMgr.Instance.bStartRun = true; //本轮攻击结束,开始跑速 break; default: break; } }
internal IntPtr FilterMessage( IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, ref bool handled ) { // It is possible to be re-entered during disposal. Just return. if(null == _source || null == _source.Value) { return IntPtr.Zero; } if (msg == WindowMessage.WM_APPCOMMAND) { // WM_APPCOMMAND message notifies a window that the user generated an application command event, // for example, by clicking an application command button using the mouse or typing an application command // key on the keyboard. RawAppCommandInputReport report = new RawAppCommandInputReport( _source.Value, InputMode.Foreground, SafeNativeMethods.GetMessageTime(), GetAppCommand(lParam), GetDevice(lParam), InputType.Command); handled = _site.Value.ReportInput(report); } return handled ? new IntPtr(1) : IntPtr.Zero ; }
public bool RegisterWindowMessageHandler(WindowMessage callback) { bool result = true; if (null == callback) { throw FxTrace.Exception.AsError(new ArgumentNullException("callback")); } //if there are no other callbacks registered - create initial multicast delegate //and hookup message processing if (null == this.listeners) { this.listeners = (WindowMessage)Delegate.Combine(callback); this.HookupMessageProcessing(); } //otherwise, check if callback is not in the list already else { Delegate[] initial = this.listeners.GetInvocationList(); //if it isn't - add it to callback list if (-1 == Array.IndexOf<Delegate>(initial, callback)) { Delegate[] combined = new Delegate[initial.Length + 1]; combined[initial.Length] = callback; Array.Copy(initial, combined, initial.Length); this.listeners = (WindowMessage)Delegate.Combine(combined); } else { result = false; } } return result; }
protected override bool DialogProc(IntPtr hwndDlg, WindowMessage uMsg, IntPtr wParam, IntPtr lParam) { switch (uMsg) { case WindowMessage.InitDialog: { Rect initialSize = new Rect { Left = 0, Top = 0, Right = 260, Bottom = 260 }; Win32.MapDialogRect(hwndDlg, ref initialSize); this.Size = new System.Drawing.Size(initialSize.Right, initialSize.Bottom); this.Refresh(); } break; } return base.DialogProc(hwndDlg, uMsg, wParam, lParam); }
public void Initialize() { var window = new WindowMessage(Text); ManagerWindow.NewWindow("gameEventMessage",window); ManagerInput.ThrottleInput = true; Done = false; }
internal KeyboardKeyAction GetKeyboardKeyAction(WindowMessage message) { KeyboardKeyAction action; if (!_mappings.WindowMessageToKeyboardKeyAction.TryGetValue(message, out action)) { action = KeyboardKeyAction.None; } return action; }
public void SendWindowMsg(WindowID targetWindow, WindowMessage msg, params object[] args) { if (!AllWindowScript.ContainsKey(targetWindow)) { return; } if (!AllWindowScript[targetWindow]) { return; } AllWindowScript[targetWindow].SendWindowMsg(msg, args); }
public static Boolean ScrollToBottom(IntPtr Handle, Boolean Blocking) { WindowMessage Message = new WindowMessage(); Message.Handle = Handle; Message.InVal = KEYWORDS.WM_VSCROLL; Message.PtrLparam = new IntPtr(0); Message.PtrWparam = KEYWORDS.SB_BOTTOM; if (Blocking) { return System.Boolean.Equals(true, SendWindowMessage(Message)); } else { ParameterizedThreadStart pts = new ParameterizedThreadStart(SendWindowMessage); Thread t = new Thread(pts); t.Start(Message); return false; } }
protected override unsafe bool DialogProc(IntPtr hwndDlg, WindowMessage uMsg, IntPtr wParam, IntPtr lParam) { switch (uMsg) { case WindowMessage.InitDialog: { Rect initialSize; initialSize.left = 0; initialSize.top = 0; initialSize.right = 260; initialSize.bottom = 260; NativeApi.MapDialogRect(hwndDlg, ref initialSize); this.Size = new System.Drawing.Size(initialSize.right, initialSize.bottom); } break; case WindowMessage.ShowWindow: if (!_layoutInitialized) { void* dialogItem = NativeApi.PhAddPropPageLayoutItem( hwndDlg, hwndDlg, (void*)0x1, // PH_PROP_PAGE_TAB_CONTROL_PARENT 0xf // PH_ANCHOR_ALL ); // Resize our .NET-based control automatically as well. NativeApi.PhAddPropPageLayoutItem( hwndDlg, this.Handle, dialogItem, 0xf // PH_ANCHOR_ALL ); NativeApi.PhDoPropPageLayout(hwndDlg); _layoutInitialized = true; } break; } return base.DialogProc(hwndDlg, uMsg, wParam, lParam); }
protected abstract IntPtr WindowProcedure( IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam);
public static void RunWindowProc(WindowCore coreWindow, ref WindowMessage msg) { msg.SetResult(coreWindow.WindowProc(msg.Hwnd, (uint)msg.Id, msg.WParam, msg.LParam)); }
public static extern bool PeekMessage(out WindowMessage message, IntPtr hwnd, uint messageFilterMin, uint messageFilterMax, uint flags);
protected override IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { switch (message) { #region mouse case WindowMessage.MOUSEMOVE: { if (!_mouseTracking) { var tme = new TrackMouseEvent(TrackMouseEventFlags.TME_LEAVE, Handle); if (Functions.TrackMouseEvent(ref tme)) { _mouseTracking = true; } } } break; case WindowMessage.MOUSEACTIVATE: System.Diagnostics.Debug.WriteLine("MOUSEACTIVATE."); break; case WindowMessage.MOUSELEAVE: _mouseTracking = false; System.Diagnostics.Debug.WriteLine("MOUSELEAVE."); break; case WindowMessage.LBUTTONDOWN: //HasKeyboardFocus = true; System.Diagnostics.Debug.WriteLine("LBUTTONDOWN."); break; #endregion #region keyBoard case WindowMessage.KEYDOWN: case WindowMessage.SYSKEYDOWN: System.Diagnostics.Debug.WriteLine("KEYDOWN."); OnKeyDown(VirtualKeyToKeyTranslator.Translate((VirtualKey)wParam.ToInt32())); break; case WindowMessage.KEYUP: case WindowMessage.SYSKEYUP: System.Diagnostics.Debug.WriteLine("KEYUP."); OnKeyUp(VirtualKeyToKeyTranslator.Translate((VirtualKey)wParam.ToInt32())); break; #endregion case WindowMessage.SETFOCUS: System.Diagnostics.Debug.WriteLine("SETFOCUS."); break; case WindowMessage.KILLFOCUS: System.Diagnostics.Debug.WriteLine("KILLFOCUS."); break; case WindowMessage.ACTIVATE: System.Diagnostics.Debug.WriteLine("ACTIVATE."); break; case WindowMessage.ERASEBKGND: return(IntPtr.Zero); break; case WindowMessage.PAINT: Draw(); break; case WindowMessage.WINDOWPOSCHANGING: break; case WindowMessage.CLOSE: Functions.DestroyWindow(Handle); break; case WindowMessage.DESTROY: Functions.PostQuitMessage(0); break; } return(Functions.DefWindowProc(handle, message, wParam, lParam)); }
protected override IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { switch (message) { case WindowMessage.INPUT: int Size = 0; Functions.GetRawInputData(lParam, GetRawInputDataEnum.INPUT, IntPtr.Zero, out Size, API.RawInputHeaderSize); if (Size == Functions.GetRawInputData(lParam, GetRawInputDataEnum.INPUT, out WinRawInput.data, out Size, API.RawInputHeaderSize)) { switch (WinRawInput.data.Header.Type) { case RawInputDeviceType.MOUSE: if (((WinRawMouse) this.MouseDriver).ProcessMouseEvent(WinRawInput.data)) return IntPtr.Zero; else break; case RawInputDeviceType.KEYBOARD: if (((WinRawKeyboard) this.KeyboardDriver).ProcessKeyboardEvent(WinRawInput.data)) return IntPtr.Zero; else break; } } else break; case WindowMessage.DEVICECHANGE: ((WinRawKeyboard) this.KeyboardDriver).RefreshDevices(); ((WinRawMouse) this.MouseDriver).RefreshDevices(); break; } return base.WindowProcedure(handle, message, wParam, lParam); }
void HandleCreate(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { CreateStruct cs = (CreateStruct)Marshal.PtrToStructure(lParam, typeof(CreateStruct)); if (cs.hwndParent == IntPtr.Zero) { bounds.X = cs.x; bounds.Y = cs.y; bounds.Width = cs.cx; bounds.Height = cs.cy; Win32Rectangle rect; Functions.GetClientRect(handle, out rect); client_rectangle = rect.ToRectangle(); invisible_since_creation = true; } }
public static extern IntPtr SendMessage( IntPtr windowHandle, WindowMessage message, IntPtr wparam, IntPtr lparam);
public static extern void PostMessage( IntPtr windowHandle, WindowMessage message, IntPtr wparam, IntPtr lparam);
static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam) { switch (message) { case WindowMessage.InputLanguageChange: dwCharSet = (CharacterSet)(uint)wParam; goto case WindowMessage.Create; case WindowMessage.Create: using (DeviceContext dc = window.GetDeviceContext()) { using (FontHandle font = Windows.CreateFont(0, 0, 0, 0, FontWeight.DoNotCare, false, false, false, dwCharSet, OutputPrecision.Default, ClippingPrecision.Default, Quality.Default, FontPitch.FixedPitch, FontFamily.DoNotCare, null)) { dc.SelectObject(font); dc.GetTextMetrics(out TEXTMETRIC tm); cxChar = tm.tmAveCharWidth; cyChar = tm.tmHeight; dc.SelectObject(StockFont.System); } } goto CalculateSize; case WindowMessage.Size: cxClient = lParam.LowWord; cyClient = lParam.HighWord; CalculateSize: // calculate window size in characters cxBuffer = Math.Max(1, cxClient / cxChar); cyBuffer = Math.Max(1, cyClient / cyChar); // allocate memory for buffer and clear it pBuffer = new char[cxBuffer, cyBuffer]; // set caret to upper left corner xCaret = 0; yCaret = 0; if (window == Windows.GetFocus()) { Windows.SetCaretPosition(xCaret * cxChar, yCaret * cyChar); } window.Invalidate(true); return(0); case WindowMessage.SetFocus: // create and show the caret window.CreateCaret(null, cxChar, cyChar); Windows.SetCaretPosition(xCaret * cxChar, yCaret * cyChar); window.ShowCaret(); return(0); case WindowMessage.KillFocus: // hide and destroy the caret window.HideCaret(); Windows.DestroyCaret(); return(0); case WindowMessage.KeyDown: switch ((VirtualKey)wParam) { case VirtualKey.Home: xCaret = 0; break; case VirtualKey.End: xCaret = cxBuffer - 1; break; case VirtualKey.Prior: yCaret = 0; break; case VirtualKey.Next: yCaret = cyBuffer - 1; break; case VirtualKey.Left: xCaret = Math.Max(xCaret - 1, 0); break; case VirtualKey.Right: xCaret = Math.Min(xCaret + 1, cxBuffer - 1); break; case VirtualKey.Up: yCaret = Math.Max(yCaret - 1, 0); break; case VirtualKey.Down: yCaret = Math.Min(yCaret + 1, cyBuffer - 1); break; case VirtualKey.Delete: for (int x = xCaret; x < cxBuffer - 1; x++) { pBuffer[x, yCaret] = pBuffer[x + 1, yCaret]; } pBuffer[cxBuffer - 1, yCaret] = ' '; window.HideCaret(); using (DeviceContext dc = window.GetDeviceContext()) { using (FontHandle font = Windows.CreateFont(0, 0, 0, 0, FontWeight.DoNotCare, false, false, false, dwCharSet, OutputPrecision.Default, ClippingPrecision.Default, Quality.Default, FontPitch.FixedPitch, FontFamily.DoNotCare, null)) { dc.SelectObject(font); unsafe { fixed(char *c = &pBuffer[xCaret, yCaret]) dc.TextOut(xCaret * cxChar, yCaret * cyChar, c, cxBuffer - xCaret); } dc.SelectObject(StockFont.System); } window.ShowCaret(); } break; } Windows.SetCaretPosition(xCaret * cxChar, yCaret * cyChar); return(0); case WindowMessage.Char: for (int i = 0; i < lParam.LowWord; i++) { switch ((char)wParam) { case '\b': // backspace if (xCaret > 0) { xCaret--; window.SendMessage(WindowMessage.KeyDown, (uint)VirtualKey.Delete, 1); } break; case '\t': // tab do { window.SendMessage(WindowMessage.Char, ' ', 1); } while (xCaret % 8 != 0); break; case '\n': // line feed if (++yCaret == cyBuffer) { yCaret = 0; } break; case '\r': // carriage return xCaret = 0; if (++yCaret == cyBuffer) { yCaret = 0; } break; case '\x1B': // escape for (int y = 0; y < cyBuffer; y++) { for (int x = 0; x < cxBuffer; x++) { pBuffer[x, y] = ' '; } } xCaret = 0; yCaret = 0; window.Invalidate(false); break; default: // character codes pBuffer[xCaret, yCaret] = (char)wParam; window.HideCaret(); using (DeviceContext dc = window.GetDeviceContext()) { using (FontHandle font = Windows.CreateFont(0, 0, 0, 0, FontWeight.DoNotCare, false, false, false, dwCharSet, OutputPrecision.Default, ClippingPrecision.Default, Quality.Default, FontPitch.FixedPitch, FontFamily.DoNotCare, null)) { dc.SelectObject(font); unsafe { fixed(char *c = &pBuffer[xCaret, yCaret]) dc.TextOut(xCaret * cxChar, yCaret * cyChar, c, 1); } dc.SelectObject(StockFont.System); } window.ShowCaret(); } if (++xCaret == cxBuffer) { xCaret = 0; if (++yCaret == cyBuffer) { yCaret = 0; } } break; } } Windows.SetCaretPosition(xCaret * cxChar, yCaret * cyChar); return(0); case WindowMessage.Paint: using (DeviceContext dc = window.BeginPaint()) { using (FontHandle font = Windows.CreateFont(0, 0, 0, 0, FontWeight.DoNotCare, false, false, false, dwCharSet, OutputPrecision.Default, ClippingPrecision.Default, Quality.Default, FontPitch.FixedPitch, FontFamily.DoNotCare, null)) { dc.SelectObject(font); unsafe { for (int y = 0; y < cyBuffer; y++) fixed(char *c = &pBuffer[0, y]) dc.TextOut(0, y * cyChar, c, cxBuffer); } dc.SelectObject(StockFont.System); } } return(0); case WindowMessage.Destroy: Windows.PostQuitMessage(0); return(0); } return(Windows.DefaultWindowProcedure(window, message, wParam, lParam)); }
public static extern IntPtr DefWindowProcW( IntPtr hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam);
public static extern bool PostMessage(HandleRef hwnd, WindowMessage msg, IntPtr wparam, IntPtr lparam);
public static extern IntPtr SendMessage(HandleRef hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam);
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, WindowMessage msg, UIntPtr wParam, IntPtr lParam, SendMessageTimeoutFlags fuFlags, uint uTimeout, out UIntPtr lpdwResult);
/// <summary> /// This is the WNDPROC that gets inserted into the window's /// WNDPROC chain. It responds to various conditions that /// would cause this HwndSubclass object to unsubclass the window, /// and then calls the delegate specified to the HwndSubclass /// constructor to process the message. If the delegate does not /// handle the message, the message is then passed on down the /// WNDPROC chain for further processing. /// </summary> /// <param name="hwnd"> /// The window that this message was sent or posted to. /// </param> /// <param name="msg"> /// The message that was sent or posted. /// </param> /// <param name="wParam"> /// A parameter for the message that was sent or posted. /// </param> /// <param name="lParam"> /// A parameter for the message that was sent or posted. /// </param> /// <returns> /// The value that is the result of processing the message. /// </returns> internal IntPtr SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) { IntPtr retval = IntPtr.Zero; bool handled = false; WindowMessage message = (WindowMessage)msg; // If we are unattached and we receive a message, then we must have // been used as the original window proc. In this case, we insert // ourselves as if the original window proc had been DefWindowProc. // We pass in DefWndProcStub as a workaround for a bug in UxTheme on // Windows XP. For details see the comment on the DefWndProcWrapper method. if (_bond == Bond.Unattached) { HookWindowProc(hwnd, new NativeMethods.WndProc(SubclassWndProc), Marshal.GetFunctionPointerForDelegate(DefWndProcStub)); } else if (_bond == Bond.Detached) { throw new InvalidOperationException(); } IntPtr oldWndProc = _oldWndProc; // in case we get detached during this method if (message == DetachMessage) { // We received our special message to detach. Make sure it is intended // for us by matching the bridge. if (wParam == IntPtr.Zero || wParam == (IntPtr)_gcHandle) { int param = (int)lParam; // 0 - normal, 1 - force, 2 - force and forward bool force = (param > 0); retval = CriticalDetach(force) ? new IntPtr(1) : IntPtr.Zero; handled = (param < 2); } } else { // Pass this message to our delegate function. Do this under // the exception filter/handlers of the dispatcher for this thread. Dispatcher dispatcher = Dispatcher.FromThread(Thread.CurrentThread); if (dispatcher != null && !dispatcher.HasShutdownFinished) { if (_dispatcherOperationCallback == null) { _dispatcherOperationCallback = new DispatcherOperationCallback(this.DispatcherCallbackOperation); } // _paramDispatcherCallbackOperation is a thread static member which should be reused to avoid // creating a new data structure every time we call DispatcherCallbackOperation // Cache the param locally in case of reentrance and set _paramDispatcherCallbackOperation to null so reentrancy calls will create a new param if (_paramDispatcherCallbackOperation == null) { _paramDispatcherCallbackOperation = new DispatcherOperationCallbackParameter(); } DispatcherOperationCallbackParameter param = _paramDispatcherCallbackOperation; _paramDispatcherCallbackOperation = null; param.hwnd = hwnd; param.msg = msg; param.wParam = wParam; param.lParam = lParam; //synchronous call object result = dispatcher.Invoke( DispatcherPriority.Send, _dispatcherOperationCallback, param); if (result != null) { handled = param.handled; retval = param.retVal; } // Restore _paramDispatcherCallbackOperation to the previous value so we will reuse it on the next call _paramDispatcherCallbackOperation = param; } // Handle WM_NCDESTROY explicitly to forcibly clean up. if (message == WindowMessage.WM_NCDESTROY) { // The fact that we received this message means that we are // still in the call chain. This is our last chance to clean // up, and no other message should be received by this window // proc again. It is OK to force a cleanup now. CriticalDetach(true); // Always pass the WM_NCDESTROY message down the chain! handled = false; } } // If our window proc didn't handle this message, pass it on down the // chain. if (!handled) { retval = CallOldWindowProc(oldWndProc, hwnd, message, wParam, lParam); } return(retval); }
void HandleKeyboard(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { bool pressed = message == WindowMessage.KEYDOWN || message == WindowMessage.SYSKEYDOWN; // Shift/Control/Alt behave strangely when e.g. ShiftRight is held down and ShiftLeft is pressed // and released. It looks like neither key is released in this case, or that the wrong key is // released in the case of Control and Alt. // To combat this, we are going to release both keys when either is released. Hacky, but should work. // Win95 does not distinguish left/right key constants (GetAsyncKeyState returns 0). // In this case, both keys will be reported as pressed. bool extended = (lParam.ToInt64() & ExtendedBit) != 0; short scancode = (short)((lParam.ToInt64() >> 16) & 0xFF); VirtualKeys vkey = (VirtualKeys)wParam; bool is_valid; Key key = KeyMap.TranslateKey(scancode, vkey, extended, false, out is_valid); if (is_valid) { keyboard.SetKey(key, (byte)scancode, pressed); if (pressed) { key_down.Key = key; key_down.Modifiers = keyboard.GetModifiers(); KeyDown(this, key_down); } else { key_up.Key = key; key_up.Modifiers = keyboard.GetModifiers(); KeyUp(this, key_up); } } }
/// <summary> /// This method lets the user call the old WNDPROC, i.e /// the next WNDPROC in the chain directly. /// </summary> /// <param name="oldWndProc"> /// The WndProc to call. /// </param> /// <param name="hwnd"> /// The window that this message was sent or posted to. /// </param> /// <param name="msg"> /// The message that was sent or posted. /// </param> /// <param name="wParam"> /// A parameter for the message that was sent or posted. /// </param> /// <param name="lParam"> /// A parameter for the message that was sent or posted. /// </param> /// <returns> /// The value that is the result of processing the message. /// </returns> IntPtr CallOldWindowProc(IntPtr oldWndProc, IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam) { return(UnsafeNativeMethods.CallWindowProc(oldWndProc, hwnd, (int)msg, wParam, lParam)); }
void HandleDestroy(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { exists = false; if (handle == window.Handle) { Functions.UnregisterClass(ClassName, Instance); } window.Dispose(); child_window.Dispose(); Closed(this, EventArgs.Empty); }
protected virtual IntPtr WindowProcedure( IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { return(Unhandled); }
/// <summary> /// Filters out a mouse message before it is dispatched /// </summary> /// <param name="target">The Control that will receive the message</param> /// <param name="msg">A WindowMessage that represents the message to process</param> /// <param name="wParam">Specifies the WParam field of the message</param> /// <param name="lParam">Specifies the LParam field of the message</param> /// <returns>true to filter the message and prevent it from being dispatched; /// false to allow the message to continue to the next filter or control</returns> public override bool ProcessMouseMessage(Control target, WindowMessage msg, int wParam, int lParam) { if (this.DroppedDown) { if (msg == WindowMessage.WM_LBUTTONDOWN || msg == WindowMessage.WM_RBUTTONDOWN || msg == WindowMessage.WM_MBUTTONDOWN || msg == WindowMessage.WM_XBUTTONDOWN || msg == WindowMessage.WM_NCLBUTTONDOWN || msg == WindowMessage.WM_NCRBUTTONDOWN || msg == WindowMessage.WM_NCMBUTTONDOWN || msg == WindowMessage.WM_NCXBUTTONDOWN) { Point cursorPos = Cursor.Position; if (!this.DropDown.Bounds.Contains(cursorPos)) { if (target != this.EditingTable && target != this.TextBox) { if (this.ShouldStopEditing(target, cursorPos)) { this.EditingTable.StopEditing(); } } } } else if (msg == WindowMessage.WM_MOUSEMOVE) { Point cursorPos = Cursor.Position; if (this.DropDown.Bounds.Contains(cursorPos)) { if (!this.containsMouse) { this.containsMouse = true; this.EditingTable.RaiseCellMouseLeave(this.EditingCellPos); } } else { this.containsMouse = true; } } } return false; }
void HandleStyleChanged(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { WindowBorder old_border = windowBorder; WindowBorder new_border = old_border; unsafe { GWL get_window_style = (GWL)unchecked(wParam.ToInt32()); if ((get_window_style & (GWL.STYLE | GWL.EXSTYLE)) != 0) { WindowStyle style = ((StyleStruct*)lParam)->New; if ((style & WindowStyle.Popup) != 0) new_border = WindowBorder.Hidden; else if ((style & WindowStyle.ThickFrame) != 0) new_border = WindowBorder.Resizable; else if ((style & ~(WindowStyle.ThickFrame | WindowStyle.MaximizeBox)) != 0) new_border = WindowBorder.Fixed; } } if (new_border != windowBorder) { // Ensure cursor remains grabbed if (!CursorVisible) GrabCursor(); windowBorder = new_border; WindowBorderChanged(this, EventArgs.Empty); } }
static unsafe LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam) { switch (message) { case WindowMessage.Create: baseUnits = Windows.GetDialogBaseUnits(); btnWidth = baseUnits.cx * 8; btnHeight = baseUnits.cy * 4; // Create the owner-draw pushbuttons CREATESTRUCT *create = (CREATESTRUCT *)lParam; hwndSmaller = Windows.CreateWindow("button", "", WindowStyles.Child | WindowStyles.Visible | (WindowStyles)ButtonStyles.OwnerDrawn, ExtendedWindowStyles.None, 0, 0, btnWidth, btnHeight, window, (IntPtr)ID_SMALLER, create->Instance, IntPtr.Zero); hwndLarger = Windows.CreateWindow("button", "", WindowStyles.Child | WindowStyles.Visible | (WindowStyles)ButtonStyles.OwnerDrawn, ExtendedWindowStyles.None, 0, 0, btnWidth, btnHeight, window, (IntPtr)ID_LARGER, create->Instance, IntPtr.Zero); return(0); case WindowMessage.Size: cxClient = lParam.LowWord; cyClient = lParam.HighWord; // Move the buttons to the new center hwndSmaller.MoveWindow(cxClient / 2 - 3 * btnWidth / 2, cyClient / 2 - btnHeight / 2, btnWidth, btnHeight, true); hwndLarger.MoveWindow(cxClient / 2 + btnWidth / 2, cyClient / 2 - btnHeight / 2, btnWidth, btnHeight, true); return(0); case WindowMessage.Command: RECT rc = window.GetWindowRectangle(); // Make the window 10% smaller or larger switch ((int)(uint)wParam) { case ID_SMALLER: rc.left += cxClient / 20; rc.right -= cxClient / 20; rc.top += cyClient / 20; rc.bottom -= cyClient / 20; break; case ID_LARGER: rc.left -= cxClient / 20; rc.right += cxClient / 20; rc.top -= cyClient / 20; rc.bottom += cyClient / 20; break; } window.MoveWindow(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, true); return(0); case WindowMessage.DrawItem: DRAWITEMSTRUCT *pdis = (DRAWITEMSTRUCT *)lParam; // Fill area with white and frame it black using (DeviceContext dc = pdis->DeviceContext) { RECT rect = pdis->rcItem; dc.FillRectangle(rect, StockBrush.White); dc.FrameRectangle(rect, StockBrush.Black); // Draw inward and outward black triangles int cx = rect.right - rect.left; int cy = rect.bottom - rect.top; POINT[] pt = new POINT[3]; switch ((int)pdis->CtlID) { case ID_SMALLER: pt[0].x = 3 * cx / 8; pt[0].y = 1 * cy / 8; pt[1].x = 5 * cx / 8; pt[1].y = 1 * cy / 8; pt[2].x = 4 * cx / 8; pt[2].y = 3 * cy / 8; Triangle(dc, pt); pt[0].x = 7 * cx / 8; pt[0].y = 3 * cy / 8; pt[1].x = 7 * cx / 8; pt[1].y = 5 * cy / 8; pt[2].x = 5 * cx / 8; pt[2].y = 4 * cy / 8; Triangle(dc, pt); pt[0].x = 5 * cx / 8; pt[0].y = 7 * cy / 8; pt[1].x = 3 * cx / 8; pt[1].y = 7 * cy / 8; pt[2].x = 4 * cx / 8; pt[2].y = 5 * cy / 8; Triangle(dc, pt); pt[0].x = 1 * cx / 8; pt[0].y = 5 * cy / 8; pt[1].x = 1 * cx / 8; pt[1].y = 3 * cy / 8; pt[2].x = 3 * cx / 8; pt[2].y = 4 * cy / 8; Triangle(dc, pt); break; case ID_LARGER: pt[0].x = 5 * cx / 8; pt[0].y = 3 * cy / 8; pt[1].x = 3 * cx / 8; pt[1].y = 3 * cy / 8; pt[2].x = 4 * cx / 8; pt[2].y = 1 * cy / 8; Triangle(dc, pt); pt[0].x = 5 * cx / 8; pt[0].y = 5 * cy / 8; pt[1].x = 5 * cx / 8; pt[1].y = 3 * cy / 8; pt[2].x = 7 * cx / 8; pt[2].y = 4 * cy / 8; Triangle(dc, pt); pt[0].x = 3 * cx / 8; pt[0].y = 5 * cy / 8; pt[1].x = 5 * cx / 8; pt[1].y = 5 * cy / 8; pt[2].x = 4 * cx / 8; pt[2].y = 7 * cy / 8; Triangle(dc, pt); pt[0].x = 3 * cx / 8; pt[0].y = 3 * cy / 8; pt[1].x = 3 * cx / 8; pt[1].y = 5 * cy / 8; pt[2].x = 1 * cx / 8; pt[2].y = 4 * cy / 8; Triangle(dc, pt); break; } // Invert the rectangle if the button is selected if ((pdis->itemState & OwnerDrawStates.Selected) != 0) { dc.InvertRectangle(rect); } if ((pdis->itemState & OwnerDrawStates.Focus) != 0) { rect.left += cx / 16; rect.top += cy / 16; rect.right -= cx / 16; rect.bottom -= cy / 16; dc.DrawFocusRectangle(rect); } } return(0); case WindowMessage.Destroy: Windows.PostQuitMessage(0); return(0); } return(Windows.DefaultWindowProcedure(window, message, wParam, lParam)); }
void HandleChar(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { char c; if (IntPtr.Size == 4) c = (char)wParam.ToInt32(); else c = (char)wParam.ToInt64(); if (!Char.IsControl(c)) { key_press.KeyChar = c; KeyPress(this, key_press); } }
public static bool RunDwmDefWindowProc(ref WindowMessage msg) { return(DwmApiMethods.DwmDefWindowProc(msg.Hwnd, (uint)msg.Id, msg.WParam, msg.LParam, out msg.Result)); }
void HandleMouseLeave(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { mouse_outside_window = true; // Mouse tracking is disabled automatically by the OS MouseLeave(this, EventArgs.Empty); }
IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { Point point; switch (message) { #region Size / Move / Style events case WindowMessage.ACTIVATE: // See http://msdn.microsoft.com/en-us/library/ms646274(VS.85).aspx (WM_ACTIVATE notification): // wParam: The low-order word specifies whether the window is being activated or deactivated. bool new_focused_state = Focused; if (IntPtr.Size == 4) { focused = (wParam.ToInt32() & 0xFFFF) != 0; } else { focused = (wParam.ToInt64() & 0xFFFF) != 0; } if (new_focused_state != Focused) { FocusedChanged(this, EventArgs.Empty); } break; case WindowMessage.ENTERMENULOOP: case WindowMessage.ENTERSIZEMOVE: // Entering the modal size/move loop: we don't want rendering to // stop during this time, so we register a timer callback to continue // processing from time to time. StartTimer(handle); break; case WindowMessage.EXITMENULOOP: case WindowMessage.EXITSIZEMOVE: // ExitingmModal size/move loop: the timer callback is no longer // necessary. StopTimer(handle); break; case WindowMessage.ERASEBKGND: return(new IntPtr(1)); case WindowMessage.WINDOWPOSCHANGED: unsafe { WindowPosition *pos = (WindowPosition *)lParam; if (window != null && pos->hwnd == window.WindowHandle) { Point new_location = new Point(pos->x, pos->y); if (Location != new_location) { bounds.Location = new_location; Move(this, EventArgs.Empty); } Size new_size = new Size(pos->cx, pos->cy); if (Size != new_size) { bounds.Width = pos->cx; bounds.Height = pos->cy; Win32Rectangle rect; Functions.GetClientRect(handle, out rect); client_rectangle = rect.ToRectangle(); Functions.SetWindowPos(child_window.WindowHandle, IntPtr.Zero, 0, 0, ClientRectangle.Width, ClientRectangle.Height, SetWindowPosFlags.NOZORDER | SetWindowPosFlags.NOOWNERZORDER | SetWindowPosFlags.NOACTIVATE | SetWindowPosFlags.NOSENDCHANGING); if (suppress_resize <= 0) { Resize(this, EventArgs.Empty); } } } } break; case WindowMessage.STYLECHANGED: unsafe { if (wParam.ToInt64() == (long)GWL.STYLE) { WindowStyle style = ((StyleStruct *)lParam)->New; if ((style & WindowStyle.Popup) != 0) { windowBorder = WindowBorder.Hidden; } else if ((style & WindowStyle.ThickFrame) != 0) { windowBorder = WindowBorder.Resizable; } else if ((style & ~(WindowStyle.ThickFrame | WindowStyle.MaximizeBox)) != 0) { windowBorder = WindowBorder.Fixed; } } } break; case WindowMessage.SIZE: SizeMessage state = (SizeMessage)wParam.ToInt64(); WindowState new_state = windowState; switch (state) { case SizeMessage.RESTORED: new_state = borderless_maximized_window_state ? WindowState.Maximized : WindowState.Normal; break; case SizeMessage.MINIMIZED: new_state = WindowState.Minimized; break; case SizeMessage.MAXIMIZED: new_state = WindowBorder == WindowBorder.Hidden ? WindowState.Fullscreen : WindowState.Maximized; break; } if (new_state != windowState) { windowState = new_state; WindowStateChanged(this, EventArgs.Empty); } break; #endregion #region Input events case WindowMessage.CHAR: if (IntPtr.Size == 4) { key_press.KeyChar = (char)wParam.ToInt32(); } else { key_press.KeyChar = (char)wParam.ToInt64(); } KeyPress(this, key_press); break; case WindowMessage.MOUSEMOVE: point = new Point( (short)((uint)lParam.ToInt32() & 0x0000FFFF), (short)(((uint)lParam.ToInt32() & 0xFFFF0000) >> 16)); mouse.Position = point; if (mouse_outside_window) { // Once we receive a mouse move event, it means that the mouse has // re-entered the window. mouse_outside_window = false; EnableMouseTracking(); } if (this.client_rectangle.Contains(lastCursorPos) && !this.client_rectangle.Contains(point)) { if (!CursorVisible) { ShowCursor(); } mouse.NotifyLeave(); MouseLeave(this, EventArgs.Empty); } if (!this.client_rectangle.Contains(lastCursorPos) && this.client_rectangle.Contains(point)) { if (!CursorVisible) { HideCursor(); } mouse.NotifyEnter(); MouseEnter(this, EventArgs.Empty); } lastCursorPos = point; break; case WindowMessage.MOUSELEAVE: mouse_outside_window = true; // Mouse tracking is disabled automatically by the OS Functions.GetCursorPos(out point); point = this.PointToClient(point); if (this.client_rectangle.Contains(lastCursorPos) && !this.client_rectangle.Contains(point)) { if (!CursorVisible) { ShowCursor(); } mouse.NotifyLeave(); MouseLeave(this, EventArgs.Empty); } lastCursorPos = point; break; case WindowMessage.MOUSEWHEEL: // This is due to inconsistent behavior of the WParam value on 64bit arch, whese // wparam = 0xffffffffff880000 or wparam = 0x00000000ff100000 mouse.WheelPrecise += ((long)wParam << 32 >> 48) / 120.0f; break; case WindowMessage.LBUTTONDOWN: Functions.SetCapture(window.WindowHandle); mouse[MouseButton.Left] = true; break; case WindowMessage.MBUTTONDOWN: Functions.SetCapture(window.WindowHandle); mouse[MouseButton.Middle] = true; break; case WindowMessage.RBUTTONDOWN: Functions.SetCapture(window.WindowHandle); mouse[MouseButton.Right] = true; break; case WindowMessage.XBUTTONDOWN: Functions.SetCapture(window.WindowHandle); mouse[((wParam.ToInt32() & 0xFFFF0000) >> 16) != (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = true; break; case WindowMessage.LBUTTONUP: Functions.ReleaseCapture(); mouse[MouseButton.Left] = false; break; case WindowMessage.MBUTTONUP: Functions.ReleaseCapture(); mouse[MouseButton.Middle] = false; break; case WindowMessage.RBUTTONUP: Functions.ReleaseCapture(); mouse[MouseButton.Right] = false; break; case WindowMessage.XBUTTONUP: Functions.ReleaseCapture(); mouse[((wParam.ToInt32() & 0xFFFF0000) >> 16) != (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = false; break; // Keyboard events: case WindowMessage.KEYDOWN: case WindowMessage.KEYUP: case WindowMessage.SYSKEYDOWN: case WindowMessage.SYSKEYUP: bool pressed = message == WindowMessage.KEYDOWN || message == WindowMessage.SYSKEYDOWN; // Shift/Control/Alt behave strangely when e.g. ShiftRight is held down and ShiftLeft is pressed // and released. It looks like neither key is released in this case, or that the wrong key is // released in the case of Control and Alt. // To combat this, we are going to release both keys when either is released. Hacky, but should work. // Win95 does not distinguish left/right key constants (GetAsyncKeyState returns 0). // In this case, both keys will be reported as pressed. bool extended = (lParam.ToInt64() & ExtendedBit) != 0; switch ((VirtualKeys)wParam) { case VirtualKeys.SHIFT: // The behavior of this key is very strange. Unlike Control and Alt, there is no extended bit // to distinguish between left and right keys. Moreover, pressing both keys and releasing one // may result in both keys being held down (but not always). // The only reliable way to solve this was reported by BlueMonkMN at the forums: we should // check the scancodes. It looks like GLFW does the same thing, so it should be reliable. // Note: we release both keys when either shift is released. // Otherwise, the state of one key might be stuck to pressed. if (ShiftRightScanCode != 0 && pressed) { unchecked { if (((lParam.ToInt64() >> 16) & 0xFF) == ShiftRightScanCode) { keyboard[Input.Key.ShiftRight] = pressed; } else { keyboard[Input.Key.ShiftLeft] = pressed; } } } else { // Windows 9x and NT4.0 or key release event. keyboard[Input.Key.ShiftLeft] = keyboard[Input.Key.ShiftRight] = pressed; } return(IntPtr.Zero); case VirtualKeys.CONTROL: if (extended) { keyboard[Input.Key.ControlRight] = pressed; } else { keyboard[Input.Key.ControlLeft] = pressed; } return(IntPtr.Zero); case VirtualKeys.MENU: if (extended) { keyboard[Input.Key.AltRight] = pressed; } else { keyboard[Input.Key.AltLeft] = pressed; } return(IntPtr.Zero); case VirtualKeys.RETURN: if (extended) { keyboard[Key.KeypadEnter] = pressed; } else { keyboard[Key.Enter] = pressed; } return(IntPtr.Zero); default: if (!KeyMap.ContainsKey((VirtualKeys)wParam)) { Debug.Print("Virtual key {0} ({1}) not mapped.", (VirtualKeys)wParam, (long)lParam); break; } else { keyboard[KeyMap[(VirtualKeys)wParam]] = pressed; } return(IntPtr.Zero); } break; case WindowMessage.SYSCHAR: return(IntPtr.Zero); case WindowMessage.KILLFOCUS: keyboard.ClearKeys(); keyboard.NotifyLostFocus(); break; case WindowMessage.SETFOCUS: keyboard.NotifyGotFocus(); break; #endregion #region Creation / Destruction events case WindowMessage.CREATE: CreateStruct cs = (CreateStruct)Marshal.PtrToStructure(lParam, typeof(CreateStruct)); if (cs.hwndParent == IntPtr.Zero) { bounds.X = cs.x; bounds.Y = cs.y; bounds.Width = cs.cx; bounds.Height = cs.cy; Win32Rectangle rect; Functions.GetClientRect(handle, out rect); client_rectangle = rect.ToRectangle(); invisible_since_creation = true; } break; case WindowMessage.CLOSE: System.ComponentModel.CancelEventArgs e = new System.ComponentModel.CancelEventArgs(); Closing(this, e); if (!e.Cancel) { DestroyWindow(); break; } return(IntPtr.Zero); case WindowMessage.DESTROY: exists = false; Functions.UnregisterClass(ClassName, Instance); window.Dispose(); child_window.Dispose(); Closed(this, EventArgs.Empty); break; #endregion } return(Functions.DefWindowProc(handle, message, wParam, lParam)); }
void HandleRButtonDown(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { Functions.SetCapture(window.Handle); mouse[MouseButton.Right] = true; }
internal abstract void HandleMessage(WindowMessage msg, IntPtr wParam, IntPtr lParam);
void HandleRButtonUp(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { Functions.ReleaseCapture(); mouse[MouseButton.Right] = false; }
public bool PostMessage(WindowMessage message, int wParam, int lParam) { return(Win32.PostMessage(this, message, wParam, lParam)); }
unsafe IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { switch (message) { #region Size / Move / Style events case WindowMessage.ACTIVATE: // See http://msdn.microsoft.com/en-us/library/ms646274(VS.85).aspx (WM_ACTIVATE notification): // wParam: The low-order word specifies whether the window is being activated or deactivated. bool new_focused_state = Focused; focused = (wParam.ToInt64() & 0xFFFF) != 0; if (new_focused_state != Focused && FocusedChanged != null) { FocusedChanged(this, EventArgs.Empty); } break; case WindowMessage.ENTERMENULOOP: case WindowMessage.ENTERSIZEMOVE: case WindowMessage.EXITMENULOOP: case WindowMessage.EXITSIZEMOVE: break; case WindowMessage.ERASEBKGND: return(new IntPtr(1)); case WindowMessage.WINDOWPOSCHANGED: WindowPosition *pos = (WindowPosition *)lParam; if (window != null && pos->hwnd == window.handle) { Point new_location = new Point(pos->x, pos->y); if (Location != new_location) { bounds.Location = new_location; if (Move != null) { Move(this, EventArgs.Empty); } } Size new_size = new Size(pos->cx, pos->cy); if (Size != new_size) { bounds.Width = pos->cx; bounds.Height = pos->cy; Win32Rectangle rect; API.GetClientRect(handle, out rect); client_rectangle = rect.ToRectangle(); API.SetWindowPos(window.handle, IntPtr.Zero, bounds.X, bounds.Y, bounds.Width, bounds.Height, SetWindowPosFlags.NOZORDER | SetWindowPosFlags.NOOWNERZORDER | SetWindowPosFlags.NOACTIVATE | SetWindowPosFlags.NOSENDCHANGING); if (suppress_resize <= 0 && Resize != null) { Resize(this, EventArgs.Empty); } } } break; case WindowMessage.STYLECHANGED: if (wParam.ToInt64() == (long)GWL.STYLE) { WindowStyle style = ((StyleStruct *)lParam)->New; if ((style & WindowStyle.Popup) != 0) { hiddenBorder = true; } else if ((style & WindowStyle.ThickFrame) != 0) { hiddenBorder = false; } } break; case WindowMessage.SIZE: SizeMessage state = (SizeMessage)wParam.ToInt64(); WindowState new_state = windowState; switch (state) { case SizeMessage.RESTORED: new_state = WindowState.Normal; break; case SizeMessage.MINIMIZED: new_state = WindowState.Minimized; break; case SizeMessage.MAXIMIZED: new_state = hiddenBorder ? WindowState.Fullscreen : WindowState.Maximized; break; } if (new_state != windowState) { windowState = new_state; if (WindowStateChanged != null) { WindowStateChanged(this, EventArgs.Empty); } } break; #endregion #region Input events case WindowMessage.CHAR: key_press.KeyChar = (char)wParam.ToInt64(); if (KeyPress != null) { KeyPress(this, key_press); } break; case WindowMessage.MOUSEMOVE: Point point = new Point( (short)((uint)lParam.ToInt32() & 0x0000FFFF), (short)(((uint)lParam.ToInt32() & 0xFFFF0000) >> 16)); mouse.Position = point; if (mouse_outside_window) { // Once we receive a mouse move event, it means that the mouse has // re-entered the window. mouse_outside_window = false; EnableMouseTracking(); if (MouseEnter != null) { MouseEnter(this, EventArgs.Empty); } } break; case WindowMessage.MOUSELEAVE: mouse_outside_window = true; // Mouse tracking is disabled automatically by the OS if (MouseLeave != null) { MouseLeave(this, EventArgs.Empty); } // Set all mouse buttons to off when user leaves window, prevents them being stuck down. for (MouseButton btn = 0; btn < MouseButton.LastButton; btn++) { mouse[btn] = false; } break; case WindowMessage.MOUSEWHEEL: // This is due to inconsistent behavior of the WParam value on 64bit arch, whese // wparam = 0xffffffffff880000 or wparam = 0x00000000ff100000 mouse.Wheel += ((long)wParam << 32 >> 48) / 120.0f; return(IntPtr.Zero); case WindowMessage.LBUTTONDOWN: mouse[MouseButton.Left] = true; break; case WindowMessage.MBUTTONDOWN: mouse[MouseButton.Middle] = true; break; case WindowMessage.RBUTTONDOWN: mouse[MouseButton.Right] = true; break; case WindowMessage.XBUTTONDOWN: keyboard[(((ulong)wParam.ToInt64() >> 16) & 0xFFFF) == 1 ? Key.XButton1 : Key.XButton2] = true; break; case WindowMessage.LBUTTONUP: mouse[MouseButton.Left] = false; break; case WindowMessage.MBUTTONUP: mouse[MouseButton.Middle] = false; break; case WindowMessage.RBUTTONUP: mouse[MouseButton.Right] = false; break; case WindowMessage.XBUTTONUP: keyboard[(((ulong)wParam.ToInt64() >> 16) & 0xFFFF) == 1 ? Key.XButton1 : Key.XButton2] = false; break; // Keyboard events: case WindowMessage.KEYDOWN: case WindowMessage.KEYUP: case WindowMessage.SYSKEYDOWN: case WindowMessage.SYSKEYUP: bool pressed = message == WindowMessage.KEYDOWN || message == WindowMessage.SYSKEYDOWN; // Shift/Control/Alt behave strangely when e.g. ShiftRight is held down and ShiftLeft is pressed // and released. It looks like neither key is released in this case, or that the wrong key is // released in the case of Control and Alt. // To combat this, we are going to release both keys when either is released. Hacky, but should work. // Win95 does not distinguish left/right key constants (GetAsyncKeyState returns 0). // In this case, both keys will be reported as pressed. bool extended = (lParam.ToInt64() & ExtendedBit) != 0; switch ((VirtualKeys)wParam) { case VirtualKeys.SHIFT: // The behavior of this key is very strange. Unlike Control and Alt, there is no extended bit // to distinguish between left and right keys. Moreover, pressing both keys and releasing one // may result in both keys being held down (but not always). bool lShiftDown = (API.GetKeyState((int)VirtualKeys.LSHIFT) >> 15) == 1; bool rShiftDown = (API.GetKeyState((int)VirtualKeys.RSHIFT) >> 15) == 1; if (!pressed || lShiftDown != rShiftDown) { Keyboard[Input.Key.ShiftLeft] = lShiftDown; Keyboard[Input.Key.ShiftRight] = rShiftDown; } return(IntPtr.Zero); case VirtualKeys.CONTROL: if (extended) { keyboard[Input.Key.ControlRight] = pressed; } else { keyboard[Input.Key.ControlLeft] = pressed; } return(IntPtr.Zero); case VirtualKeys.MENU: if (extended) { keyboard[Input.Key.AltRight] = pressed; } else { keyboard[Input.Key.AltLeft] = pressed; } return(IntPtr.Zero); case VirtualKeys.RETURN: if (extended) { keyboard[Key.KeypadEnter] = pressed; } else { keyboard[Key.Enter] = pressed; } return(IntPtr.Zero); default: Key tkKey; if (!KeyMap.TryGetMappedKey((VirtualKeys)wParam, out tkKey)) { Debug.Print("Virtual key {0} ({1}) not mapped.", (VirtualKeys)wParam, lParam.ToInt64()); break; } else { keyboard[tkKey] = pressed; } return(IntPtr.Zero); } break; case WindowMessage.SYSCHAR: return(IntPtr.Zero); case WindowMessage.KILLFOCUS: keyboard.ClearKeys(); break; #endregion #region Creation / Destruction events case WindowMessage.CREATE: CreateStruct cs = (CreateStruct)Marshal.PtrToStructure(lParam, typeof(CreateStruct)); if (cs.hwndParent == IntPtr.Zero) { bounds.X = cs.x; bounds.Y = cs.y; bounds.Width = cs.cx; bounds.Height = cs.cy; Win32Rectangle rect; API.GetClientRect(handle, out rect); client_rectangle = rect.ToRectangle(); invisible_since_creation = true; } break; case WindowMessage.CLOSE: System.ComponentModel.CancelEventArgs e = new System.ComponentModel.CancelEventArgs(); if (Closing != null) { Closing(this, e); } if (!e.Cancel) { DestroyWindow(); break; } return(IntPtr.Zero); case WindowMessage.DESTROY: exists = false; API.UnregisterClass(ClassName, Instance); window.Dispose(); if (Closed != null) { Closed(this, EventArgs.Empty); } break; #endregion } return(API.DefWindowProc(handle, message, wParam, lParam)); }
void HandleSize(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { SizeMessage state = (SizeMessage)wParam.ToInt64(); WindowState new_state = windowState; switch (state) { case SizeMessage.RESTORED: new_state = borderless_maximized_window_state ? WindowState.Maximized : WindowState.Normal; break; case SizeMessage.MINIMIZED: new_state = WindowState.Minimized; break; case SizeMessage.MAXIMIZED: new_state = WindowBorder == WindowBorder.Hidden ? WindowState.Fullscreen : WindowState.Maximized; break; } if (new_state != windowState) { windowState = new_state; WindowStateChanged(this, EventArgs.Empty); // Ensure cursor remains grabbed if (!CursorVisible) GrabCursor(); } }
public IntPtr SendMessage(WindowMessage message, IntPtr wParam, IntPtr lParam) { return(Win32.SendMessage(this, message, wParam, lParam)); }
void HandleMouseMove(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { Point point = new Point( (short)((uint)lParam.ToInt32() & 0x0000FFFF), (short)(((uint)lParam.ToInt32() & 0xFFFF0000) >> 16)); mouse.Position = point; if (mouse_outside_window) { // Once we receive a mouse move event, it means that the mouse has // re-entered the window. mouse_outside_window = false; EnableMouseTracking(); MouseEnter(this, EventArgs.Empty); } }
public IntPtr SendMessageTimeout(WindowMessage message, int wParam, int lParam, SmtoFlags flags, int timeout, out int result) { return(Win32.SendMessageTimeout(this, message, wParam, lParam, flags, timeout, out result)); }
void HandleMouseWheel(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { // This is due to inconsistent behavior of the WParam value on 64bit arch, whese // wparam = 0xffffffffff880000 or wparam = 0x00000000ff100000 mouse.WheelPrecise += ((long)wParam << 32 >> 48) / 120.0f; }
protected abstract void ProcessRawInput(WindowMessage msg, IntPtr lParam);
void HandleXButtonDown(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { Functions.SetCapture(window.Handle); mouse[((wParam.ToInt32() & 0xFFFF0000) >> 16) == 1 ? MouseButton.Button1 : MouseButton.Button2] = true; }
public static extern IntPtr SendMessage(IntPtr windowHandle, WindowMessage wm, IntPtr wParam, StringBuilder lParam);
void HandleXButtonUp(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { Functions.ReleaseCapture(); mouse[((wParam.ToInt32() & 0xFFFF0000) >> 16) == 1 ? MouseButton.Button1 : MouseButton.Button2] = false; }
protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam) { switch (message) { case MessageType.Create: _chunk = _sb.GetChunk(); goto case MessageType.DisplayChange; case MessageType.DisplayChange: // Get maximum size of client area cyClientMax = Windows.GetSystemMetrics(SystemMetric.MaximizedHeight); // Get character size for fixed-pitch font using (DeviceContext dc = window.GetDeviceContext()) { dc.SelectObject(StockFont.SystemFixed); dc.GetTextMetrics(out TextMetrics tm); cyChar = tm.Height; } cLinesMax = cyClientMax / cyChar; pmsg = new WindowMessage[cLinesMax]; cLines = 0; goto CalculateScroll; case MessageType.Size: cxClient = lParam.LowWord; cyClient = lParam.HighWord; CalculateScroll: rectScroll = Rectangle.FromLTRB(0, cyChar, cxClient, cyChar * (cyClient / cyChar)); window.Invalidate(true); return(0); case MessageType.KeyDown: case MessageType.KeyUp: case MessageType.Char: case MessageType.DeadChar: case MessageType.SystemKeyDown: case MessageType.SystemKeyUp: case MessageType.SystemChar: case MessageType.SystemDeadChar: // Rearrange storage array for (int i = cLinesMax - 1; i > 0; i--) { pmsg[i] = pmsg[i - 1]; } // Store new message pmsg[0] = new WindowMessage(window, message, wParam, lParam); cLines = Math.Min(cLines + 1, cLinesMax); // Scroll up the display window.ScrollWindow(new Point(0, -cyChar), rectScroll, rectScroll); break; // i.e., call DefWindowProc so Sys messages work case MessageType.Paint: using (DeviceContext dc = window.BeginPaint()) { dc.SelectObject(StockFont.SystemFixed); dc.SetBackgroundMode(BackgroundMode.Transparent); dc.TextOut(default, "Message Key Char Repeat Scan Ext ALT Prev Tran".AsSpan()); dc.TextOut(default, "_______ ___ ____ ______ ____ ___ ___ ____ ____".AsSpan()); for (int i = 0; i < Math.Min(cLines, cyClient / cyChar - 1); i++) { bool iType; switch (pmsg[i].Type) { case MessageType.Char: case MessageType.SystemChar: case MessageType.DeadChar: case MessageType.SystemDeadChar: iType = true; break; default: iType = false; break; } _sb.Clear(); _sb.AppendFormat(iType ? "{0,-13} {1,3} {2,15} {3,6} {4,4} {5,3} {6,3} {7,4} {8,4}" : "{0,-13} {1,3} {2,-15} {3,6} {4,4} {5,3} {6,3} {7,4} {8,4} VirtualKey: {9}", pmsg[i].Type, pmsg[i].wParam.ToString(), iType ? $"0x{((uint)pmsg[i].wParam):X4} {(char)(uint)pmsg[i].wParam}" : Windows.GetKeyNameText(pmsg[i].lParam), pmsg[i].lParam.LowWord, pmsg[i].lParam.HighWord & 0xFF, (0x01000000 & pmsg[i].lParam) != 0 ? "Yes" : "No", (0x20000000 & pmsg[i].lParam) != 0 ? "Yes" : "No", (0x40000000 & pmsg[i].lParam) != 0 ? "Down" : "Up", (0x80000000 & pmsg[i].lParam) != 0 ? "Up" : "Down", (VirtualKey)pmsg[i].wParam); dc.TextOut(new Point(0, (cyClient / cyChar - 1 - i) * cyChar), _chunk.Span.Slice(0, _sb.Length)); } } return(0); }
void HandleKillFocus(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { keyboard.ClearKeys(); }
public static extern bool PostMessage(IntPtr hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam);
void HandleClose(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { System.ComponentModel.CancelEventArgs e = new System.ComponentModel.CancelEventArgs(); Closing(this, e); if (!e.Cancel) { DestroyWindow(); } }
public static extern IntPtr SendMessageW( IntPtr hWnd, WindowMessage Msg, IntPtr wParam, IntPtr lParam);
IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { switch (message) { #region Size / Move / Style events case WindowMessage.ACTIVATE: HandleActivate(handle, message, wParam, lParam); break; case WindowMessage.ENTERMENULOOP: case WindowMessage.ENTERSIZEMOVE: HandleEnterModalLoop(handle, message, wParam, lParam); break; case WindowMessage.EXITMENULOOP: case WindowMessage.EXITSIZEMOVE: HandleExitModalLoop(handle, message, wParam, lParam); break; case WindowMessage.ERASEBKGND: return new IntPtr(1); case WindowMessage.WINDOWPOSCHANGED: HandleWindowPositionChanged(handle, message, wParam, lParam); break; case WindowMessage.STYLECHANGED: HandleStyleChanged(handle, message, wParam, lParam); break; case WindowMessage.SIZE: HandleSize(handle, message, wParam, lParam); break; #endregion #region Input events case WindowMessage.CHAR: HandleChar(handle, message, wParam, lParam); break; case WindowMessage.MOUSEMOVE: HandleMouseMove(handle, message, wParam, lParam); break; case WindowMessage.MOUSELEAVE: HandleMouseLeave(handle, message, wParam, lParam); break; case WindowMessage.MOUSEWHEEL: HandleMouseWheel(handle, message, wParam, lParam); break; case WindowMessage.LBUTTONDOWN: HandleLButtonDown(handle, message, wParam, lParam); break; case WindowMessage.MBUTTONDOWN: HandleMButtonDown(handle, message, wParam, lParam); break; case WindowMessage.RBUTTONDOWN: HandleRButtonDown(handle, message, wParam, lParam); break; case WindowMessage.XBUTTONDOWN: HandleXButtonDown(handle, message, wParam, lParam); break; case WindowMessage.LBUTTONUP: HandleLButtonUp(handle, message, wParam, lParam); break; case WindowMessage.MBUTTONUP: HandleMButtonUp(handle, message, wParam, lParam); break; case WindowMessage.RBUTTONUP: HandleRButtonUp(handle, message, wParam, lParam); break; case WindowMessage.XBUTTONUP: HandleXButtonUp(handle, message, wParam, lParam); break; // Keyboard events: case WindowMessage.KEYDOWN: case WindowMessage.KEYUP: case WindowMessage.SYSKEYDOWN: case WindowMessage.SYSKEYUP: HandleKeyboard(handle, message, wParam, lParam); return IntPtr.Zero; case WindowMessage.SYSCHAR: return IntPtr.Zero; case WindowMessage.KILLFOCUS: HandleKillFocus(handle, message, wParam, lParam); break; #endregion #region Creation / Destruction events case WindowMessage.CREATE: HandleCreate(handle, message, wParam, lParam); break; case WindowMessage.CLOSE: HandleClose(handle, message, wParam, lParam); return IntPtr.Zero; case WindowMessage.DESTROY: HandleDestroy(handle, message, wParam, lParam); break; #endregion } return Functions.DefWindowProc(handle, message, wParam, lParam); }
static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam) { switch (message) { case WindowMessage.Size: int cxClient = lParam.LowWord; int cyClient = lParam.HighWord; apt[0].x = cxClient / 4; apt[0].y = cyClient / 2; apt[1].x = cxClient / 2; apt[1].y = cyClient / 4; apt[2].x = cxClient / 2; apt[2].y = 3 * cyClient / 4; apt[3].x = 3 * cxClient / 4; apt[3].y = cyClient / 2; return(0); case WindowMessage.LeftButtonDown: case WindowMessage.RightButtonDown: case WindowMessage.MouseMove: MouseKey mk = (MouseKey)wParam.LowWord; if ((mk & (MouseKey.LeftButton | MouseKey.RightButton)) != 0) { using (DeviceContext dc = window.GetDeviceContext()) { dc.SelectObject(StockPen.White); DrawBezier(dc, apt); if ((mk & MouseKey.LeftButton) != 0) { apt[1].x = lParam.LowWord; apt[1].y = lParam.HighWord; } if ((mk & MouseKey.RightButton) != 0) { apt[2].x = lParam.LowWord; apt[2].y = lParam.HighWord; } dc.SelectObject(StockPen.Black); DrawBezier(dc, apt); } } return(0); case WindowMessage.Paint: window.Invalidate(true); using (DeviceContext dc = window.BeginPaint()) { DrawBezier(dc, apt); } return(0); case WindowMessage.Destroy: WindowMethods.PostQuitMessage(0); return(0); } return(WindowMethods.DefaultWindowProcedure(window, message, wParam, lParam)); }
private static extern IntPtr SendMessage(IntPtr hWnd, WindowMessage Msg, uint wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
public static extern IntPtr DefSubclassProc(IntPtr hWnd, WindowMessage uMsg, IntPtr wParam, IntPtr lParam);
/// <summary> /// Filters out a key message before it is dispatched /// </summary> /// <param name="target">The Control that will receive the message</param> /// <param name="msg">A WindowMessage that represents the message to process</param> /// <param name="wParam">Specifies the WParam field of the message</param> /// <param name="lParam">Specifies the LParam field of the message</param> /// <returns>true to filter the message and prevent it from being dispatched; /// false to allow the message to continue to the next filter or control</returns> public override bool ProcessKeyMessage(Control target, WindowMessage msg, int wParam, int lParam) { if (msg == WindowMessage.WM_KEYDOWN) { if (((Keys) wParam) == Keys.F4) { if (this.TextBox.Focused || this.DropDown.ContainsFocus) { this.DroppedDown = !this.DroppedDown; return true; } } } return false; }
/// <summary> /// Filters out a key message before it is dispatched /// </summary> /// <param name="target">The Control that will receive the message</param> /// <param name="msg">A WindowMessage that represents the message to process</param> /// <param name="wParam">Specifies the WParam field of the message</param> /// <param name="lParam">Specifies the LParam field of the message</param> /// <returns>true to filter the message and prevent it from being dispatched; /// false to allow the message to continue to the next filter or control</returns> public virtual bool ProcessKeyMessage(Control target, WindowMessage msg, int wParam, int lParam) { return(false); }