Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9044339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:57:39+00:00 2026-06-16T10:57:39+00:00

I am ultimately trying to write something that will check if a specific window

  • 0

I am ultimately trying to write something that will check if a specific window exists, and set it as active in the event it is.
I was able to use FindWindow to find a literal windows name.

int hWnd = FindWindow(null, "121226-000377 - company -  Oracle RightNow CX Cloud Service");
            if (hWnd > 0) //If found
            {
                SetForegroundWindow(hWnd); //Activate it

            }
            else
            {
                MessageBox.Show("Window Not Found!");
            }

The number at the front of the title changes and will never be the same twice, therefor I was trying to use Regular Expressions to find if any active window has the name structure as shown above but the numbers can change. I have a regular expresion that works for this, but I don’t know how to implement it. I tried:

int hWnd = FindWindow(null, @"^\d+-\d+\s.*?RightNow CX");
            if (hWnd > 0) //If found
            {
                SetForegroundWindow(hWnd); //Activate it

            }
            else
            {
                MessageBox.Show("Window Not Found!");
            }

But it continually fails. So how do I use the FindWindow/SetForegroundWindow commands while making them use the regular expression to check with?

UPDATE~~~~
I selected a best answer, but here is the actual code for how I got this to work in case anyone is interested.

   protected static bool EnumTheWindows(IntPtr hWnd, IntPtr lParam)
        {
            int size = GetWindowTextLength(hWnd);
            if (size++ > 0 && IsWindowVisible(hWnd))
            {
                StringBuilder sb = new StringBuilder(size);
                GetWindowText(hWnd, sb, size);

                Match match = Regex.Match(sb.ToString(), @"^\d+-\d+\s.*?RightNow CX",
               RegexOptions.IgnoreCase);


                // Here we check the Match instance.
                if (match.Success)
                {
                   ActivateRNT(sb.ToString());

                }
                else
                {
                    //this gets triggered for every single failure
                }
                //do nothing


            }
            return true;
        }

private static void ActivateRNT(string rnt)
        {
            //Find the window, using the CORRECT Window Title, for example, Notepad

            int hWnd = FindWindow(null, rnt);
            if (hWnd > 0) //If found
            {
                SetForegroundWindow(hWnd); //Activate it

            }
            else
            {
                MessageBox.Show("Window Not Found!");
            }

        }

I still need to figure out how to test in the EnumWindows method to throw an alert if the window needed doesn’t exist, but I’ll worry about that at a later time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:57:41+00:00Added an answer on June 16, 2026 at 10:57 am

    I guess EnumWindows() is what you’re looking for, although I’m not 100% sure how you’d use it in C# as you’ll need a callback.

    Edit: pinvoke.net got some code including an example callback.
    Edit 2: The linked [MSDN sample][3] has more details on why/how to do it that way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a method in C# that will return the difference between
I'm trying to write a regex expression that will take this phrase [[32, 120],
I'm trying to write a sed script that will capture all naked URL's in
Ultimately I'm trying to write out a range into a text file. When I
I am trying to use FileHelper library for parsing a text file. Ultimately the
I am designing/developing a web application that will ultimately deploy as a WAR to
This is a very odd, and quite specific question. Ultimately I am trying to
I am trying to write syntax that checks for group membership based on a
I'm trying to write a regex to match entries in delimited files that have
I am trying to write a function that imports an .AVI file and returns

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.