/// <summary> /// handle vertical scroll /// </summary> /// <param name="m"></param> private void OnVScroll(ref Message m) { int newValue = Int32.MinValue; NativeScroll.SCROLLINFO sc = ScrollInfo(NativeScroll.SB_VERT); int value = sc.nPos; int nScrollCode = NativeWindowCommon.LoWord((int)m.WParam); switch (nScrollCode) { case NativeScroll.SB_TOP: newValue = 0; break; case NativeScroll.SB_BOTTOM: newValue = sc.nMax; break; case NativeScroll.SB_LINEUP: newValue = value - 1; break; case NativeScroll.SB_LINEDOWN: newValue = value + 1; break; case NativeScroll.SB_PAGEUP: newValue = value - sc.nPage; break; case NativeScroll.SB_PAGEDOWN: newValue = value + sc.nPage; break; case NativeScroll.SB_THUMBPOSITION: EndThumbDrag(); break; case NativeScroll.SB_THUMBTRACK: StartThumbDrag(); newValue = GetThumbTrackVal(sc.nTrackPos); value = GetPrevScrollVal(sc.nPos); break; } if (newValue != Int32.MinValue && newValue != value) { ScrollVertically((ScrollEventType)m.WParam, newValue, value, true); } }
protected override void WndProc(ref Message m) { switch (m.Msg) { case 0x114: case 0x115: base.BehaviorService.Invalidate(base.BehaviorService.ControlRectInAdornerWindow(this.Control)); base.WndProc(ref m); return; case 0x84: base.WndProc(ref m); if (((int)((long)m.Result)) != -1) { break; } m.Result = (IntPtr)1; return; case 0x7b: { int x = NativeWindowCommon.LoWord((int)((long)m.LParam)); int y = NativeWindowCommon.HiWord((int)((long)m.LParam)); if ((x == -1) && (y == -1)) { Point position = Cursor.Position; x = position.X; y = position.Y; } this.OnContextMenu(x, y); return; } default: base.WndProc(ref m); break; } }
protected int WndProc(ref Message m) #endif { MouseEventArgs mouseEvents; switch (m.Msg) { #if !PocketPC case NativeWindowCommon.CBN_DROPDOWN: { if (OriginalDropDownWindowProc == IntPtr.Zero) { NativeWindowCommon.COMBOBOXINFO comboBoxInfo = new NativeWindowCommon.COMBOBOXINFO(); // alloc ptrComboBoxInfo IntPtr ptrComboBoxInfo = Marshal.AllocHGlobal(Marshal.SizeOf(comboBoxInfo)); try { //get combo Box Info comboBoxInfo.cbSize = (IntPtr)Marshal.SizeOf(comboBoxInfo); Marshal.StructureToPtr(comboBoxInfo, ptrComboBoxInfo, true); IntPtr intptr = NativeHeader.SendMessage(this.Handle, NativeWindowCommon.CB_GETCOMBOBOXINFO, 0, ptrComboBoxInfo); //CB_GETCOMBOBOXINFO : If the send message succeeds, the return value is nonzero. int returnValue = intptr.ToInt32(); if (returnValue > 0) { // get the info from ptrComboBoxInfo to comboBoxInfo comboBoxInfo = (NativeWindowCommon.COMBOBOXINFO)Marshal.PtrToStructure(ptrComboBoxInfo, typeof(NativeWindowCommon.COMBOBOXINFO)); // save hwnd drop down list HwndDropDownList = comboBoxInfo.hwndList; //replace the window proc of the drop down list CustomDropDownWindowProc = new ControlWndProc(DropDownWindowProc); // save the original drop down list (most be member in the class so the garbig collection will not free it) OriginalDropDownWindowProc = (IntPtr)NativeWindowCommon.SetWindowLong(HwndDropDownList, NativeWindowCommon.GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate(CustomDropDownWindowProc).ToInt32()); } else { Debug.Assert(false); } } finally { // free the ptrComboBoxInfo Marshal.FreeHGlobal(ptrComboBoxInfo); } } } break; #endif case NativeWindowCommon.WM_LBUTTONDOWN: case NativeWindowCommon.WM_LBUTTONDBLCLK: if (!this.DroppedDown) { // prevent drop down on combo - to prevent combo openning on non parkable controls // - it must be handled manually mouseEvents = new MouseEventArgs(MouseButtons.Left, 0, NativeWindowCommon.LoWord((int)m.LParam), NativeWindowCommon.HiWord((int)m.LParam), 0); this.OnMouseDown(mouseEvents); // provide doubleclick event #if !PocketPC if (m.Msg == NativeWindowCommon.WM_LBUTTONDBLCLK) { this.OnMouseDoubleClick(mouseEvents); } return; #else return(0); #endif } break; } #if !PocketPC base.WndProc(ref m); #else return(NativeWindowCommon.CallWindowProc(OrigWndProc, m.HWnd, (uint)m.Msg, (uint)m.WParam.ToInt32(), m.LParam.ToInt32())); #endif }
/// <summary> /// handle horizontal scroll /// </summary> /// <param name="m"></param> private void OnHScroll(ref Message m) { int newValue = int.MinValue; NativeScroll.SCROLLINFO sc = new NativeScroll.SCROLLINFO(); int nScrollCode = NativeWindowCommon.LoWord((int)m.WParam); sc = ScrollInfo(NativeScroll.SB_HORZ); int value = sc.nPos; int maxValue = sc.nMax; switch (nScrollCode) { case NativeScroll.SB_LEFT: newValue = 0; break; case NativeScroll.SB_RIGHT: newValue = maxValue; break; case NativeScroll.SB_LINELEFT: newValue = value - 1; break; case NativeScroll.SB_LINERIGHT: if (value + 1 <= maxValue) { newValue = value + 1; } break; case NativeScroll.SB_PAGELEFT: newValue = value - sc.nPage; break; case NativeScroll.SB_PAGERIGHT: newValue = value + sc.nPage; break; case NativeScroll.SB_THUMBTRACK: newValue = sc.nTrackPos; break; } //Sometimes we get here even if no horizontal scrollbar exsits //happens during load of RTL table in new studio designer //we should not Scroll if we do not have horizontal scollbar if (newValue != int.MinValue && isHorizontalScrollBarVisible) { ScrollEventArgs arg = new ScrollEventArgs((ScrollEventType)m.WParam, value, newValue, ScrollOrientation.HorizontalScroll); this.OnScroll(arg); ScrollHorizontally(value, newValue); Invalidate(); #if !PocketPC if (this.DesignMode) { RefreshChildrensGlyphs(); } #endif } return; }
private int WindowProc(IntPtr hwnd, uint msg, uint wParam, int lParam) { int ret = 0; // keydown of '\f' - barcode prefix. start accumulating key strokes if (msg == NativeWindowCommon.WM_KEYDOWN && wParam == '\f' && !(isJapanese() && usePasswordChar)) { accumulationMode = true; accumulatedBuffer = new StringBuilder(); } // If we are accumulating key strokes we don't want to pass on the keys messages if (accumulationMode && (msg == NativeWindowCommon.WM_KEYDOWN || msg == NativeWindowCommon.WM_CHAR || msg == NativeWindowCommon.WM_KEYUP)) { if (msg == NativeWindowCommon.WM_CHAR) { // Add the chars to our accumulation string if (wParam != '\f') { accumulatedBuffer.Append((char)wParam); } } if (msg == NativeWindowCommon.WM_KEYDOWN) { // tab signs the end of scanner input. set the text to the control and stop accumulating if ((char)wParam == '\t') { accumulationMode = false; KeyEventArgs e = new KeyEventArgs((Keys)KEY_ACCUMULATED); this.OnKeyDown(e); } } } else { // Call original proc // 1. We may get sometime (from Hebrew keyboard on a PC, from a barcode scanner...)a keydown event // with wParam 0, which translates to nothing and causes a crash // 2. The KeyDown event for the enter key is not raised for textbox on Mobile. // On Windows Mobile 6 standard, the up and down are used by the system to change focus, // and we don't get the events in the text box, so we skip the native window proc and raise // the event. if (msg != NativeWindowCommon.WM_KEYDOWN || (wParam != (int)Keys.Enter && wParam != (int)Keys.Down && wParam != (int)Keys.Up && wParam != 0)) { if (isJapanese()) // JPN: ZIMERead function { if (msg == NativeWindowCommon.WM_IME_COMPOSITION) { if ((lParam & NativeWindowCommon.GCS_RESULTREADSTR) > 0) { int hIMC = NativeWindowCommon.ImmGetContext(this.Handle); try { int size = NativeWindowCommon.ImmGetCompositionString(hIMC, NativeWindowCommon.GCS_RESULTREADSTR, null, 0); StringBuilder buffer = new StringBuilder(size); NativeWindowCommon.ImmGetCompositionString(hIMC, NativeWindowCommon.GCS_RESULTREADSTR, buffer, (uint)size); string str = buffer.ToString().Substring(0, size / 2); ImeReadStrBuilder.Append(str); } finally { NativeWindowCommon.ImmReleaseContext(this.Handle, hIMC); } } } } ret = NativeWindowCommon.CallWindowProc(OrigWndProc, hwnd, msg, wParam, lParam); } else if (msg != NativeWindowCommon.WM_KEYDOWN || wParam != 0) { KeyEventArgs e = new KeyEventArgs((Keys)wParam); this.OnKeyDown(e); } // else WM_KEYDOWN with wParam == 0 - do nothing } // Raise the events we don't get on Mobile if (msg == NativeWindowCommon.WM_LBUTTONDOWN) { MouseEventArgs mouseEvents = new MouseEventArgs(MouseButtons.Left, 0, NativeWindowCommon.LoWord(lParam), NativeWindowCommon.HiWord(lParam), 0); this.OnMouseDown(mouseEvents); } else if (msg == NativeWindowCommon.WM_LBUTTONUP) { MouseEventArgs mouseEvents = new MouseEventArgs(MouseButtons.Left, 0, NativeWindowCommon.LoWord(lParam), NativeWindowCommon.HiWord(lParam), 0); this.OnMouseUp(mouseEvents); } return(ret); }
// Our wndproc private int WindowProc(IntPtr hwnd, uint msg, uint wParam, int lParam) { MouseEventArgs mouseEvents; int ret = 0; KeyEventArgs keyEvents; switch (msg) { case NativeWindowCommon.WM_LBUTTONDOWN: { ret = NativeWindowCommon.CallWindowProc(OrigWndProc, hwnd, msg, wParam, lParam); mouseEvents = new MouseEventArgs(MouseButtons.Left, 0, NativeWindowCommon.LoWord(lParam), NativeWindowCommon.HiWord(lParam), 0); this.OnMouseDown(mouseEvents); } break; case NativeWindowCommon.WM_LBUTTONUP: { ret = NativeWindowCommon.CallWindowProc(OrigWndProc, hwnd, msg, wParam, lParam); mouseEvents = new MouseEventArgs(MouseButtons.Left, 0, NativeWindowCommon.LoWord(lParam), NativeWindowCommon.HiWord(lParam), 0); this.OnMouseUp(mouseEvents); } break; case NativeWindowCommon.WM_KEYDOWN: // Get the modifiers Keys modifiers = 0; if (user32.GetKeyState((int)Keys.ShiftKey) < 0) { modifiers |= Keys.Shift; } if (user32.GetKeyState((int)Keys.ControlKey) < 0) { modifiers |= Keys.Control; } if (user32.GetKeyState((int)Keys.Menu) < 0) { modifiers |= Keys.Alt; } keyEvents = new KeyEventArgs((Keys)wParam | modifiers); this.OnKeyDown(keyEvents); break; case NativeWindowCommon.WM_KEYUP: keyEvents = new KeyEventArgs((Keys)wParam); this.OnKeyUp(keyEvents); break; case NativeWindowCommon.WM_CHAR: break; case NativeWindowCommon.BM_CLICK: break; default: ret = NativeWindowCommon.CallWindowProc(OrigWndProc, hwnd, msg, wParam, lParam); break; } return(ret); }