A
A
Aleksandr2018-08-15 03:34:25
API
Aleksandr, 2018-08-15 03:34:25

How to find windows by title or executable file?

You need to programmatically press the Enter button on certain running windows.
those. you need to find a window by title or by executable file, emulate pressing the Enter button, and so on with each window. How to do it? =)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
mshak, 2018-08-15
@mshak

There is no built-in sharp, but there is a Win32 api

[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

#
#, 2018-08-15
@mindtester

1 - find window, get handle (duplicate of colleague's answer, though)

[DllImport("USER32.DLL", CharSet = CharSet.Auto)]
        internal static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

2 - send "enterer" ... and here everything can be simple, or not quite
simple SendKeys did not suit me (long story, but you can start with it))
"/"save file" - you need a "class" message receiver, and its entire hierarchy, starting with the handle (dialog, in my case) (you will need the tool https://social.msdn.microsoft.com/Forums/vstudio/e. .. example to save
"Save Table".hWndByTitle().setTitle(csvDlg).waitForIdle().sendString(
                new string[] {
                    "DUIViewWndClassName",
                    "DirectUIHWND",
                    "FloatNotifySink",
                    "ComboBox",
                    "Edit" },
                csv);

sendString implementation
internal static IntPtr sendString(this IntPtr hWnd, string[] classNames, string msg, bool verb = false)
        {
            var hCtrl = hWnd;
            if (classNames != null && classNames.Count() > 0)
            {
                Thread.Sleep(to[toFileStdDlg]);
                foreach (var c in classNames)
                {
                    Thread.Sleep(to[toFileStdDlg]);
                    hCtrl = user32.FindWindowEx(hCtrl, IntPtr.Zero, c, null);
                    if (hCtrl.Equals(IntPtr.Zero))
                    {
                        $"\tERROR :: sendString not found class {c}".log();
                        return hWnd;
                    }
                    else
                        hCtrl.waitForIdle();
                }
            }
            for (int i = 0; i < msg.Length; i++)
                user32.PostMessage(hCtrl, WM_CHAR, msg[i], 0);

            Thread.Sleep(to[toFileStdDlg]);
            user32.PostMessage(hWnd, WM_KEYDOWN, user32.VkKeyScan('\r'), 0);
            user32.PostMessage(hWnd, WM_KEYUP, user32.VkKeyScan('\r'), 0);
            return hWnd;
        }

A
Artem @Jump, 2018-08-15
curated by the

How to find windows by title
FindWindowByTitle

P
pxaJJ, 2018-08-19
@pxaJJ

nircmd.exe

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question