/// <summary> /// 初始化 /// </summary> /// <returns></returns> public bool Initiate() { Win32Message.ChangeWindowMessageFilter(Win32Message.WM_COPYDATA, 1); tetsingEnable = true; return(true); }
public GameLoop(LoopCallback callback) { _callback = callback; msg = new Win32Message(); Application.Idle += Application_Idle; //_gameLoopThread = new Thread(new ThreadStart(TheLoop)); //_gameLoopThread.Start(); }
//private UserProcessState _UserProcessState = UserProcessState.Processing ; ///// <summary> ///// 用户选择状态 ///// </summary> //public virtual UserProcessState UserProcessState //{ // get { return _UserProcessState; } // set { _UserProcessState = value; } //} //private UserProcessState _DefaultUserProcessState = UserProcessState.Accept; ///// <summary> ///// 默认的选择状态 ///// </summary> //public virtual UserProcessState DefaultUserProcessState //{ // get { return _DefaultUserProcessState; } // set { _DefaultUserProcessState = value; } //} /// <summary> /// 等待用户的选择操作,本函数将不返回直到用户确定选择或取消选择 /// </summary> /// <remarks>本函数向当前应用程序添加自定义的消息过滤器,并开始循环处理当前应用程序的消息,若用户确定或取消的选择操作则退出循环处理</remarks> /// <returns>用户是否选择的某个项目</returns> public virtual void WaitUserSelected() { //Win32.NativeMSG msg = new Win32.NativeMSG(); // Process messages until exit condition recognised bolExitLoop = false; bolUserAccept = false; MessageFilter.ExcludePaintMessageFilter.Enabled = true; Win32Message.ClearMessage(); //System.Windows.Forms.Application.DoEvents(); MessageFilter.ExcludePaintMessageFilter.Enabled = false; System.Windows.Forms.Application.AddMessageFilter(this); //this.UserProcessState = WinForms.UserProcessState.Processing; UserProcessState state = UserProcessState.Processing; WindowInformation info = new WindowInformation(this); while (Win32Message.Wait()) { //User32.GetMessage(ref msg, 0, 0, 0); // Windows32.User32.GetMessage( ref msg , 0 , 0 , 0 ); // Windows32.User32.TranslateMessage( ref msg ); // Windows32.User32.DispatchMessage( ref msg ); System.Windows.Forms.Application.DoEvents(); //state = this.UserProcessState ; if (this.Visible == false) { break; } if (state == UserProcessState.Accept || state == UserProcessState.Cancel) { break; } if (bolExitLoop) { break; } }//while System.Windows.Forms.Application.RemoveMessageFilter(this); Win32Message.ClearMessage(); //if (state == UserProcessState.Processing) //{ // state = this.DefaultUserProcessState; //} if (this.AutoClose) { this.Hide(); } //return state == UserProcessState.Accept ; }
public void SendMessage(Win32Message msg) { SendMessage((uint)msg); }
public void PostMessage(Win32Message msg) { PostMessage((uint)msg); }
/// <summary> /// 本函数实现 System.Windows.Forms.IMessageFilter接口的PreFilterMessage函数,用于对当前应用程序的消息进行预处理 /// </summary> /// <remarks>本过滤器处理了鼠标按钮按下时间和键盘事件以及鼠标滚轮事件, /// 若鼠标在本列表边框外部按下则表示认为用户想要关闭列表,此时立即关闭本列表窗体 /// 此外本函数还处理汉语拼音辅助定位列表元素 /// 用户可用上下光标键或者上下翻页键来滚动列表,用空格或回车来进行选择</remarks> /// <param name="m">当前消息队列中的消息对象</param> /// <returns>true 当前消息其他程序不可处理(本消息被吃掉了) false本消息还可被其他程序处理</returns> public virtual bool PreFilterMessage(ref System.Windows.Forms.Message m) { bool eatMessage = false; if (this.IsDisposed || this.Disposing || this.Visible == false) { // 若对象被销毁了或列表不显示则删除本消息过滤器 System.Windows.Forms.Application.RemoveMessageFilter(this); return(false); } Win32Message msg = new Win32Message(m); // 获得窗体的绝对位置和大小 System.Drawing.Rectangle BoundsRect = this.Bounds; // 鼠标在客户区的按键按下消息 // Mouse was pressed in a window of this application if (msg.IsMouseDownMessage) { if (msg.Msg == (int)Msgs.WM_LBUTTONDOWN || msg.Msg == (int)Msgs.WM_MBUTTONDOWN || msg.Msg == (int)Msgs.WM_RBUTTONDOWN || msg.Msg == (int)Msgs.WM_XBUTTONDOWN) { System.Drawing.Point mousePos = msg.ScreenMousePosition; bolExitLoop = !BoundsRect.Contains(mousePos); msgBack = m; eatMessage = bolExitLoop; if (bolExitLoop) { if (IsChildWindow(m.HWnd)) { bolExitLoop = false; } WindowInformation info = new WindowInformation(this.Handle); if (info.Enabled == false) { // 窗体不可用,很可能正在显示对话框使得本窗体暂时不可用 bolExitLoop = false; } //else //{ // this.UserProcessState = WinForms.UserProcessState.Accept; //} return(true); } } } // 鼠标在非客户区的按键按下消息 // Mouse was pressed in a window of this application if ((m.Msg == (int)Msgs.WM_NCLBUTTONDOWN) || (m.Msg == (int)Msgs.WM_NCMBUTTONDOWN) || (m.Msg == (int)Msgs.WM_NCRBUTTONDOWN) || (m.Msg == (int)Msgs.WM_NCXBUTTONDOWN)) { System.Drawing.Point mousePos = msg.MousePosition; bolExitLoop = !BoundsRect.Contains(mousePos); //eatMessage = true; msgBack = m; eatMessage = bolExitLoop; if (bolExitLoop) { if (IsChildWindow(m.HWnd)) { bolExitLoop = false; } WindowInformation info = new WindowInformation(this.Handle); if (info.Enabled == false) { // 窗体不可用,很可能正在显示对话框使得本窗体暂时不可用 bolExitLoop = false; } //else //{ // this.UserProcessState = WinForms.UserProcessState.Accept; //} return(true); } } if (this.RuntimeContentControl is IMessageFilter) { WindowInformation info = new WindowInformation(this.Handle); //if (info.Enabled) { IMessageFilter mf = (IMessageFilter)this.RuntimeContentControl; return(mf.PreFilterMessage(ref m)); } } return(eatMessage); }
/// <summary> /// main working horse - determines proxy Url and sets up IWebProxy class complete with credentials /// </summary> /// <param name="targetUrl">the file to download</param> /// <param name="useDefaultProxy">whether to use Internet Explorer settings</param> /// <param name="useDynamicProxy">If set, will download a script that provides the real proxy URL</param> /// <param name="proxyUrl">Script URL (if useDynamicProxy is true) or proxy URL</param> /// <param name="userName">User name (credentials)</param> /// <param name="password">Password (credentials)</param> /// <returns>An IWebProxy configured correspondingly</returns> public static IWebProxy DetermineProxyForUrl( string targetUrl, bool useDefaultProxy, bool useDynamicProxy, string proxyUrl, string userName, string password ) { IWebProxy theProxy = null; if (useDefaultProxy) { // Get Internet Explorer settings theProxy = WebRequest.DefaultWebProxy; } else { if (useDynamicProxy) { // need to use scripting, call corresponding method int errCode = 0; theProxy = DetermineAutoProxyForUrl(targetUrl, proxyUrl, ref errCode); if (errCode != 0) { // failed, throw an exception throw new System.Exception( String.Format( CultureInfo.CurrentCulture, "Determining dynamic proxy for target url '{0}' using script url '{1}' failed with Win32 error '{2}'", targetUrl, IsEmpty(proxyUrl) ? "(none)" : proxyUrl, Win32Message.GetMessage(errCode)) ); } } else { if (IsEmpty(proxyUrl)) { // no scripting, no default -> no proxy theProxy = null; } else { // plain URL provided theProxy = new WebProxy(proxyUrl); } } } // add credentials to the mix if provided and if proxy exists if (theProxy != null) { theProxy.Credentials = DetermineCredentials(userName, password, null); } return(theProxy); }
private void InjectKeyboardEvent(Win32Message message, byte virtualKeyCode, bool isExtended, bool contextCode, bool previousState, bool transitionState) { var lParam = new KeyLParam(1, virtualKeyCode, isExtended, contextCode, previousState, transitionState); webView.InjectKeyboardEvent((IntPtr)0, (int)message, virtualKeyCode, lParam); }
public static extern bool PeekMessage( out Win32Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);
public static extern IntPtr DispatchMessage([In] ref Win32Message lpmsg);
public static extern bool TranslateMessage([In] ref Win32Message lpMsg);
public static extern bool PeekMessage(out Win32Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);