2010-02-01 680 views
1

我想使用SendMessage/PostMessage將某些鍵發送到應用程序文本框。我使用Microsoft Spyxx來獲取此文本框的類名。現在我遇到了這個應用程序中有幾個文本框與同一個類名稱(「WindowsForms10.EDIT.app.0.2e0c681」)和相同的窗口名稱的問題。FindWindowEx - 如果存在多個具有相同類名的文本框,請選擇文本框

如何獲得正確的句柄?

PS:我編碼在C#中使用Visual C#2008 Express的

回答

0

嗯,一定是有什麼你不知道,你可以使用textboxe:比如你可以爲一個文本框搜索具有特定所有者,並檢查前面的子窗口是什麼...如果控件有標籤,可以先找到標籤,然後找到坐在它右側的控件。

0

如果不同的hWnd值返回相同的結果的API函數

[DllImport("user32.dll")] 
public static extern int GetClassNameW(HandleRef hWnd, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder className, int nMaxCount); 

[DllImport("user32.dll")] 
public static extern int GetWindowTextLength(HandleRef hWnd); 

[DllImport("user32.dll")] 
public static extern int GetWindowTextW(HandleRef hWnd, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder text, int maximum); 

你可能具有基於在實物的形式存在上的位置做你的編輯被卡住

public struct WindowPlacement { 
    public int length; 
    public int flags; 
    public int showCmd; 
    public Point minPosition; 
    public Point maxPosition; 
    public Rectangle normalPosition; 
} 

[DllImport("user32.dll")] 
public static extern bool GetWindowPlacement(HandleRef hWnd, ref WindowPlacement position); 
相關問題