我從 http://improve.dk/archive/2007/04/07/finding-specific-windows.aspx找到一個可見的按鈕
「偷」的代碼,但不是寫的類名,標題和處理到我要檢查,如果某個按鈕是可見的控制檯。如果按鈕是可見的我想最大化窗口。
我改變了這部分=>
private static bool foundWindow(int handle)
{
bool buttonCheck = false;
IntPtr hButton = FindWindowEx((IntPtr)handle, IntPtr.Zero, "AfxWnd90u21", null);
if (hButton != IntPtr.Zero)
{
buttonCheck = true;
}
if (buttonCheck)
{
ShowWindowAsync(handle, (int)3); // maximize the window
}
return true;
}
the button class is `AfxWnd90u` and the instance is `21`. I wrote this in autoit before and AfxWnd90u21 is 100 % correct.
the problem is that i cant find the button with AfxWnd90u21. if i only use
IntPtr hButton = FindWindowEx((IntPtr)handle, IntPtr.Zero, "AfxWnd90u", null);
all windows get maximized.
It has to be something with the instance.
i hope you can help me,
thanks
最新編輯 我只是想用 「GetClassName」 找到的類名。我發現每個句柄有190個課,但是我需要的課不在那裏。 IAM真的絕望 我希望有人能幫助我, 感謝
private static bool foundWindow(int handle)
{
int i = 0;
IntPtr hWnd = (IntPtr)handle;
// System.Windows.Forms.Control control = System.Windows.Forms.Control.FromHandle(hWnd);
StringBuilder sbClass = new StringBuilder(256);
while (hWnd != IntPtr.Zero)
{
++i;
///////////////////////////////////////////////////
////////////// Compare if the classname exists/////
GetClassName((int)hWnd, sbClass, sbClass.Capacity);
if (sbClass.ToString().Equals("AfxWnd90u21"))
{
MessageBox.Show(sbClass.ToString());
}
///////////////////////////////////////////////////
////// trying to find the correct class with findwindowEX//////////
IntPtr hButton = FindWindowEx(hWnd, IntPtr.Zero, "AfxWnd90u21", null);
if (hButton != IntPtr.Zero)
{
MessageBox.Show("true");
ShowWindowAsync(handle, (int)2); // maximize the window
}
hWnd = FindWindowEx(IntPtr.Zero, hWnd, null, null);
}
MessageBox.Show(""+i);
return true;
}
謝謝, 我試圖迭代兒童,但它沒有奏效。你能給我一個例子嗎?給控件添加一個句柄,並通過它的成員迭代它? 我剛剛發現這@MSDN:http://msdn.microsoft.com/en-us/library/ms908149.aspx sry,但我完全混淆 – 2012-01-13 15:28:45
@MaikKlein更新 – 2012-01-13 15:52:26
好吧, 但我仍然有點困惑。我得到了類型轉換System.Windows.Forms.Control control = System.Windows.Forms.Control.FromHandle(hWnd); 我檢查了控件的所有成員函數,唯一可以幫助的函數是control.contains,但它需要一個控件作爲參數 我如何用控件對象來檢查類? 或者我可以檢查您之前發佈的「lpszWindow」類嗎? – 2012-01-13 21:59:25