For our software testing we have a test that lets us check to see if certain windows are open using the FindWindowByClassNameAndRegex P/Invoke call. The issue we’re getting is when we have windows open with more than a certain number of special characters we always get IntPtr.Zero as a return. Are there any known issues with this? Here’s some of the code we use to find the window: (in this case it’s for a firefox window)
Regex windowTitleRegex = new Regex(Regex.Escape(fullWindowTitle).Replace("\?", "."), RegexOptions.IgnoreCase | RegexOptions.ECMAScript);
curWindowHandle = NativeMethods.FindWindowByClassNameAndRegex("MozillaUIWindowClass", windowTitleRegex);
Where the title of the window is ~`!@#$%^&*()_-+={[}]|:;'<,>.?/\"àëÉùÙâÏûâÏûÊÛçîÀË«éïÂλœÇÔêôÈŒ\
(There’s no actual line break it’s just a formatting thing)
There is no Windows API function by that name. I’m guessing you’ve found some DLL that exports this function. Odds are always good that the regex this DLL uses is of some kind that doesn’t quite match the syntax that .NET’s Regex class uses. There are a lot of dialects.
Best thing to do is to pinvoke EnumWindows(). You can use your own Regex in the callback to filter, GetClassName() gets you the window class name. If you already know the window name then just use FindWindow().