public bool PreFilterMessage(ref Message m) { NativeConsts.WindowMessage WindowsMessage = (NativeConsts.WindowMessage)m.Msg; if (WindowsMessage == NativeConsts.WindowMessage.WM_PAINT) { Control ctl = Control.FromHandle(m.HWnd); if (ctl != null) { if (ctl is ProgressBar) { Graphics g = ctl.CreateGraphics(); g.FillRectangle(Brushes.Red, new Rectangle(0, 0, 20, 20)); } } } Control ctll = Control.FromHandle(m.HWnd); if (ctll != null) { if (ctll is Form) { Debug.Print(ctll.Name); Debug.Print(m.Msg.ToString()); } } if (WindowsMessage == NativeConsts.WindowMessage.WM_CREATE) { MessageBox.Show(m.HWnd.ToString()); } return(false); }
/// <summary> /// 当产生消息时 /// </summary> /// <param name="msg">消息</param> void mh_MessageOccurred(ref Message msg) { NativeConsts.WindowMessage WindowsMessage = (NativeConsts.WindowMessage)msg.Msg; switch (WindowsMessage) { case NativeConsts.WindowMessage.WM_CREATE: { try { Control ctl = Control.FromHandle(msg.HWnd); if (ctl is Form) { BindEvent(ctl); } } catch { } break; } } }