Exemple #1
0
    /// <summary>
    /// entry point of the program
    /// </summary>
    public static List <string> GetWindowTitles()
    {
        var collection = new List <string>();

        User32.EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
        {
            StringBuilder strbTitle = new StringBuilder(255);
            int           nLength   = User32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
            string        strTitle  = strbTitle.ToString();

            if (User32.IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false)
            {
                collection.Add(strTitle);
            }
            return(true);
        };

        if (User32.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero))
        {
            return(collection);
        }
        else
        {
            return(null);
        }
    }
Exemple #2
0
        private List <SecurityDialog> GetSecurityDialogs(Process[] outlookProcess)
        {
            _listDialogs.Clear();

            User32.EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
            {
                User32.GetClassName(hWnd, _strbClassName, _strbClassName.Capacity + 1);
                string className = _strbClassName.ToString();

                User32.GetWindowText(hWnd, _strbCaption, _strbCaption.Capacity + 1);
                string caption = _strbCaption.ToString();

                if (("#32770" == className.ToString()) && (User32.IsWindowVisible(hWnd)))
                {
                    uint processID = 0;
                    User32.GetWindowThreadProcessId(hWnd, out processID);
                    foreach (Process process in outlookProcess)
                    {
                        if (processID == process.Id)
                        {
                            User32.RECT rect = new User32.RECT();
                            User32.GetWindowRect(hWnd, out rect);
                            _listDialogs.Add(new SecurityDialog(hWnd, caption, className, new Rect(rect)));
                            break;
                        }
                    }
                }
                return(true);
            };

            User32.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero);
            return(_listDialogs);
        }
Exemple #3
0
        private Dictionary <SecurityDialog, DateTime> GetSecurityDialogs(Process[] outlookProcess)
        {
            Dictionary <SecurityDialog, DateTime> local = new Dictionary <SecurityDialog, DateTime>();

            User32.EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
            {
                User32.GetClassName(hWnd, _strbClassName, _strbClassName.Capacity + 1);
                string className = _strbClassName.ToString();

                User32.GetWindowText(hWnd, _strbCaption, _strbCaption.Capacity + 1);
                string caption = _strbCaption.ToString();

                if ((_dialogClassName == className.ToString()) && (User32.IsWindowVisible(hWnd)))
                {
                    uint processID = 0;
                    User32.GetWindowThreadProcessId(hWnd, out processID);
                    foreach (Process process in outlookProcess)
                    {
                        if (processID == process.Id)
                        {
                            User32.RECT rect = new User32.RECT();
                            User32.GetWindowRect(hWnd, out rect);
                            local.Add(new SecurityDialog(hWnd, caption, className, new Rect(rect)), DateTime.Now);
                            break;
                        }
                    }
                }
                return(true);
            };
            User32.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero);

            foreach (KeyValuePair <SecurityDialog, DateTime> item in local)
            {
                SecurityDialog existing = GetDialogFromHandle(_listDialogs, item.Key.Handle);
                if (null == existing)
                {
                    _listDialogs.Add(item.Key, item.Value);
                }
            }

            List <SecurityDialog> toDelete = new List <SecurityDialog>();

            foreach (KeyValuePair <SecurityDialog, DateTime> item in _listDialogs)
            {
                SecurityDialog existing = GetDialogFromHandle(_listDialogs, item.Key.Handle);
                if (null == existing)
                {
                    toDelete.Add(item.Key);
                }
            }
            foreach (SecurityDialog item in toDelete)
            {
                _listDialogs.Remove(item);
            }

            return(_listDialogs);
        }
 private void GetDesktopWindowsTitlesToPrivateVar()
 {
     try
     {
         User32.EnumDelegate delEnumfunc = new User32.EnumDelegate(EnumWindowsProc);
         bool bSuccessful = User32.EnumDesktopWindows(IntPtr.Zero, delEnumfunc, IntPtr.Zero); //for current desktop
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
         Application.Exit();
     }
 }
Exemple #5
0
        private void GetAllVisibleWindows()
        {
            User32.EnumDelegate _enumfunc = EnumWindowsProc;
            IntPtr _hDesktop = IntPtr.Zero; // current desktop
            bool   _success  = User32.EnumDesktopWindows(_hDesktop, _enumfunc, IntPtr.Zero);

            if (!_success)
            {
                // Get the last Win32 error code
                int _errorCode = Marshal.GetLastWin32Error();

                string _errorMessage = String.Format("EnumDesktopWindows failed with code {0}.", _errorCode);
                throw new Exception(_errorMessage);
            }
        }
Exemple #6
0
    public static void AlwaysOnTop(string titlePart)
    {
        User32.EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
        {
            StringBuilder strbTitle = new StringBuilder(255);
            int           nLength   = User32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
            string        strTitle  = strbTitle.ToString();

            if (User32.IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false)
            {
                if (strTitle.Contains(titlePart))
                {
                    SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
                }
            }
            return(true);
        };

        User32.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero);
    }
Exemple #7
0
        public void GetPic()
        {
            var collection = new List <string>();

            User32.EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
            {
                StringBuilder strbTitle = new StringBuilder(255);
                int           nLength   = User32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
                string        strTitle  = strbTitle.ToString();

                if (User32.IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false)
                {
                    collection.Add(strTitle);
                }
                return(true);
            };

            if (User32.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero))
            {
                foreach (var item in collection)
                {
                    if (item.Contains("[") && item.StartsWith("MAME:"))
                    {
                        string output  = item.Substring(item.IndexOf('[') + 1);
                        string value2  = output;
                        string romname = value2;
                        //string line;
                        string currentLine  = string.Empty;
                        string previousLine = string.Empty;

                        int index1 = value2.IndexOf("]");

                        if (index1 != -1)
                        {
                            romname = value2.Remove(index1, 1); // Use integer from IndexOf.
                        }
                        pictureBox1.ImageLocation = (Application.StartupPath + "\\romname" + "\\" + romname + ".png");
                    }
                }
            }
        }
Exemple #8
0
    public static void RemoveAlwaysOnTop()
    {
        User32.EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
        {
            StringBuilder strbTitle = new StringBuilder(255);
            int           nLength   = User32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
            string        strTitle  = strbTitle.ToString();

            if (!string.IsNullOrEmpty(strTitle))
            {
                WINDOWPLACEMENT placement = GetPlacement(hWnd);
                if (placement.showCmd == SW_SHOWNORMAL)     // Normal
                {
                    SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
                }
            }
            return(true);
        };

        User32.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero);
    }
        public void GetScore()
        {
            var collection = new List <string>();

            User32.EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
            {
                StringBuilder strbTitle = new StringBuilder(255);
                int           nLength   = User32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
                string        strTitle  = strbTitle.ToString();

                if (User32.IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false)
                {
                    collection.Add(strTitle);
                }
                return(true);
            };

            if (User32.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero))
            {
                foreach (var item in collection)
                {
                    if (item.Contains("["))
                    {
                        string output  = item.Substring(item.IndexOf('[') + 1);
                        string value2  = output;
                        string romname = value2;

                        string currentLine  = string.Empty;
                        string previousLine = string.Empty;

                        int index1 = value2.IndexOf("]");

                        if (index1 != -1)
                        {
                            romname = value2.Remove(index1, 1);  // Use integer from IndexOf.
                        }

                        string[] lines = File.ReadAllLines(Application.StartupPath + "\\" + "HighScores.txt");
                        int      i     = 0;

                        var Scoreitems = from line in lines
                                         where i++ != -1
                                         //let words = line.Split('|')
                                         select new
                        {
                            rom   = line.Split('|')[0],
                            date  = line.Split('|')[1],
                            name  = line.Split('|')[2],
                            score = line.Split('|')[3]
                        };
                        foreach (var line in Scoreitems)
                        {
                            //if (line.rom.Contains(romname))
                            if (line.rom == romname)
                            {
                                try
                                {
                                    // lblScore.Text = line.score.ToString();

                                    lblScore.Invoke((Action)(() => lblScore.Text = line.score.ToString()));
                                    //label2.Text = line.rom.ToString();
                                    label2.Invoke((Action)(() => label2.Text = line.rom.ToString()));
                                    //lblDate.Text = line.date.ToString();
                                    lblDate.Invoke((Action)(() => lblDate.Text = line.date.ToString()));
                                    //lblName.Text = line.name.ToString();
                                    lblName.Invoke((Action)(() => lblName.Text = line.name.ToString()));
                                    //lblNotFound.Text = " ";
                                    lblNotFound.Invoke((Action)(() => lblNotFound.Text = " "));
                                }
                                catch (InvalidOperationException e)
                                {
                                    MessageBox.Show(e.Message);
                                }
                            }