C # GetWindowModuleFileName и GetWindowText дают результаты разных дескрипторов - PullRequest
0 голосов
/ 02 июля 2018

Я использую один и тот же маркер для обоих, но получаю разные результаты.

Мой код:

    [DllImport("user32.dll")]
    static extern IntPtr GetForegroundWindow();

    [DllImport("user32.dll")]
    static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);



    private string GetActiveWindowTitle()
    {
        const int nChars = 256;
        StringBuilder Buff = new StringBuilder(nChars);
        IntPtr handle = GetForegroundWindow();

        if (GetWindowText(handle, Buff, nChars) > 0)
        {
            return Buff.ToString();
        }
        return null;
    }

    [DllImport("user32.dll")]
    static extern IntPtr GetWindowModuleFileName(IntPtr hWnd, StringBuilder text, uint count);

    private string GetActiveWindowName()
    {
        const uint nChars = 256;
        StringBuilder Buff = new StringBuilder((int)nChars);
        IntPtr handle = GetForegroundWindow();

        if (GetWindowModuleFileName(handle, Buff, nChars) > 0)
        {
            return Buff.ToString();
        }
        return Buff.ToString();

    }

Мой вывод:

Для GetWindowText: Почтальон

Для GetWindowModuleFileName: C: \ Users \ Сулеман \ Desktop \ SocketService \ DataReport \ DataReport \ Bin \ Debug \ DataReport.vshost.exe

Но как это может отличаться, если ручка одинакова? Моя целевая среда: .NET 3.5

...