我对两者都使用相同的句柄,但收到不同的结果。
我的代码:
[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 \ Suleman \ Desktop \ SocketService \ DataReport \ DataReport \ bin \ Debug \ DataReport.vshost.exe
但是如果句柄相同,这怎么可能不同?我的目标框架是.NET 3.5