gtzpower Posted March 10, 2004 Posted March 10, 2004 I am coding in c# and I can not get the AccessibleObjectFromWindow API to work (and provide a useable object) for the life of me. You know you're in trouble when you search google, and EVERY result is purple instead of blue (indicating you have clicked them already) I have tried sooooooooooooooo many different snippets of code and I am not having any luck. Please help if you can! I'll even PayPal ya $5 (maybe more) if you can help me get it working! TIA Quote
Leaders dynamic_sysop Posted March 10, 2004 Leaders Posted March 10, 2004 here's link to a topic about it ... Link on CodeGuru not sure if that'll help ( it's in C# ) Quote
gtzpower Posted March 17, 2004 Author Posted March 17, 2004 Here's my source code: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Runtime.InteropServices; using System.Text; using Accessibility; namespace AccessibilityApp { /// <summary> /// Summary description for WinForm. /// </summary> public class WinForm : System.Windows.Forms.Form { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; private System.Windows.Forms.Button testButton; (System.Object childID); public WinForm() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose (bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.testButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // // testButton // this.testButton.Location = new System.Drawing.Point(56, 32); this.testButton.Name = "testButton"; this.testButton.Size = new System.Drawing.Size(176, 64); this.testButton.TabIndex = 0; this.testButton.Text = "Test"; this.testButton.Click += new System.EventHandler(this.testButton_Click); // // WinForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.Add(this.testButton); this.Name = "WinForm"; this.Text = "WinForm"; this.ResumeLayout(false); } #endregion ///Declare APS's and Constants delegate bool EnumWindowsCallback(IntPtr hWnd, int lParam); [DllImport("user32.dll")] static extern int EnumWindows(EnumWindowsCallback callback, int lParam); delegate bool EnumChildWindowsCallback(IntPtr hWnd, int lParam); [DllImport("user32.dll")] static extern int EnumChildWindows(IntPtr hWnd, EnumChildWindowsCallback callback, int lParam); [DllImport("user32.dll")] public static extern void GetWindowText(IntPtr hWnd, System.Text.StringBuilder lpWndTxt, int nMaxCount); [DllImport("oleacc.dll",CharSet=CharSet.Auto)] public static extern IntPtr AccessibleObjectFromWindow (IntPtr hwnd, uint dwId, UUID riid, out IAccessible ppvObject); IntPtr notepadWindow; /// <summary> /// The main entry point for the application. /// </summary> [sTAThread] static void Main() { Application.Run(new WinForm()); } private void testButton_Click(object sender, System.EventArgs e) { EnumWindows(new EnumWindowsCallback(checkHWND), 0); if(notepadWindow.ToInt32() != 0) EnumChildWindows(notepadWindow, new EnumChildWindowsCallback(findChildWin),0); } private bool checkHWND(IntPtr hWnd, int lParam) { int n = 18; System.Text.StringBuilder wndText = new System.Text.StringBuilder(n); GetWindowText(hWnd, wndText,n + 1); if(wndText.ToString() == "Untitled - Notepad") notepadWindow = hWnd; return true; } private bool findChildWin(IntPtr hWnd, int lParam) { UUID uuidAccessible = new UUID(); uuidAccessible.data1 = 0x618736e0; uuidAccessible.data2 = 0x3c3d; uuidAccessible.data3 = 0x11cf; uuidAccessible.data4 = new byte[8]; uuidAccessible.data4[0] = 0x81; uuidAccessible.data4[1] = 0xc; uuidAccessible.data4[2] = 0x0; uuidAccessible.data4[3] = 0xaa; uuidAccessible.data4[4] = 0x0; uuidAccessible.data4[5] = 0x38; uuidAccessible.data4[6] = 0x9b; uuidAccessible.data4[7] = 0x71; IAccessible accObj; AccessibleObjectFromWindow(hWnd,0x00000000,uuidAccessible,out accObj); MessageBox.Show(accObj.ToString()); accObj.accValue = "5"; testButton.Text = Accessibility.IAccessible.get_accValue(System.Object ); return true; } } } [structLayout(LayoutKind.Sequential)] public class UUID { public int data1; public short data2; public short data3; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]public byte[] data4; } These 2 lines are causing problems compiling: accObj.accValue = "5"; testButton.Text = Accessibility.IAccessible.get_accValue(0); The first line says that the property is not supported be the language, and recommends using the Accessibility.IAccessible.get_accValue(object);. The second says that an object reference is required for the non-static method. On this site (in the private methods section): http://www.dotnet247.com/247reference/System/Windows/Forms/AccessibleObject/__members I can use any of the methods or access them as properties of accObj as long as they don't have anything in the ()'s as they appear on the site (the object reference???) like accObj.getChildCount works fine and returns a numerical value. Maybe this is a lead to fixing my problem? Please help! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.