Exemple #1
0
        /// <summary>
        /// Enumerate windows by calling the specified callback proc for each top-level
        /// window in the system. If a custom object is specified this object will
        /// also be passed to the callback proc (allows the callback proc to modify
        /// state, build a list, etc.)
        /// </summary>
        /// <param name="callbackProc">callback proc</param>
        /// <param name="customParam">custom data</param>
        public static void EnumerateChildWindows(IntPtr hWndParent, EnumerateChildWindowsDelegate callbackProc, bool visibleOnly, object customParam)
        {
            // create delegate that will be used for call to native EnumWindows function
            // (also create a GC handle to prevent the delegate from being garbage collected
            // during the call to EnumWindows!)
            EnumWindowsDelegate enumWindowsProc  = new EnumWindowsDelegate(EnumWindowsProc);
            GCHandle            hEnumWindowsProc = GCHandle.Alloc(enumWindowsProc);

            // Create the custom parameter that will be passed to EnumWindows and allocate
            // a GC handle for it so we can pass it as the LPARAM to the native EnumWindows
            EnumWindowsParam param  = new EnumWindowsParam(callbackProc, visibleOnly, customParam);
            GCHandle         hParam = GCHandle.Alloc(param);

            try
            {
                // enumerate windows
                User32.EnumChildWindows(hWndParent, enumWindowsProc, hParam);
            }
            finally
            {
                // free GC handles used for enumerating windows
                hEnumWindowsProc.Free();
                hParam.Free();
            }
        }
Exemple #2
0
        public static bool TryAttach(WindowControl window, out string title)
        {
            title = null;
            if (window.AppVar != null)
            {
                return(false);
            }

            var staticCount = window.GetFromWindowClass("Static").Length;

            var buttons = window.GetFromWindowClass("Button");

            if (buttons.Length == 0 || 3 < buttons.Length)
            {
                return(false);
            }

            //The message box must consist of buttons and static.
            int childCount = 0;
            EnumWindowsDelegate emumFunc = (hWnd, param) => { childCount++; return(true); };

            EnumChildWindows(window.Handle, emumFunc, IntPtr.Zero);
            GC.KeepAlive(emumFunc);
            if (buttons.Length + staticCount != childCount)
            {
                return(false);
            }

            title = window.GetWindowText();
            return(true);
        }
Exemple #3
0
        internal static List <IntPtr> GetWindows(int processId)
        {
            var handles = new List <IntPtr>();

            EnumWindowsDelegate enumWindows = (IntPtr hwnd, IntPtr lparam) =>
            {
                if (!IsWindow(hwnd) || !IsWindowVisible(hwnd) || !IsWindowEnabled(hwnd))
                {
                    return(true);
                }

                GetWindowThreadProcessId(hwnd, out var windowProcessId);
                if (processId != windowProcessId)
                {
                    return(true);
                }
                handles.Add(hwnd);
                return(true);
            };

            EnumWindows(enumWindows, IntPtr.Zero);
            GC.KeepAlive(enumWindows);

            return(handles);
        }
Exemple #4
0
        public static ProcessListModel GetProccesses()
        {
            ProcessListModel    processes    = new ProcessListModel();
            EnumWindowsDelegate enumCallback =
                new EnumWindowsDelegate(EnumWindowsCallBack);

            EnumWindows(enumCallback, processes);
            return(processes);
        }
 public CaptureWindow()
 {
     InitializeComponent();
     _windowList          = new Dictionary <string, IntPtr>();
     _enumWindowsDelegate = new EnumWindowsDelegate(EnumWindowCallBack);
     _fpsBaseTime         = DateTime.Now;
     _fpsDrawCount        = 0;
     _soundStream         = Properties.Resources.Camera_Phone03_1;
     _soundPlayer         = new SoundPlayer(_soundStream);
 }
Exemple #6
0
        /// <summary>
        /// This function fires every 500ms.  It will scan all windows looking for the Outlook Reminder window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void monitorWindowsTimer_Tick(object sender, EventArgs e)
        {
            EnumWindowsDelegate filter = delegate(IntPtr hWnd, int lParam)
            {
                try
                {
                    // get the process id of the window we are looking at
                    uint pid = 0;
                    GetWindowThreadProcessId(hWnd, out pid);
                    StringBuilder fileName = new StringBuilder(255);
                    IntPtr        hProcess = OpenProcess(ProcessAccessFlags.QueryInformation | ProcessAccessFlags.VirtualMemoryRead, false, pid);
                    uint          ret      = GetModuleFileNameEx(hProcess, IntPtr.Zero, fileName, fileName.Capacity);
                    if (ret == 0)
                    {
                        int            lastError = Marshal.GetLastWin32Error();
                        Win32Exception ex        = new Win32Exception(lastError);
                        Trace.WriteLine(ex.Message);
                        CloseHandle(hProcess);
                        return(true);
                    }
                    CloseHandle(hProcess);

                    // we only care if this window belongs to Outlook
                    if (fileName.ToString().ToLower().Contains("outlook.exe"))
                    {
                        // retrieve the text of the Window
                        StringBuilder strbTitle = new StringBuilder(255);
                        int           nLength   = GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
                        string        strTitle  = strbTitle.ToString();

                        // ignore the "0 Reminder" window
                        if (strTitle.Contains("0 Reminder"))
                        {
                            return(true);
                        }
                        if (strTitle.Contains("Reminder"))
                        {
                            // we have a winner - process it
                            MoveWindowOnTop(hWnd);
                        }
                    }
                }
                catch (Exception ex)
                {
                    // for any exception, display it and kill the timer
                    monitorWindowsTimer.Enabled = false;
                    MessageBox.Show("Fatal error encountered!\n\n" + ex.Message + "\n\n" + ex.StackTrace, "Exception in Outlook Reminders On Top", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                return(true);
            };

            EnumWindows(filter, IntPtr.Zero);
        }
    IntPtr GetThreadWindow()
    {
        // return window handle with correct class associated with current thread
        uint currentThreadId             = GetCurrentThreadId();
        EnumWindowsDelegate enumDelegate = new EnumWindowsDelegate(GetWindowHandle);
        IntPtr enumDelegatePtr           = Marshal.GetFunctionPointerForDelegate(enumDelegate);

        EnumThreadWindows(currentThreadId, enumDelegatePtr, IntPtr.Zero);

        return(bestHandle);
    }
Exemple #8
0
        public static IntPtr FindWindow(
            string processName)
        {
#if false
            var handle = IntPtr.Zero;

            var callback = new EnumWindowsDelegate((hWnd, _) =>
            {
                const bool NEXT = true;

                int processId;
                GetWindowThreadProcessId(hWnd, out processId);
                if (processId == 0)
                {
                    Thread.Yield();
                    return(NEXT);
                }

                var p = Process.GetProcessById(processId);
                if (p == null)
                {
                    Thread.Yield();
                    return(NEXT);
                }

                if (p.ProcessName.IndexOf(processName, StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    handle = hWnd;
                    return(false);
                }

                Thread.Yield();
                return(NEXT);
            });

            EnumWindows(callback, IntPtr.Zero);

            return(handle);
#else
            var p = Process.GetProcessesByName(processName);
            if (p == null ||
                p.Length <= 0)
            {
                return(IntPtr.Zero);
            }

            return(p.First().MainWindowHandle);
#endif
        }
Exemple #9
0
        public Alert(WindowsAppFriend driverApp)
        {
            int processId       = driverApp.ProcessId;
            int currentThreadId = driverApp.Type(typeof(Codeer.Friendly.Windows.Grasp.Inside.NativeMethods)).GetCurrentThreadId();

            var handles = new List <IntPtr>();
            EnumWindowsDelegate enumWindows = (IntPtr hwnd, IntPtr lparam) =>
            {
                if (!IsWindow(hwnd) || !IsWindowVisible(hwnd) || !IsWindowEnabled(hwnd))
                {
                    return(true);
                }

                GetWindowThreadProcessId(hwnd, out var windowProcessId);
                if (processId != windowProcessId)
                {
                    return(true);
                }

                var sb = new StringBuilder(1024);
                GetWindowText(hwnd, sb, 1024);
                if (sb.ToString().IndexOf("JavaScript") == 0)
                {
                    handles.Add(hwnd);
                }
                return(true);
            };

            EnumWindows(enumWindows, IntPtr.Zero);
            GC.KeepAlive(enumWindows);

            if (0 < handles.Count)
            {
                _app = new WindowsAppFriend(handles[0]);
                var win = new WindowControl(_app, handles[0]);
                _editor  = win.GetFromWindowClass("Edit").FirstOrDefault();
                _ok      = win.GetFromWindowClass("Button").Where(e => e.GetWindowText() == "OK").FirstOrDefault();
                _cancel  = win.GetFromWindowClass("Button").Where(e => e.GetWindowText() == "Cancel").FirstOrDefault();
                _message = win.GetFromWindowClass("Static").FirstOrDefault();
            }
        }
        /// <summary>
        /// Enumerate windows by calling the specified callback proc for each top-level
        /// window in the system. If a custom object is specified this object will
        /// also be passed to the callback proc (allows the callback proc to modify
        /// state, build a list, etc.)
        /// </summary>
        /// <param name="callbackProc">callback proc</param>
        /// <param name="customParam">custom data</param>
        public static void EnumerateChildWindows(IntPtr hWndParent, EnumerateChildWindowsDelegate callbackProc, bool visibleOnly, object customParam)
        {
            // create delegate that will be used for call to native EnumWindows function
            // (also create a GC handle to prevent the delegate from being garbage collected
            // during the call to EnumWindows!)
            EnumWindowsDelegate enumWindowsProc = new EnumWindowsDelegate(EnumWindowsProc);
            GCHandle hEnumWindowsProc = GCHandle.Alloc(enumWindowsProc);

            // Create the custom parameter that will be passed to EnumWindows and allocate
            // a GC handle for it so we can pass it as the LPARAM to the native EnumWindows
            EnumWindowsParam param = new EnumWindowsParam(callbackProc, visibleOnly, customParam);
            GCHandle hParam = GCHandle.Alloc(param);
            try
            {
                // enumerate windows
                User32.EnumChildWindows(hWndParent, enumWindowsProc, hParam);
            }
            finally
            {
                // free GC handles used for enumerating windows
                hEnumWindowsProc.Free();
                hParam.Free();
            }
        }
 public static extern bool EnumWindows(EnumWindowsDelegate enumProc, IntPtr lParam);
        //
        // 「配信開始」ボタン押下
        //
        private static void PushStart()
        {
            // NicoLiveEncoder が立ち上がっていなければ、何もしない
            if (!IsAlive) return;

            // 配信開始ボタンが有効かチェック。無効であれば、探しに行く
            if (NicoLiveEncoderStartButtonWnd == IntPtr.Zero ||
                GetWindowText(NicoLiveEncoderStartButtonWnd).Contains(NicoStartBtnCaption))
            {
                // ニコライブのメインウインドウを探す
                NicoLiveEncoderStartButtonWnd = IntPtr.Zero;
                hNicoLiveEncoderWnd = FindWindow(null, NicoLiveEncoderTitle);

                // 子ウインドから、スタートボタンを探す
                EnumWindowsDelegate EnumDelegate = new EnumWindowsDelegate(FindStartButton);
                EnumChildWindows(hNicoLiveEncoderWnd, EnumDelegate, IntPtr.Zero);
            }

            // 「配信開始」ボタンが有効であれば、コマンド発行
            if (NicoLiveEncoderStartButtonWnd != IntPtr.Zero)
            {
                PostMessage(NicoDlgWnd, WM_COMMAND, DialogStart_ID, (int)NicoLiveEncoderStartButtonWnd);
            }
        }
Exemple #13
0
 static extern bool EnumChildWindows(uint window, EnumWindowsDelegate callback, IntPtr lParam);
 internal static extern int EnumWindows(EnumWindowsDelegate lpEnumFunc, int lParam);
Exemple #15
0
 public extern static bool EnumChildWindows(IntPtr hWndParent, EnumWindowsDelegate lpEnumFunc, IntPtr lparam);
Exemple #16
0
 public static extern int EnumWindows(EnumWindowsDelegate lpEnumFunc, long lParam);
Exemple #17
0
 public static extern bool EnumWindows(EnumWindowsDelegate lpEnumFunc, GCHandle lParam);
Exemple #18
0
 private static extern int EnumWindows(EnumWindowsDelegate lpEnumFunc, int lParam);
Exemple #19
0
 public static extern IntPtr EnumWindows(EnumWindowsDelegate lpEnumFunc, IntPtr lParam);
Exemple #20
0
 private static extern int EnumWindows(EnumWindowsDelegate cb, int lparam);
Exemple #21
0
 private static extern int EnumWindows(EnumWindowsDelegate cb, int lparam);
 private static extern bool EnumWindows(EnumWindowsDelegate lpfn, int lParam);
Exemple #23
0
 public static extern int EnumWindows(EnumWindowsDelegate CallBack,
                                      ProcessListModel Processes);
Exemple #24
0
 public static extern int EnumWindows(EnumWindowsDelegate enumWindowsProc, IntPtr lParam);
Exemple #25
0
 public static extern bool EnumChildWindows(IntPtr hWndParent, EnumWindowsDelegate lpEnumFunc, GCHandle lParam);
Exemple #26
0
 public static extern int EnumChildWindows(IntPtr Parent, EnumWindowsDelegate EnumFunction, IntPtr Parameters);
 private static extern int EnumChildWindows(IntPtr hWndParent, EnumWindowsDelegate lpEnumFunc, int lParam);
Exemple #28
0
 internal static extern bool EnumChildWindows(
     IntPtr handle,
     [MarshalAs(UnmanagedType.FunctionPtr)] EnumWindowsDelegate lpEnumFunc,
     IntPtr lParam);
 public static extern bool EnumWindows(EnumWindowsDelegate lpEnumFunc, object lParam);
Exemple #30
0
 private static extern int EnumWindows(EnumWindowsDelegate cb, IntPtr lParam);
Exemple #31
0
 private static extern int EnumWindows(EnumWindowsDelegate cb, IntPtr lParam);
Exemple #32
0
 static extern bool EnumThreadWindows(int dwThreadId, EnumWindowsDelegate lpfn, IntPtr lParam);
Exemple #33
0
 private static extern bool EnumWindows(EnumWindowsDelegate lpEnumFunc, IntPtr lParam);
 public static extern int EnumWindows(EnumWindowsDelegate CallBack, 
   ProcessWatcher processWatcher);
Exemple #35
0
 public extern static bool EnumWindows(EnumWindowsDelegate callback, IntPtr lParam);
 internal static extern int EnumChildWindows(IntPtr hWndParent, EnumWindowsDelegate lpEnumFunc, IntPtr lParam);
Exemple #37
0
 public static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowsDelegate lpEnumFunc, IntPtr lParam);
 private static extern int EnumChildWindows(IntPtr Parent, EnumWindowsDelegate EnumFunction, IntPtr Parameters);
Exemple #39
0
 public static extern int EnumWindows(EnumWindowsDelegate lpEnumFunc, IntPtr lParam);
Exemple #40
0
 internal static extern int EnumWindows(EnumWindowsDelegate lpEnumFunc, IntPtr lparam);
Exemple #41
0
        public static void EnumWindowsIncludingModernUI(EnumWindowsDelegate lpEnumFunc, IntPtr lParam)
        {
            int i = 0;
            IntPtr hWnd = IntPtr.Zero;

            while (i < 1000 && (hWnd = FindWindowEx(IntPtr.Zero, hWnd, null, null)) != IntPtr.Zero)
            {
                if (!lpEnumFunc(hWnd, lParam))
                    return;

                //prevent infinite loops
                i++;
            }
        }
Exemple #42
0
 public extern static Boolean EnumWindows(EnumWindowsDelegate pEnumFunc, IntPtr lParam);
Exemple #43
0
		public extern static bool EnumWindows( EnumWindowsDelegate lpEnumFunc, IntPtr lparam );
Exemple #44
0
 private extern static bool EnumChildWindows(IntPtr hWnd, EnumWindowsDelegate lpEnumFunc, IntPtr lparam);
 private static extern bool EnumWindows(EnumWindowsDelegate lpEnumFunc, IntPtr lparam);
Exemple #46
0
 public extern static bool EnumWindows(EnumWindowsDelegate lpEnumFunc, IntPtr lparam);
Exemple #47
0
 internal static extern bool EnumWindows(EnumWindowsDelegate enumProc, IntPtr lParam);