// Our wndproc private int formWindowProc(IntPtr hwnd, uint msg, uint wParam, int lParam) { // Do not activate this form - leave it hidden if (msg == NativeWindowCommon.WM_ACTIVATE) { Hide(); return(0); } return(NativeWindowCommon.CallWindowProc(_origFormWndProc, hwnd, msg, wParam, lParam)); }
/// <summary> /// WindowProc of the drop down list box. /// </summary> /// <param name="hwnd"></param> /// <param name="msg"></param> /// <param name="wParam"></param> /// <param name="lParam"></param> /// <returns></returns> protected int DropDownWindowProc(IntPtr hwnd, uint msg, uint wParam, int lParam) { switch (msg) { case NativeWindowCommon.WM_LBUTTONDOWN: // when the user click on the drop down arise the event if (MouseDownOnDropDownList != null) { MouseDownOnDropDownList(this, new EventArgs()); } break; } return(NativeWindowCommon.CallWindowProc(OriginalDropDownWindowProc, hwnd, (uint)msg, wParam, lParam)); }
// Our wndproc private int WindowProc(IntPtr hwnd, uint msg, uint wParam, int lParam) { if (msg == 0x8001 && ClientManager.Instance.IsHidden) // Special activation message { Monitor.Exit(ClientManager.Instance.getWaitHiddenObject()); } int ret = NativeWindowCommon.CallWindowProc(_origWndProc, hwnd, msg, wParam, lParam); // If we hid all forms and hibernated the context, we need to resume the context and show the forms if (msg == 0x8001 && NeedResume) { GUIManager.Instance.restoreHiddenForms(); } return(ret); }
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); }