/// <summary> /// 接收消息 /// </summary> /// <param name="m"></param> protected override void DefWndProc(ref System.Windows.Forms.Message m) { switch (m.Msg) { case NativeMethods.WM_COPYDATA: COPYDATASTRUCT mystr = new COPYDATASTRUCT(); Type mytype = mystr.GetType(); mystr = (COPYDATASTRUCT)m.GetLParam(mytype); if (mystr.lpData.StartsWith("open")) { showDetail(mystr.lpData.Substring(mystr.lpData.IndexOf("-")+1),true); } else if (mystr.lpData.StartsWith("manualopen")) { showDetail(mystr.lpData.Substring(mystr.lpData.IndexOf("-") + 1), false); } else if (mystr.lpData.StartsWith("close")) { closeDetail(); } else { Detail_1.WINDOW_HANDLER = int.Parse(mystr.lpData); } break; default: base.DefWndProc(ref m); //MessageBox.Show("no"); break; } }
protected override void DefWndProc(ref System.Windows.Forms.Message m) { string token = ""; COPYDATASTRUCT mystr; Type mytype = null; //MessageBox.Show(m.Msg.ToString()); switch (m.Msg) { case WM_MESSAGE: mystr = new COPYDATASTRUCT(); mytype = mystr.GetType(); mystr = (COPYDATASTRUCT)m.GetLParam(mytype); token = mystr.bstrData; eterm_bga.is_eterm_status = mystr.bstrData; eterm_bga.ib_connect_status = false; eterm_bga.ib_dataflag = false; // MessageBox.Show(this, mystr.bstrData, mystr.bstrCategory); break; case WM_DATA: mystr = new COPYDATASTRUCT(); mytype = mystr.GetType(); mystr = (COPYDATASTRUCT)m.GetLParam(mytype); token = mystr.bstrData; ShowData(token); break; case WM_CTX: mystr = new COPYDATASTRUCT(); mytype = mystr.GetType(); mystr = (COPYDATASTRUCT)m.GetLParam(mytype); token = mystr.bstrToken; CreatingCtx((int)m.WParam, token); break; default: base.DefWndProc(ref m); if (eterm_bga.ib_connect_status) { eterm_bga.is_eterm_status = "Host system down"; eterm_bga.ib_connect_status = false; eterm_bga.ib_dataflag = false; } break; } }
protected override void WndProc(ref System.Windows.Forms.Message m) { if (m.Msg == TCM_ADJUSTRECT) { RECT rc = (RECT) m.GetLParam(typeof(RECT)); rc.Left -= 3; rc.Top -= 3; rc.Right += 3; rc.Bottom += 1; Marshal.StructureToPtr(rc, m.LParam, true); } base.WndProc(ref m); }
public static string _GetMessage(System.Windows.Forms.Message m) { string msg = null; if (m.Msg == Win32.WM_COPYDATA) { if (InSendMessage()) ReplyMessage(IntPtr.Zero); COPYDATASTRUCT data = (COPYDATASTRUCT)m.GetLParam(typeof(COPYDATASTRUCT)); byte[] b = new byte[data.cbData]; Marshal.Copy(data.lpData, b, 0, data.cbData); msg = Encoding.UTF8.GetString(b); } return msg; }
protected override void DefWndProc( ref System.Windows.Forms.Message m ) { switch ( m.Msg ) { case Win32API.WM_COPYDATA: COPYDATASTRUCT mystr = new COPYDATASTRUCT(); Type mytype = mystr.GetType(); mystr = (COPYDATASTRUCT)m.GetLParam( mytype ); String op = mystr.lpData; switch ( op ) { case SecuruStikMessageType.Show: this.Visible = true;break; case SecuruStikMessageType.Hiden: this.Visible = false;break; } break; default: base.DefWndProc( ref m ); break; } }
/// <summary> /// Call this inside your Window proc in the control that /// wants to do custom drawing. /// </summary> /// <param name="msg">The MSG.</param> /// <returns></returns> /// <remarks> /// Example: /// protected override void WndProc(ref Message m) /// { /// myCustDrawHandler.HandleReflectedCustDrawMessage( ref m ); /// if ( !myCustDrawHandler.MessageHandled ) /// { /// base.WndProc (ref m); /// } /// } /// </remarks> public IntPtr HandleReflectedCustDrawMessage( ref System.Windows.Forms.Message msg ) { IntPtr ret = IntPtr.Zero; messageHandled = false; if ( msg.Msg == (int)Win32.OCM.OCM_NOTIFY ) { Win32.NMHDR hrd = (Win32.NMHDR)msg.GetLParam( typeof( Win32.NMHDR ) ); if ( (hrd.code == (int)Win32.NM.NM_CUSTOMDRAW) && (hrd.hwndFrom == interfaceCustDraw.WindowHandle) ) { Win32.NMCUSTOMDRAW nmcd = (Win32.NMCUSTOMDRAW)msg.GetLParam( typeof( Win32.NMCUSTOMDRAW ) ); msg.Result = (IntPtr)OnCustomDraw( (int)msg.WParam.ToInt32(), ref nmcd ); messageHandled = true; } } return ret; }
/// <summary> /// Our WndProc which raise to user OnShow and OnHide events /// </summary> /// <param name="m"></param> protected virtual void WndProc( ref System.Windows.Forms.Message m ) { if( m.Msg == (int)Msg.WM_NOTIFY ) { NMHDR note = (NMHDR)m.GetLParam(typeof(NMHDR)); if( note.code == (int)ToolTipNotifyMsg.TTN_SHOW ) { m.Result = IntPtr.Zero; RaiseOnShowEvent(); } else if( note.code == (int)ToolTipNotifyMsg.TTN_POP ) { RaiseOnHideEvent(); } } }
/// <summary>Occurs when a Windows message is dispatched.</summary> /// <param name="message">Message to process.</param> /// <remarks>Overrides WM_PAINT, WM_ERASEBKGND.</remarks> protected override void WndProc(ref System.Windows.Forms.Message m) { const int WM_PAINT = 0x000F; const int WM_PRINTCLIENT = 0x0318; const int WM_ERASEBKGND = 0x0014; const int WM_MOUSEHOVER = 0x02A1; const int WM_NOTIFY = 0x004E; NMHDR nm1; bool messageProcessed = false; switch (m.Msg) { case (int)7: // WM_SETFOCUS //try { base.WndProc(ref m); } // skip immediate parent to avoid focus problems //catch{} m.Result = IntPtr.Zero; messageProcessed = true; break; // case (int)WindowsMessage.WM_REFLECT + (int)WindowsMessage.WM_NOTIFY: case (int)(0x0400 + 0x1c00 + WM_NOTIFY): m.Result = IntPtr.Zero; nm1 = (NMHDR)m.GetLParam(typeof(NMHDR)); switch (nm1.code) { case (int)ListViewNotificationCodes.LVN_ITEMCHANGED: messageProcessed = true; break; case (int)ListViewNotificationCodes.LVN_GETDISPINFOW: OnDispInfoNotice(ref m, false); messageProcessed = true; break; // ignore dragging as we are virtual and ListView doesnt like it. case (int)ListViewNotificationCodes.LVN_BEGINDRAG: OnBeginDrag(ref m); messageProcessed = true; break; case (int)ListViewNotificationCodes.LVN_BEGINRDRAG: OnBeginDrag(ref m); messageProcessed = true; break; case (int)NotificationCodes.NM_CUSTOMDRAW: m.Result = new IntPtr((int)OnCustomDraw(ref m)); messageProcessed = true; break; case (int)ListViewNotificationCodes.LVN_ODSTATECHANGED: { messageProcessed = true; NMLVODSTATECHANGE lvod = (NMLVODSTATECHANGE)m.GetLParam(typeof(NMLVODSTATECHANGE)); int num1 = lvod.uOldState & (int)ListViewItemStates.LVIS_SELECTED; int num2 = lvod.uNewState & (int)ListViewItemStates.LVIS_SELECTED; if (num2 == num1) return; this.OnSelectedIndexChanged(EventArgs.Empty); break; } default: break; } break; case WM_NOTIFY: nm1 = (NMHDR)m.GetLParam(typeof(NMHDR)); if (nm1.code == (int)NotificationCodes.NM_RCLICK) { IntPtr header = (IntPtr)SendMessage(Handle, (int)ListViewMessages.LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero); uint curpos = GetMessagePos(); Point ptheader = PointToClient(new Point((int)(short)curpos, (int)curpos >> 16)); HDHITTESTINFO hdhti = new HDHITTESTINFO(); hdhti.pt = ptheader; SendMessage(header, HeaderMessageCodes.HDM_HITTEST, IntPtr.Zero, ref hdhti); OnColumnRightClick(new ColumnClickEventArgs(hdhti.iItem)); } else if (nm1.code == (int)HeaderNotificationCodes.HDN_ITEMCLICKW) { if (OnCustomSort(ref m)) { m.Result = IntPtr.Zero; messageProcessed = true; } } break; case WM_ERASEBKGND: //removes flicker return; case WM_MOUSEHOVER: messageProcessed = true; break; case WM_PAINT: // The designer host does not call OnResize() if (internalGraphics == null) OnResize(EventArgs.Empty); //Set up RECT updateRect = new RECT(); if (GetUpdateRect(m.HWnd, ref updateRect, false) == 0) break; PAINTSTRUCT paintStruct = new PAINTSTRUCT(); IntPtr screenHdc = BeginPaint(m.HWnd, ref paintStruct); using (Graphics screenGraphics = Graphics.FromHdc(screenHdc)) { //Draw Internal Graphics internalGraphics.Clear(this.BackColor); IntPtr hdc = internalGraphics.GetHdc(); Message printClientMessage = Message.Create(Handle, WM_PRINTCLIENT, hdc, IntPtr.Zero); DefWndProc(ref printClientMessage); internalGraphics.ReleaseHdc(hdc); //Add the missing OnPaint() call OnPaint(new PaintEventArgs(internalGraphics, Rectangle.FromLTRB( updateRect.left, updateRect.top, updateRect.right, updateRect.bottom))); //Draw Screen Graphics screenGraphics.DrawImage(internalBitmap, 0, 0); } //Tear down EndPaint(m.HWnd, ref paintStruct); return; default: break; } if (!messageProcessed) { try { base.WndProc(ref m); } catch { } } }
protected override void DefWndProc( ref System.Windows.Forms.Message m ) { switch ( m.Msg ) { case Win32API.WM_SYSCOMMAND://prevent the form from being moved int command = m.WParam.ToInt32() & 0xfff0; if ( command == Win32API.SC_MOVE ) return; break; case Win32API.WM_COPYDATA: mystr = (COPYDATASTRUCT)m.GetLParam( mystr.GetType() ); String[] type_params = mystr.lpData.Split( this.SplitArray , StringSplitOptions.RemoveEmptyEntries ); String Type = type_params[ 0 ]; String[] parameters = type_params.Skip( 1 ).ToArray<String>(); CustomDataDelegate customDeal = lookup[ Type ]; customDeal( parameters ); break; default: base.DefWndProc( ref m ); break; } }
/// <summary> /// 接收来自详细页面的消息 /// </summary> /// <param name="m"></param> protected override void DefWndProc(ref System.Windows.Forms.Message m) { switch (m.Msg) { case NativeMethods.WM_COPYDATA: COPYDATASTRUCT mystr = new COPYDATASTRUCT(); Type mytype = mystr.GetType(); mystr = (COPYDATASTRUCT)m.GetLParam(mytype); if (mystr.lpData.StartsWith("isdetailclick")) { LogUtil.debug("isdetailclick:" + mystr.lpData); ControlCenter.pauseTime = DateTime.Now; ControlCenter.isPause = true; } else if (mystr.lpData.StartsWith("startindex"))//回首页 { LogUtil.debug("startindex:" + mystr.lpData); cc.playIndex(); } else if (mystr.lpData.StartsWith("nextdetail"))//播放下一个详情页面 { LogUtil.debug("nextdetail:" + mystr.lpData); ControlCenter.isColseDetail = true; } else if (mystr.lpData.StartsWith("exit"))//退出系统 { //先kill SystemUtil.KillProcess("sungrow_touch"); //先清理资源再退出程序 if (Main.cc != null) Main.cc.clear(); //为防本程序的进程不能成功退出而导致GE出现问题,强制杀掉本程序的进程 //System.Diagnostics.Process geProcess = System.Diagnostics.Process.GetCurrentProcess(); //geProcess.Kill(); this.Close(); LogUtil.debug("exit:" + mystr.lpData); Environment.Exit(0); } break; default: base.DefWndProc(ref m); //MessageBox.Show("no"); break; } }
protected override void DefWndProc(ref System.Windows.Forms.Message m) { switch (m.Msg) { case WM_COPYDATA: COPYDATASTRUCT mystr = new COPYDATASTRUCT(); Type mytype = mystr.GetType(); mystr = (COPYDATASTRUCT)m.GetLParam(mytype); //MessageBox.Show(mystr.lpData); Jid openJid = new Jid(mystr.lpData, XmppCon.Server,null); //MessageBox.Show(openJid.ToString()); Friend item=null; if (listView_fd.Rosters.ContainsKey(openJid.Bare)) { item = listView_fd.Rosters[openJid.Bare]; if (!Util.ChatForms.ContainsKey(item.Ritem.Jid.Bare)) { try { string nickName = listView_fd.GetFriendNickName(openJid.Bare); ChatFromMsg chat = new ChatFromMsg(openJid, XmppCon, nickName); chat.UpdateFriendOnline(item.IsOnline);//设置好友在线状态 chat.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { try { ChatFromMsg chatform = Util.ChatForms[item.Ritem.Jid.Bare] as ChatFromMsg; chatform.WindowState = FormWindowState.Normal; chatform.Activate(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { if (!Util.ChatForms.ContainsKey(openJid.Bare)) { listView_fd.UpdateFriendFlicker(openJid.Bare); string nickName = listView_fd.GetFriendNickName(openJid.Bare); ChatFromMsg chat = new ChatFromMsg(openJid, XmppCon, nickName); Friend friend; if (listView_fd.Rosters.ContainsKey(openJid.Bare)) { friend = listView_fd.Rosters[openJid.Bare]; } else { friend = null; } if (friend != null) { chat.UpdateFriendOnline(listView_fd.Rosters[openJid.Bare].IsOnline); } if (msgBox.ContainsKey(openJid.Bare.ToString())) { chat.FristMessage(msgBox[openJid.Bare.ToString()]); msgBox.Remove(openJid.Bare.ToString()); } try { chat.Show(); } catch (Exception) { } } else { try { ChatFromMsg chatform = Util.ChatForms[openJid.Bare.ToString()] as ChatFromMsg; chatform.WindowState = FormWindowState.Normal; chatform.Activate(); } catch (Exception ex) { MessageBox.Show("打开窗体错误:"+ex.Message); } } } break; default: base.DefWndProc(ref m); break; } }
protected override void WndProc(ref System.Windows.Forms.Message m) { base.WndProc(ref m); if (m.Msg == WM_GETMINMAXINFO) { MINMAXINFO mmi = (MINMAXINFO)m.GetLParam(typeof(MINMAXINFO)); mmi.ptMinTrackSize.x = this.MinimumSize.Width; mmi.ptMinTrackSize.y = this.MinimumSize.Height; if (this.MaximumSize.Width != 0 || this.MaximumSize.Height != 0) { mmi.ptMaxTrackSize.x = this.MaximumSize.Width; mmi.ptMaxTrackSize.y = this.MaximumSize.Height; } mmi.ptMaxPosition.x = 0; mmi.ptMaxPosition.y = 0; System.Runtime.InteropServices.Marshal.StructureToPtr(mmi, m.LParam, true); } }
//************************************************************************* // Method: WndProc // Description: Handles window messages to the listview // // Parameters: // m - the message sent to the control // // Return Value: None //************************************************************************* protected override void WndProc(ref System.Windows.Forms.Message m) { NMHDR nm1; bool messageProcessed = false; switch (m.Msg) { case (int)WindowsMessage.WM_REFLECT + (int)WindowsMessage.WM_NOTIFY: nm1 = (NMHDR) m.GetLParam(typeof(NMHDR)); switch(nm1.code) { case (int)ListViewNotices.LVN_GETDISPINFOW: OnDispInfoNotice(ref m); messageProcessed = true; break; case (int)ListViewNotices.LVN_BEGINDRAG: case (int)ListViewNotices.LVN_BEGINRDRAG: messageProcessed = true; break; default: break; } break; case (int)WindowsMessage.WM_DESTROY: messageProcessed = true; break; default: break; } if (!messageProcessed) { try { base.WndProc(ref m); } catch (ArgumentOutOfRangeException) { // vs.net 2003 and later throws an exception on get and set focus // but just catching it solves the problem } } }
/// <summary> /// Only three windows messages are trapped here: WM_ERASEBKGND /// since the OnPaintBackground doesn't work for the ListView, /// WM_NOTIFY so that we can get all the ListViewFilterHeader /// notificiations, and OCM_NOTIFY for our own notifications. /// </summary> /// <param name="m">Message</param> protected override void WndProc( ref System.Windows.Forms.Message m ) { base.WndProc( ref m ); // determine if we want to process this message type switch( m.Msg ) { // notify messages can come from the header and are used // for column sorting and item filtering if wanted case ( int )W32_WM.WM_NOTIFY: // get the notify message header from this message LParam NMHEADER h1 = ( NMHEADER )m.GetLParam( typeof( NMHEADER ) ); // process messages ONLY from our header control if( ( _headerControl != null ) && ( h1.hdr.hwndFrom == _headerControl.Handle ) ) NotifyHeaderMessage( h1 ); break; // internal ListView notify messages are reflected to us via OCM case ( int )W32_OCM.OCM_NOTIFY: // get the notify message header from this message LParam NMHEADER h2 = ( NMHEADER )m.GetLParam( typeof( NMHEADER ) ); // process ONLY messages that are to this ListView control if( h2.hdr.hwndFrom == Handle ) { // process only specific ListView notify messages switch( h2.hdr.code ) { // draw message, we return a result for the drawstate case ( int )W32_NM.NM_CUSTOMDRAW: //NMLVCUSTOMDRAW d = ( NMLVCUSTOMDRAW )m.GetLParam( typeof( NMLVCUSTOMDRAW ) ); //m.Result = ( IntPtr )NotifyCustomDraw( ref d ); //Marshal.StructureToPtr( d, m.LParam, true ); break; } } break; } }
/// <summary> /// WndProc /// </summary> /// <param name="m"></param> protected override void WndProc(ref System.Windows.Forms.Message m) { #region View messages if(false) { string val; val = Enum.GetName(typeof(APIsEnums.ListViewMessages), (APIsEnums.ListViewMessages) m.Msg); if(val != "" && val != null) Debug.WriteLine(val); else { val = Enum.GetName(typeof(APIsEnums.WindowMessages), (APIsEnums.WindowMessages) m.Msg); if(val != "" && val != null) Debug.WriteLine(val); } if(val != "" && val != null) Debug.WriteLine(m.Msg.ToString()); if(val == "LBUTTONDOWN") { int a= 0; a++; } } #endregion TreeListViewItem item = null; Rectangle rec; switch((APIsEnums.WindowMessages) m.Msg) { #region NOTIFY case APIsEnums.WindowMessages.NOTIFY: case (APIsEnums.WindowMessages) APIsEnums.ReflectedMessages.NOTIFY: APIsStructs.NMHDR nmhdr = (APIsStructs.NMHDR) m.GetLParam(typeof(APIsStructs.NMHDR)); APIsStructs.NMHEADER nmheader =(APIsStructs.NMHEADER) m.GetLParam(typeof(APIsStructs.NMHEADER)); switch((APIsEnums.ListViewNotifications) nmhdr.code) { #region APIsEnums.ListViewNotifications.MARQUEEBEGIN case APIsEnums.ListViewNotifications.MARQUEEBEGIN: if((MouseButtons & MouseButtons.Left) != MouseButtons.Left) m.Result = (IntPtr)1; else _hasMarquee = true; break; #endregion #region APIsEnums.ListViewNotifications.ITEMCHANGING case APIsEnums.ListViewNotifications.ITEMCHANGING: APIsStructs.NMLISTVIEW nmlistview = (APIsStructs.NMLISTVIEW) m.GetLParam(typeof(APIsStructs.NMLISTVIEW)); if(nmlistview.iItem < 0) break; if((item = GetTreeListViewItemFromIndex(nmlistview.iItem)) == null) break; bool cancel = false; if(nmlistview.Select) { if(_selectionMark == null) _selectionMark = item; else if(!_selectionMark.Visible) _selectionMark = item; if(HasMarquee) item.Focused = true; } else if(nmlistview.UnSelect && HasMarquee) { if(item.NextVisibleItem != null) if(item.NextVisibleItem.Selected) item.NextVisibleItem.Focused = true; if(item.PrevVisibleItem != null) if(item.PrevVisibleItem.Selected) item.PrevVisibleItem.Focused = true; } #region Select after dbl click // Disable the selection after a double click (normaly, if the control scrolls after // a collapse, the new item under the cursor is automatically selected...) if(_dblclicktime.AddMilliseconds(500).CompareTo(DateTime.Now) > 0 && (nmlistview.Select || nmlistview.Focus) && FocusedItem != item) cancel = true; #endregion #region Wrong Level Select if(((APIsEnums.ListViewItemStates)nmlistview.uNewState & APIsEnums.ListViewItemStates.SELECTED) == APIsEnums.ListViewItemStates.SELECTED && MultiSelect) if(SelectedIndices.Count > 0) if(GetTreeListViewItemFromIndex(nmlistview.iItem).Parent != SelectedItems[0].Parent) cancel = true; #endregion #region Check during selection // Disable check boxes check when : // - the Marquee selection tool is being used // - the Ctrl or Shift keys are down bool state = (nmlistview.uChanged & (uint)APIsEnums.ListViewItemFlags.STATE) == (uint)APIsEnums.ListViewItemFlags.STATE; bool ctrlKeyDown = (ModifierKeys & Keys.Control) == Keys.Control; bool shiftKeyDown = (ModifierKeys & Keys.Shift) == Keys.Shift; if((nmlistview.Check || nmlistview.UnCheck) && (HasMarquee || ctrlKeyDown || shiftKeyDown)) { // MessageBox.Show(this, // "uChanged = " + nmlistview->uChanged.ToString() + "\n\n" + // "uOld = " + nmlistview->uOldState.ToString() + "\n" + // "uNew = " + nmlistview->uChanged.ToString() + "\n\n" + // "OldCheck : " + (oldCheck ? "true" : "false") + "\n" + // "NewCheck : " + (newCheck ? "true" : "false")); cancel = true; } #endregion if(cancel) { m.Result = (IntPtr)1; return; } break; #endregion #region APIsEnums.ListViewNotifications.BEGINLABELEDIT case APIsEnums.ListViewNotifications.BEGINLABELEDIT: // Cancel label edit if the message is sent just after a double click if(_lastdoubleclick.AddMilliseconds(450) > DateTime.Now) { Message canceledit = Message.Create(Handle, (int) APIsEnums.ListViewMessages.CANCELEDITLABEL, IntPtr.Zero, IntPtr.Zero); WndProc(ref canceledit); m.Result = (IntPtr) 1; return; } item = _lastitemclicked.Item; item.EnsureVisible(); // Add subitems if needed while(item.SubItems.Count-1 < _lastitemclicked.ColumnIndex) item.SubItems.Add(""); TreeListViewBeforeLabelEditEventArgs beforeed = new TreeListViewBeforeLabelEditEventArgs( FocusedItem, _lastitemclicked.ColumnIndex, item.SubItems[_lastitemclicked.ColumnIndex].Text); OnBeforeLabelEdit(beforeed); if(beforeed.Cancel) { Message canceledit = Message.Create(Handle, (int) APIsEnums.ListViewMessages.CANCELEDITLABEL, IntPtr.Zero, IntPtr.Zero); WndProc(ref canceledit); m.Result = (IntPtr) 1; return; } _inedit = true; // Get edit handle Message mess = Message.Create(Handle, (int)APIsEnums.ListViewMessages.GETEDITCONTROL, IntPtr.Zero, IntPtr.Zero); WndProc(ref mess); IntPtr edithandle = mess.Result; _customedit = new CustomEdit(edithandle, this, beforeed.Editor); _editeditem = new EditItemInformations( FocusedItem, beforeed.ColumnIndex, FocusedItem.SubItems[beforeed.ColumnIndex].Text); m.Result = IntPtr.Zero; return; #endregion #region APIsEnums.ListViewNotifications.ENDLABELEDIT case APIsEnums.ListViewNotifications.ENDLABELEDIT: if(_customedit != null) _customedit.HideEditControl(); _customedit = null; _inedit = false; _editeditem = new EditItemInformations(); m.Result = IntPtr.Zero; return; #endregion #region CUSTOMDRAW case (APIsEnums.ListViewNotifications) APIsEnums.NotificationMessages.CUSTOMDRAW: base.WndProc(ref m); CustomDraw(ref m); return; #endregion #region BEGINSCROLL case APIsEnums.ListViewNotifications.BEGINSCROLL: _updating = true; break; #endregion #region ENDSCROLL case APIsEnums.ListViewNotifications.ENDSCROLL: _updating = false; // Disable display bug with vertical lines (slow...) // if(ShowPlusMinus) // { // DrawPlusMinusItemsLines(); // DrawPlusMinusItems(); // } break; #endregion #region APIsEnums.HeaderControlNotifications.BEGINDRAG case (APIsEnums.ListViewNotifications) APIsEnums.HeaderControlNotifications.BEGINDRAG: nmheader =(APIsStructs.NMHEADER) m.GetLParam(typeof(APIsStructs.NMHEADER)); if(nmheader.iItem == 0) { m.Result = (IntPtr)1; return; } break; #endregion #region APIsEnums.HeaderControlNotifications.ENDDRAG case (APIsEnums.ListViewNotifications) APIsEnums.HeaderControlNotifications.ENDDRAG: nmheader =(APIsStructs.NMHEADER) m.GetLParam(typeof(APIsStructs.NMHEADER)); // Get mouse position in header coordinates IntPtr headerHandle = (IntPtr) APIsUser32.SendMessage(Handle, (int) APIsEnums.ListViewMessages.GETHEADER, IntPtr.Zero, IntPtr.Zero); APIsStructs.POINTAPI pointapi = new APIsStructs.POINTAPI(MousePosition); APIsUser32.ScreenToClient(headerHandle, ref pointapi); // HeaderItem Rect APIsStructs.RECT headerItemRect = new APIsStructs.RECT(); APIsUser32.SendMessage(headerHandle, (int)APIsEnums.HeaderControlMessages.GETITEMRECT, 0, ref headerItemRect); int headerItemWidth = headerItemRect.right - headerItemRect.left; // Cancel the drag operation if the first column is moved // or destination is the first column if(pointapi.x <= headerItemRect.left + headerItemWidth / 2 || nmheader.iItem == 0) { m.Result = (IntPtr)1; return; } break; #endregion #region APIsEnums.HeaderControlNotifications.TRACK / ENDTRACK // case (APIsEnums.ListViewNotifications)APIsEnums.HeaderControlNotifications.TRACK: case (APIsEnums.ListViewNotifications)APIsEnums.HeaderControlNotifications.ENDTRACK: Invalidate(); break; #endregion } break; #endregion #region LBUTTONDOWN // Cancel the click on checkboxes if the item is not "checkable" case APIsEnums.WindowMessages.LBUTTONDOWN: if(Columns.Count == 0) break; // Set the clickeditem and column int colclicked = GetColumnAt(MousePosition); if(colclicked == -1) colclicked = 0; item = GetItemAtFullRow(PointToClient(MousePosition)); _lastitemclicked = new EditItemInformations(item, colclicked, ""); if(_selectionMark == null || !_selectionMark.Visible) _selectionMark = item; if(((APIsEnums.KeyStatesMasks)(int)m.WParam & APIsEnums.KeyStatesMasks.SHIFT) != APIsEnums.KeyStatesMasks.SHIFT && !(((APIsEnums.KeyStatesMasks)(int)m.WParam & APIsEnums.KeyStatesMasks.CONTROL) == APIsEnums.KeyStatesMasks.CONTROL && item.Parent != _selectionMark.Parent)) _selectionMark = item; // Get where the mouse has clicked APIsStructs.LVHITTESTINFO lvhittest = new APIsStructs.LVHITTESTINFO(); lvhittest.pt = new APIsStructs.POINTAPI(PointToClient(MousePosition)); APIsUser32.SendMessage(Handle, (Int32) APIsEnums.ListViewMessages.HITTEST, 0, ref lvhittest); if(item == null) break; // Plus / Minus click if(item.GetBounds(TreeListViewItemBoundsPortion.PlusMinus).Contains(PointToClient(MousePosition)) && ShowPlusMinus && item.Items.Count > 0 && Columns[0].Width > (item.Level+1)*SystemInformation.SmallIconSize.Width) { Focus(); if(item.IsExpanded) item.Collapse(); else item.Expand(); OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, PointToClient(MousePosition).X, PointToClient(MousePosition).Y, 0)); return; } // Cancel mouse click if multiselection on a wrong item if(SelectedIndices.Count > 0 && (((APIsEnums.KeyStatesMasks)(int)m.WParam & APIsEnums.KeyStatesMasks.SHIFT) == APIsEnums.KeyStatesMasks.SHIFT || ((APIsEnums.KeyStatesMasks)(int)m.WParam & APIsEnums.KeyStatesMasks.CONTROL) == APIsEnums.KeyStatesMasks.CONTROL) && MultiSelect) { if(_selectionMark.Parent == item.Parent && ((APIsEnums.KeyStatesMasks)(int)m.WParam & APIsEnums.KeyStatesMasks.SHIFT) == APIsEnums.KeyStatesMasks.SHIFT) { _updating = true; SetSelectedItemsRange(item, _selectionMark); // Prevent all item at the wrong level of being selected m.WParam = (IntPtr) APIsEnums.KeyStatesMasks.CONTROL; base.WndProc(ref m); item.Selected = true; _updating = false; DrawSelectedItemsFocusCues(); return; } } break; #endregion #region LBUTTONDBLCLK // Disable this notification to remove the auto-check when // the user double-click on an item and append the expand / collapse function case APIsEnums.WindowMessages.LBUTTONDBLCLK: _lastdoubleclick = DateTime.Now; if(FocusedItem != null) { item = FocusedItem; bool doExpColl = false; switch(ExpandMethod) { case TreeListViewExpandMethod.IconDbleClick: rec = item.GetBounds(ItemBoundsPortion.Icon); if(rec.Contains(PointToClient(MousePosition))) doExpColl = true; break; case TreeListViewExpandMethod.ItemOnlyDbleClick: rec = item.GetBounds(ItemBoundsPortion.ItemOnly); if(rec.Contains(PointToClient(MousePosition))) doExpColl = true; break; case TreeListViewExpandMethod.EntireItemDbleClick: rec = item.GetBounds(ItemBoundsPortion.Entire); if(rec.Contains(PointToClient(MousePosition))) doExpColl = true; break; default: break; } if(doExpColl) { _dblclicktime = DateTime.Now; Cursor = Cursors.WaitCursor; BeginUpdate(); if(item.IsExpanded) item.Collapse(); else item.Expand(); EndUpdate(); Cursor = Cursors.Default; } } OnDoubleClick(new EventArgs()); return; #endregion #region MOUSEMOVE case APIsEnums.WindowMessages.MOUSEMOVE: if((MouseButtons & MouseButtons.Left) != MouseButtons.Left && HasMarquee) _hasMarquee = false; break; #endregion #region UNICHAR, CHAR, KEYDOWN case APIsEnums.WindowMessages.UNICHAR: case APIsEnums.WindowMessages.CHAR: CharPressed((char) m.WParam); return; case APIsEnums.WindowMessages.KEYDOWN: OnKeyDown(new KeyEventArgs((Keys)(int) m.WParam)); return; #endregion #region PAINT case APIsEnums.WindowMessages.PAINT: if(InEdit && EditedItem.Item != null) { APIsStructs.RECT rect = new APIsStructs.RECT( EditedItem.Item.GetBounds(ItemBoundsPortion.Entire)); APIsUser32.ValidateRect(Handle, ref rect); } base.WndProc(ref m); DrawIntermediateStateItems(); DrawSelectedItemsFocusCues(); return; #endregion #region VSCROLL, HSCROLL, ENSUREVISIBLE case APIsEnums.WindowMessages.VSCROLL: case APIsEnums.WindowMessages.HSCROLL: case (APIsEnums.WindowMessages)APIsEnums.ListViewMessages.ENSUREVISIBLE: if(!Scrollable) { m.Result = (IntPtr)0; return; } break; #endregion } base.WndProc(ref m); }
/// <summary> /// Handle a WM_COPYDATA message sent to the application. /// </summary> /// <param name="m">received message</param> public void handleWmCopyData(ref System.Windows.Forms.Message m) { CopyData copyData = default(CopyData); int handle = 0; // get message contents copyData = (CopyData)m.GetLParam(typeof(CopyData)); handle = (int)m.WParam; // handle known messages // NB: messy handling to convert the received 32-bit value into // an unsigned value - a proper C# programmer could probably do // this more gracefully. long event_id; int event_id_integer = (int)copyData.dwData; if (event_id_integer < 0) { event_id = event_id_integer + 4294967296; } else { event_id = event_id_integer; } switch (event_id) { case ChipAttach: this.ProcessChipAttach(ref copyData); break; case ChipDetach: this.ProcessChipDetach(); break; case ChipDebugData: this.ProcessChipDebugData(ref copyData); break; case ChipDebugStartConfirm: this.ProcessChipDebugStartConfirm(ref copyData); break; case ChipDebugStopConfirm: this.ProcessChipDebugStopConfirm(ref copyData); break; case ChipLoadConfigConfirm: this.ProcessChipLoadConfigConfirm(ref copyData); break; case ChipSaveConfigConfirm: this.ProcessChipSaveConfigConfirm(ref copyData); break; case ChipObjectTable: this.ProcessChipObjectTable(ref copyData); break; case ObjectConfig: this.ProcessObjectConfig(ref copyData); break; case ObjectInvalidMessageRegisterConfirm: this.ProcessObjectInvalidMessageRegisterConfirm(); break; case ObjectInvalidMessageUnregisterConfirm: this.ProcessObjectInvalidMessageUnregisterConfirm(); break; case ObjectMessage: this.ProcessObjectMessage(ref copyData); break; case ServerConnectionInfo: this.ProcessServerConnectionInfo(ref copyData); break; case ServerInfo: this.ProcessServerInfo(ref copyData); break; case ServerPong: this.ProcessServerPong((IntPtr)handle, ref copyData); break; case ServerDetach: this.ProcessServerDetach(); break; } }
protected override void WndProc(ref System.Windows.Forms.Message m) { switch ((WM) m.Msg) { case (WM)TCM.ADJUSTRECT: { // We need to adjust the display rectangle, which directly determines where the content is shown. Win32.RECT rectangle = (Win32.RECT) m.GetLParam(typeof(Win32.RECT)); // The "larger" value indicates the direction of the computation. // A 1 means from display rectangle to window rectangle. A 0 the other way around. int topOffset = 0; if (tabStyle == TabStyleType.TopNormal || tabStyle == TabStyleType.TopTransparent) topOffset = ItemSize.Height; int bottomOffset = 0; if (tabStyle == TabStyleType.BottomNormal) bottomOffset = ItemSize.Height; int larger = m.WParam.ToInt32(); if (larger == 0) { rectangle.Left += Margin.Left + contentPadding.Left; rectangle.Right -= Margin.Right + contentPadding.Right; rectangle.Top += Margin.Top + ContentPadding.Top + topOffset; rectangle.Bottom -= Margin.Bottom + ContentPadding.Bottom + bottomOffset; } else { rectangle.Left -= Margin.Left + contentPadding.Left; rectangle.Right += Margin.Right + contentPadding.Right; rectangle.Top -= Margin.Top + contentPadding.Top + topOffset; rectangle.Bottom += Margin.Bottom + contentPadding.Bottom + bottomOffset; } Marshal.StructureToPtr(rectangle, m.LParam, true); break; } case WM.HSCROLL: switch ((SB) Win32.LoWord(m.WParam.ToInt32())) { case SB.THUMBPOSITION: scrollOffset = -scrollScaleFactor * Win32.HiWord(m.WParam.ToInt32()); Invalidate(); break; } m.Result = new IntPtr(1); break; case WM.WINDOWPOSCHANGED: base.WndProc(ref m); UpdateScroller(); if (tabStyle == TabStyleType.BottomNormal) AdjustLayoutInfo(null); break; case WM.SIZE: base.WndProc(ref m); if (m.WParam.ToInt32() == Win32.SIZE_RESTORED && m.LParam.ToInt32() != 0) { // Window has been resized. if (pendingScrollIntoViewIndex > -1) ScrollIntoView(pendingScrollIntoViewIndex); pendingScrollIntoViewIndex = -1; } break; case WM.NCHITTEST: { // Declare everything as being part of the client area, so we get mouse events for that. m.Result = new IntPtr(1); // HT_CLIENT break; } case WM.LBUTTONDOWN: { // Handle this message directly to keep the base class from doing unwanted things. uint lparam = (uint)m.LParam.ToInt32(); int x = Win32.LoWord(lparam); int y = Win32.HiWord(lparam); MouseEventArgs args = new MouseEventArgs(MouseButtons.Left, 1, x, y, 0); OnMouseDown(args); m.Result = IntPtr.Zero; break; } default: base.WndProc(ref m); // The tab relayout message is a message registered by the original tab control // and obviously the one where the tab control also sets the position of the scroller. // Since we have our own view of how that should be done we listen to this message to // make our own adjustments. if (tabRelayoutMessageID != 0 && m.Msg == tabRelayoutMessageID) UpdateScroller(); break; } }