Example #1
0
        private void OnWmActivate(GuiForm form, EventArgs e)
        {
            GuiForm lastForm = lastActiveTopLevelForm as GuiForm;

            System.TimeSpan timeFromActivation      = DateTime.Now - form.ActivateAppTime;
            System.TimeSpan timeFromMouseActivation = DateTime.Now - form.MouseActivateAppTime;
            ActivateArgs    args = (ActivateArgs)e;

            if (timeFromActivation.TotalMilliseconds < 200 && args.WmParam == NativeWindowCommon.MA_ACTIVATE && (timeFromMouseActivation.Milliseconds > 200)) // we are moving from another application
                                                                                                                                                              //there was no click on the application

            {
                if (lastForm != null && lastForm != form && !lastForm.IsClosing &&
                    !ContextForms.IsLastForm(form) &&               //new from is opening
                    ContextForms.BelongsToCurrentContext(lastForm)) //we are in the same context
                {
                    if (!lastForm.IsMdiChild && !lastForm.IsMdiContainer)
                    {//the solution is not for MDI windows
                        args.StopActivation = true;
                        lastForm.Activate();
                    }
                }
            }
        }
Example #2
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
#if !PocketPC
            case NativeWindowCommon.WM_COPYDATA:
                CopyData(this, new CopyDataEventArgs(m.LParam));
                break;

            case NativeWindowCommon.WM_WINDOWPOSCHANGING:
                WindowReposition(m);
                break;
#endif

            case NativeWindowCommon.WM_SIZING:
                if (Sizing != null)
                {
                    SizingEventArgs sizingEventArgs = new SizingEventArgs(
                        (NativeWindowCommon.SizingEdges)m.WParam,
                        (NativeWindowCommon.RECT)Marshal.PtrToStructure(m.LParam, typeof(NativeWindowCommon.RECT))
                        );
                    Sizing(this, sizingEventArgs);
                    Marshal.StructureToPtr(sizingEventArgs.DragRect, m.LParam, true);
                }
                break;

            case NativeWindowCommon.WM_SYSCOMMAND:
                if (!AllowMove && m.WParam.ToInt32() == NativeWindowCommon.SC_MOVE)
                {
                    return;
                }
                else
                {
                    //Defect #125874. It is .Net behavior (or bug?) that if MaximizeBox = false and the form is being maximized, it covers
                    //the whole screen --- even expanding below the task bar.
                    //So, temporarily set MaximizeBox = true.
                    bool isRestoring = (m.WParam.ToInt32().Equals(NativeWindowCommon.SC_RESTORE));
                    bool orgMaxBox   = this.MaximizeBox;
                    if (isRestoring)
                    {
                        this.MaximizeBox = true;
                    }

                    //Defect 81609: simulating behavior in unipass 1.9:
                    //the ACT_HIT message added to the queue by WM_NCLBUTTONDOWN, was not extracted untill whole WM_SYSCOMMAND was not exectuted.
                    //WM_SYSCOMMAND exits only after mouse is up and all needed windows are activated
                    //if we will handle ACT_HIT before it, WM_SYSCOMMAND will override our handling and activate clicked window disregarding magic logic.
                    base.WndProc(ref m);

                    if (isRestoring)
                    {
                        this.MaximizeBox = orgMaxBox;
                    }

                    RaiseMouseDownIfNeeded();
                    return;
                }

            case NativeWindowCommon.WM_NCLBUTTONDOWN:
            case NativeWindowCommon.WM_NCRBUTTONDOWN:
            case NativeWindowCommon.WM_NCLBUTTONDBLCLK:
                if (!AllowMove && m.WParam.ToInt32() == NativeWindowCommon.HTCAPTION && m.Msg == NativeWindowCommon.WM_NCLBUTTONDOWN)
                {
                    OnNCMouseDown(m);
                    return;
                }
                else
                {
                    int param = m.WParam.ToInt32();
                    Debug.Write("WM_NCLBUTTONDOWN Param=" + param);
                    Debug.Flush();
                    postponedMessage = m;
                    // Activate();
                }
                break;

            case NativeWindowCommon.WM_CHILDACTIVATE:
                NativeWindowCommon.SendMessage(this.Handle, NativeWindowCommon.WM_NCACTIVATE, 1, 0);
                break;

            case NativeWindowCommon.WM_NCACTIVATE:
                if (NCActivate != null && m.WParam.ToInt32() == 1)
                {
                    NCActivate(this, new EventArgs());
                }
                break;

            case NativeWindowCommon.WM_ACTIVATE:
                if (WMActivate != null)
                {
                    ActivateArgs args = new ActivateArgs();
                    args.WmParam = (int)m.WParam;
                    WMActivate(this, args);
                    if (args.StopActivation)      //restore focus to last form
                    {
                        return;
                    }
                }
                break;

            case NativeWindowCommon.WM_ACTIVATEAPP:
                if (m.WParam.ToInt32() == 1)     // application is activated
                {
                    activateAppTime = DateTime.Now;
                }

                break;

            case NativeWindowCommon.WM_MOUSEACTIVATE:
                mouseActivateAppTime = DateTime.Now;;
                break;
            }

            base.WndProc(ref m);
        }
Example #3
0
 internal void WMActivateHandler(object sender, ActivateArgs e)
 {
     handleEvent(EventType.WMACTIVATE, sender, e);
 }