1

私はこのコードを得ました:

using System.Runtime.InteropServices;

[DllImportAttribute("User32.dll")]
private static extern int FindWindow(String ClassName, String WindowName);
[DllImport("User32")]
private static extern int ShowWindow(int hWnd, int nCmdShow);
private const int SW_HIDE = 0;


int hWnd = FindWindow(null, Microsoft Excel - Book1);
if (hWnd > 0)
{
    ShowWindow(hWnd, SW_HIDE);
}

しかし、OpenOffice.org で Book1 を開いていることがあります。私の質問は、どうすれば異なるウィンドウ タイトルを SW_HIDE できるのでしょうか?

Microsoft Excel - Book1 タイトルが存在する場合

Book1 - OpenOffice.org Calc タイトルが存在する場合

Windowsのタイトル部分「Book1」を見つけることができるかもしれません

どうもありがとうございました!

4

1 に答える 1

0

以下のコードを使用して、開いているすべてのウィンドウのリストを取得します。

[DllImport("user32.dll")]
        static extern bool EnumWindows(EnumDelegate lpfn, IntPtr lParam);

次に、デリゲート関数を次のように記述します。

public string[] win_List = new string[50];
int i = 0;
public bool lpfn(IntPtr hWnd, int lParam)
{
    StringBuilder stbrTitle = new StringBuilder(255);
    int titleLength = GetWindowText(hWnd, stbrTitle, stbrTitle.Capacity + 1);
    string strTitle = stbrTitle.ToString();
    if (IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false)
    {
        win_List[i++] = strTitle;                      
    }
    return true;
}


public string[] GetWinList()
{
    EnumDelegate del_fun = new EnumDelegate(lpfn);
    EnumWindows(del_fun, IntPtr.Zero);
    return win_List;
}
于 2014-06-05T10:03:31.423 に答える