public bool InstallMsgHook()
 {
     locEvtHook   = new User32.WinEventDelegate(LocChangeHook);
     focusEvtHook = new User32.WinEventDelegate(FocusChangeHook);
     hLocHook     = User32.SetWinEventHook(0x800B, 0x800B, IntPtr.Zero, locEvtHook, (uint)DS3Interop.Process.Id, DS3Interop.WinThread, 3);
     hFocusHook   = User32.SetWinEventHook(0x8005, 0x8005, IntPtr.Zero, focusEvtHook, 0, 0, 0);
     return(hLocHook != IntPtr.Zero && hFocusHook != IntPtr.Zero);
 }
        private void detachFromSystemEvents()
        {
            foreach (var handle in _monitoredWinEventsHookHandles)
            {
                User32.UnhookWinEvent(handle);
            }

            _monitoredWinEventsHookHandles.Clear();
            _handleWindowPositionChangedDelegate = null;
        }
        private void attachToSystemEvents()
        {
            _handleWindowPositionChangedDelegate = handleWindowPositionChanged;

            foreach (var user32Event in _windowPositionChangedUser32Events)
            {
                var winEventsHookHandle = User32.SetWinEventHook((uint)user32Event, (uint)user32Event, IntPtr.Zero, _handleWindowPositionChangedDelegate, 0, 0, (uint)User32Events.WINEVENT_OUTOFCONTEXT);
                _monitoredWinEventsHookHandles.Add(winEventsHookHandle);
            }

            // Add other User32Events here and use monitoredWinEventsHookHandles to store handles. Modification
            // of detachFromSystemEvents will be not needed.
        }
示例#4
0
        private void InitHook(){
            //make sure the event delegate isn't getting lost ...
            _procDelegate = new User32.WinEventDelegate(WinEventProc);

            m_hhook = User32.SetWinEventHook(
                User32.EVENT_SYSTEM_SWITCHSTART, // eventMin
                User32.EVENT_SYSTEM_SWITCHEND,   // eventMax
                IntPtr.Zero,                     // hmodWinEventProc
                _procDelegate,                   // lpfnWinEventProc
                0,                               // idProcess
                0,                               // idThread
                User32.WINEVENT_OUTOFCONTEXT);
        }
示例#5
0
        private void InitHook()
        {
            //make sure the event delegate isn't getting lost ...
            _procDelegate = new User32.WinEventDelegate(WinEventProc);

            m_hhook = User32.SetWinEventHook(
                User32.EVENT_SYSTEM_SWITCHSTART, // eventMin
                User32.EVENT_SYSTEM_SWITCHEND,   // eventMax
                IntPtr.Zero,                     // hmodWinEventProc
                _procDelegate,                   // lpfnWinEventProc
                0,                               // idProcess
                0,                               // idThread
                User32.WINEVENT_OUTOFCONTEXT);
        }
        public PersistentWindowProcessor()
        {
            monitorApplications = new Dictionary <string, SortedDictionary <string, ApplicationDisplayMetrics> >();
            this.CreateEventHandlers();
            this.winEventsCaptureDelegate = WinEventProc;
            // this.winEventDebugDelegate = WinEventProcDebug;

            //this.ignoreCaptureTimer = new Timer(state =>
            //{
            //    Log.Trace("ignoreCaptureTimer done. Re-enabling capture requests.");
            //    this.ignoreCaptureRequests = false;
            //});

            this.delayedCaptureTimer = new Timer(state =>
            {
                Log.Trace("Delayed capture timer triggered");
                this.BeginCaptureApplicationsOnCurrentDisplays();
            });
        }
示例#7
0
        public MainViewModel()
        {
            if (IsInDesignMode)
            {
                WindowTitle = "PoeSuite (Designmode)";
            }
            else
            {
                WindowTitle = "PoeSuite - Settings";
            }

            _ioService = SimpleIoc.Default.GetInstance <IOService>();

            OpenFileDialogCommand = new RelayCommand(OpenFile);

            _timer          = new Timer(250);
            _timer.Elapsed += OnTimerElapsed;

            if (Properties.Settings.Default.AutoStartPoe &&
                !string.IsNullOrEmpty(Properties.Settings.Default.PoeFilePath) &&
                Game.ValidateGamePath(Properties.Settings.Default.PoeFilePath) &&
                !Game.GetRunningInstances().Any())
            {
                Poe = Game.Launch(Properties.Settings.Default.PoeFilePath);
            }
            else
            {
                _timer.Start();
            }

            t = new Misc(Game.Settings);

            HotkeysManager.Get.AddCallback("Logout", () =>
            {
                Poe?.CloseTcpConnections();
                Logger.Get.Debug("logoutCommand called");
            });


            _winEventCallback = new User32.WinEventDelegate(WinEventProc);
            IntPtr m_hhook = User32.SetWinEventHook(User32.EVENT_SYSTEM_FOREGROUND, User32.EVENT_SYSTEM_FOREGROUND,
                                                    IntPtr.Zero, _winEventCallback, 0, 0, User32.WINEVENT_OUTOFCONTEXT);
        }
示例#8
0
        public WindowMonitor(string configFile)
        {
            if (!File.Exists(configFile))
            {
                throw new System.InvalidOperationException("File " + configFile + " doesn't exist.");
            }

            Config = JsonConvert.DeserializeObject <WindowMonitorConfig>(File.ReadAllText(configFile));
            Config.validateConfig();

            /* Memory before writing to disk */
            RecordCollection = new RecordCollection(Config.HowManyChangesBeforeDiskWrite);

            PersistInterval         = new BackgroundWorker();
            PersistInterval.DoWork += new DoWorkEventHandler(PersistIntervalJob);
            PersistInterval.RunWorkerAsync();

            Callback = new User32.WinEventDelegate(UpdateProcess);

            User32.SetClickHook(Callback);
            UpdateProcess();
        }
示例#9
0
        public static CancellationTokenSource Run(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, User32.WinEventDelegate eventDelegate, uint idProcess, uint idThread, uint dwFlags)
        {
            var cancellationToken = new CancellationTokenSource();

            Task.Run(() =>
            {
                var handle = User32.SetWinEventHook(eventMin, eventMax, hmodWinEventProc, eventDelegate, idProcess, idThread, dwFlags);
                while (!cancellationToken.Token.IsCancellationRequested)
                {
                    if (User32.PeekMessage(out var msg, IntPtr.Zero, 0, 0, PM_REMOVE))
                    {
                        if (msg.Message == WM_QUIT)
                        {
                            break;
                        }

                        User32.TranslateMessage(ref msg);
                        User32.DispatchMessage(ref msg);
                    }
                    Thread.Sleep(200);
                }
                User32.UnhookWinEvent(handle);
            }, cancellationToken.Token);


            return(cancellationToken);
        }
示例#10
0
 public WindowTracker()
 {
     callback = new User32.WinEventDelegate(HandleWinEvent);
 }
        private void BtnBaslat_Click(object sender, EventArgs e)
        {
            try
            {
                var     path    = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\notepad.exe";
                Process process = Process.Start(path);
trying:
                IntPtr handle = process.MainWindowHandle;
                if (handle == IntPtr.Zero)
                {
                    goto trying;
                }

                IntPtr editpoint = User32.FindWindowEx(handle, IntPtr.Zero, "Edit", IntPtr.Zero);

                var hMainMenu  = User32.CreateMenu();
                var hPopupMenu = User32.CreateMenu();

                StringBuilder sb = new StringBuilder();
                User32.GetWindowText(handle, sb, 200);
                var windowTitle = sb.ToString();

                var sysMenu = User32.GetMenu(handle);
                if (User32.GetMenuItemCount(sysMenu) != 6)
                {
trying2:
                    bool check = User32.InsertMenu(sysMenu, 4, User32.MenuFlags.MF_BYPOSITION | User32.MenuFlags.MF_POPUP, (int)hMainMenu, "Ekstra Menü");
                    if (!check)
                    {
                        goto trying2;
                    }

                    User32.InsertMenu(hMainMenu, 0, User32.MenuFlags.MF_STRING | User32.MenuFlags.MF_POPUP, (int)hPopupMenu, "C# Derleyici(Konsol)");
                    User32.InsertMenu(hPopupMenu, 0, User32.MenuFlags.MF_STRING, (int)102, "Örnek Konsol Uygulaması");
                    User32.InsertMenu(hPopupMenu, 0, User32.MenuFlags.MF_STRING, (int)103, "Örnek Konsol Uygulaması(Hesap Makinesi)");
                    User32.InsertMenu(hPopupMenu, 0, User32.MenuFlags.MF_SEPARATOR, (int)104, "");
                    User32.InsertMenu(hPopupMenu, 0, User32.MenuFlags.MF_STRING, (int)105, "Derle");
                    User32.InsertMenu(hMainMenu, 0, User32.MenuFlags.MF_STRING, (int)106, "Html Önizle");
                    User32.InsertMenu(hMainMenu, 0, User32.MenuFlags.MF_SEPARATOR, (int)107, "");
                    User32.InsertMenu(hMainMenu, 0, User32.MenuFlags.MF_STRING, (int)108, "Hakkında");

                    User32.SetMenu(handle, sysMenu);
                    User32.DrawMenuBar(handle);
                }
                this.FormClosing += new FormClosingEventHandler(delegate
                {
                    try
                    {
                        User32.UnhookWinEvent(hhook);
                        User32.RemoveMenu(sysMenu, 4, (uint)0x00000400L);
                        User32.DrawMenuBar(sysMenu);
                    }
                    catch
                    {
                    }
                });

                procDelegate = new User32.WinEventDelegate(delegate(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
                {
                    switch (idChild)
                    {
                    case 102:
                    case 103:
                        OrnekUygulama(editpoint, handle, idChild);
                        break;

                    case 105:
                        DebugKonsol(editpoint);
                        break;

                    case 106:                   //Html önizle
                        HtmlPreview(editpoint); //Not defterimizin texteditörün bellek adresini gönderiyoruz
                        break;

                    case 108:
                        User32.MessageBoxEx(handle, "Test Projesi 0x1dot tarafından hazırlanmıştır.", "Cyber-Warrior.Org", (uint)User32.MessageUType.MB_OK | (uint)User32.MessageIconType.MB_ICONINFORMATION, 0);
                        break;
                    }
                });
                hhook = User32.SetWinEventHook(EVENT_OBJECT_INVOKED, EVENT_OBJECT_INVOKED, IntPtr.Zero,
                                               procDelegate, 0, 0, WINEVENT_OUTOFCONTEXT);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }