Example #1
0
        public WindowData AddWindow(Form window, IWinProc wp)
        {
            bool bWinProcCreated = false;

            //FormWinProc windowWndProc = null;
            //if (window is FormWinProc)
            //    windowWndProc = (FormWinProc)window;
            if (wp == null)
            {
                if (window is IWinProc)
                    wp = (IWinProc)window;
                else
                {
                    wp = new WinProc(window);
                    //wp.Trace = gbTrace;
                    bWinProcCreated = true;
                }
            }
            if (window.Created && gWindows.ContainsKey(window.Handle.ToInt32()))
            {
                if (bWinProcCreated) wp.Dispose();
                throw new WindowsAppException("error adding window : window is already in window list : {0} - {1}", window.Text, window.Handle);
            }
            // **************************************************************************************************
            // ***** attention ici (après l'appel de gWindows.ContainsKey()) c'est trop tard : ******************
            // **************************************************************************************************
            // *****              if (wp == null) wp = new WinProc(window);                    ******************
            // **************************************************************************************************
            //WindowData windowData = new WindowData() { Form = window, WinProc = wp, EnableCtrlF4Close = EnableCtrlF4Close, DisableAltF4 = DisableAltF4, CloseApplicationOnAltF4 = CloseApplicationOnAltF4 };

            WindowData windowData = null;
            //if (windowWndProc == null)
            //    windowData = new WindowData() { Form = window, WinProc = wp, EnableCtrlF4Close = gbEnableCtrlF4Close, DisableAltF4 = gbDisableAltF4, CloseApplicationOnAltF4 = gbCloseApplicationOnAltF4 };
            //else
            //    windowData = new WindowData() { Form = window, FormWinProc = windowWndProc, EnableCtrlF4Close = gbEnableCtrlF4Close, DisableAltF4 = gbDisableAltF4, CloseApplicationOnAltF4 = gbCloseApplicationOnAltF4 };
            windowData = new WindowData() { Form = window, WinProc = wp, EnableCtrlF4Close = gbEnableCtrlF4Close, DisableAltF4 = gbDisableAltF4, CloseApplicationOnAltF4 = gbCloseApplicationOnAltF4 };

            if (window.Created)
                gWindows.Add(window.Handle.ToInt32(), windowData);
            else
            {
                // si window.Created est false le handle de la fenetre n'est pas encore créé, donc on ajoute la fonction window_Load dans l'event Load
                gWindowsTmp.Add(windowData);
                window.Load += new EventHandler(LoadWindowEvent);
            }
            if (gFirstWindow == null)
            {
                gFirstWindow = windowData;
                gParentWindow.Form.Text = window.Text;
                window.TextChanged += new EventHandler(FirstWindow_TextChanged);
            }

            //if (windowWndProc == null)
            //    wp.MessageEvent += new WinProc.MessageProc(WndProc_Window);
            //else
            //    windowWndProc.MessageEvent += new FormWinProc.MessageProc(WndProc_Window);
            wp.MessageEvent += new MessageProc(WndProc_Window);

            if (gbTrace)
                pb.Trace.WriteLine("WindowsApp                        : AddWindow                                 window {0,-25} hWnd {1}", window.Text, window.Handle);
            return windowData;
        }
Example #2
0
        public void Init(Form parentWindow, IWinProc wp, Icon icon, WAOptions options)
        {

            if (parentWindow == null)
                parentWindow = new MainBaseForm();

            if (wp == null)
            {
                if (parentWindow is IWinProc)
                    wp = (IWinProc)parentWindow;
                else
                    wp = new WinProc(parentWindow);
            }
            parentWindow.ShowInTaskbar = true;
            parentWindow.Load += new EventHandler(parentWindow_Load);

            wp.MessageEvent += new MessageProc(WndProc_ParentWindow);
            gParentWindow = new WindowData() { Form = parentWindow, WinProc = wp, EnableCtrlF4Close = false, DisableAltF4 = false, CloseApplicationOnAltF4 = false };

            //AppMessageFilter = new MessageFilter();
            //AppMessageFilter.PreFilterMessageEvent += new MessageFilter.PreFilterMessageProc(AppPreFilterMessage);
            //Application.AddMessageFilter(AppMessageFilter);

            // gestion CTRL-TAB, CTRL-F4, ALT-F4
            gKeyboardHook = new KeyboardHook();
            gKeyboardHook.HookEvent += new KeyboardHook.HookProc(KeyboardHookProc);

            //gPreWindowHook = new PreWindowHook();
            //gPreWindowHook.HookEvent += new PreWindowHook.HookProc(PreWindowHookProc);

            //gPostWindowHook = new PostWindowHook();
            //gPostWindowHook.HookEvent += new PostWindowHook.HookProc(PostWindowHookProc);

            //gGetMessageWindowHook = new GetMessageWindowHook();
            //gGetMessageWindowHook.HookEvent += new GetMessageWindowHook.HookProc(GetMessageWindowHookProc);
            //gGetMessageWindowHook.Trace = true;

            gbMinimizeParentWindowWhenMinimize = false;
            if ((options & WAOptions.MinimizeParentWindowWhenMinimize) == WAOptions.MinimizeParentWindowWhenMinimize)
                gbMinimizeParentWindowWhenMinimize = true;
            gbHideWindowWhenMinimize = false;
            if ((options & WAOptions.HideWindowWhenMinimize) == WAOptions.HideWindowWhenMinimize)
                gbHideWindowWhenMinimize = true;
            gbHideWindowWhenClose = false;
            if ((options & WAOptions.HideWindowWhenClose) == WAOptions.HideWindowWhenClose)
                gbHideWindowWhenClose = true;
            gbEnableCtrlF4Close = false;
            if ((options & WAOptions.EnableCtrlF4Close) == WAOptions.EnableCtrlF4Close)
                gbEnableCtrlF4Close = true;
            gbDisableAltF4 = false;
            if ((options & WAOptions.DisableAltF4) == WAOptions.DisableAltF4)
                gbDisableAltF4 = true;
            gbCloseApplicationOnAltF4 = false;
            if ((options & WAOptions.CloseApplicationOnAltF4) == WAOptions.CloseApplicationOnAltF4)
                gbCloseApplicationOnAltF4 = true;
            if ((options & WAOptions.CreateNotifyIcon) == WAOptions.CreateNotifyIcon)
                CreateNotifyIcon(icon);
            Icon = icon;

            if (gbTrace)
                pb.Trace.WriteLine("WindowsApp                        : new WindowsApp                            window {0,-25} hWnd {1}", parentWindow.Text, parentWindow.Handle);
        }