protected Boolean CheckClickSequence(Message m) { Boolean rc = false; // In Win10, WM_IME_CHAR just after WM_IME_ENDCOMPOSITION should be ignored. // In Win7, it must be processed. // To distinguish, WM_REFLECT_WM_COMMAND/EN_CHANGE is checked. switch (m.Msg) { case NativeWindowCommon.WM_IME_STARTCOMPOSITION: shouldIgnoreNextImeChar = false; break; case NativeWindowCommon.WM_IME_ENDCOMPOSITION: shouldIgnoreNextImeChar = true; break; case NativeWindowCommon.WM_REFLECT_WM_COMMAND: if ((ENNOTIFY)NativeWindowCommon.HiWord((int)m.WParam) == ENNOTIFY.EN_CHANGE) { shouldIgnoreNextImeChar = false; } break; case NativeWindowCommon.WM_IME_CHAR: rc = shouldIgnoreNextImeChar; shouldIgnoreNextImeChar = false; break; } return(rc); }
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 }
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); }