나는 그들의 이름/비밀번호/도메인에 대한 사용자하라는 메시지를 표시하는 애플리케이션에 싱글 사인온 (SSO)을 수행 할 수 년 동안이 성공적으로 같은 코드를 사용하고있다. 주의 할 점은 대상으로 삼고있는 대화 상자의 제어 구조를 알아야한다는 것입니다. 그러나 이것은 Spy ++로 쉽게 수행 할 수 있으며 거의 변경되지 않습니다. 물론 윈도우의 컨트롤 구조에 맞게이 코드를 수정해야합니다.
[DllImport("user32.dll")]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter,
string lpszClass, string lpszWindow);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, string lParam);
[DllImport("User32.Dll")]
public static extern IntPtr PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
private const uint WM_GETTEXTLENGTH = 0x000E;
private const uint WM_SETTEXT = 0x000C;
private const uint WM_GETTEXT = 0x000D;
private const uint BM_CLICK = 0x00F5;
private const uint WM_CLOSE = 0x0010;
enum GetWindow_Cmd : uint
{
GW_HWNDFIRST = 0,
GW_HWNDLAST = 1,
GW_HWNDNEXT = 2,
GW_HWNDPREV = 3,
GW_OWNER = 4,
GW_CHILD = 5,
GW_ENABLEDPOPUP = 6
}
var dialog FindWindow("optionalClassNameHere", "Log On"); //Get the handle of the window
var w3 = GetWindow(dialog , (uint)GetWindow_Cmd.GW_CHILD); //I use GetWindow to walk the window controls
var wUid = FindWindowEx(w3, IntPtr.Zero, "Edit", "");
var w4 = GetWindow(wUid, (uint)GetWindow_Cmd.GW_HWNDNEXT);
var wPwd = FindWindowEx(w4 , IntPtr.Zero, "Edit", "");
var wOK = FindWindowEx(w3, IntPtr.Zero, "Button", "OK");
SendMessage(wUid, WM_SETTEXT, 0, _WinDomain + "\\" + Username); //Send username to username edit control
SendMessage(wPwd, WM_SETTEXT, 0, Password); //Send password to password edit control
PostMessage(wOK, BM_CLICK, 0, 0); //Send left click(0x00f5) to OK button
Windows 메시지 처리의 복잡성을 숨기려면 흰색과 같은 UI 자동화 프레임 워크를 사용해 보셨습니까? (http://code.google.com/p/white-project/) 여기에서 예제를 찾을 수 있습니다 : http://scip.be/index.php?Page=ArticlesNET19&Lang=NL –
시도했습니다. 예외가 있습니다. Castle.Proxies.Win32ComboBoxProxy에서 캐스팅 할 수 없습니다. 캐스팅을 시도 할 때. –