예제 #1
0
        public static List <int> GetProcessIdByWindowByTitle(string sProcessName, string sTitle, bool bWholeWord)
        {
            List <int> piList = new List <int>();
            Process    ps     = null;

            if (sTitle == null)
            {
                sTitle = "";
            }

            foreach (KeyValuePair <IntPtr, string> window in WindowList.GetOpenWindows())
            {
                IntPtr handle = window.Key;
                string title  = window.Value;

                if (sProcessName != "")   //input에 processName이 있으면 process name 일치 여부를 먼저 체크
                {
                    uint pid = 0;
                    GetWindowThreadProcessId(handle, out pid);
                    ps = Process.GetProcessById((int)pid);

                    if (ps.ProcessName != sProcessName)
                    {
                        continue;
                    }
                }

                if (bWholeWord)
                {
                    if (title == sTitle)
                    {
                        piList.Add(ps.Id);
                    }
                }
                else
                {
                    if (title.Contains(sTitle))
                    {
                        piList.Add(ps.Id);
                    }
                }
            }

            return(piList);
        }
예제 #2
0
        public static HWND FindWindowByTitle(string sProcessName, string sTitle, bool bWholeWord)
        {
            foreach (KeyValuePair <IntPtr, string> window in WindowList.GetOpenWindows())
            {
                IntPtr handle = window.Key;
                string title  = window.Value;

                if (sProcessName != "")   //input에 processName이 있으면 process name 일치 여부를 먼저 체크
                {
                    uint pid = 0;
                    GetWindowThreadProcessId(handle, out pid);
                    Process ps = Process.GetProcessById((int)pid);

                    if (ps.ProcessName != sProcessName)
                    {
                        continue;
                    }
                }

                if (bWholeWord)
                {
                    if (title == sTitle)
                    {
                        return(handle);
                    }
                }
                else
                {
                    if (title.Contains(sTitle))
                    {
                        return(handle);
                    }
                }
            }

            return(IntPtr.Zero);
        }