<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>North Atlanta Web Design &#187; Microsoft Active Accessibility</title>
	<atom:link href="https://www.northatlantawebdesign.com/index.php/tag/microsoft-active-accessibility/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.northatlantawebdesign.com</link>
	<description>Programming Examples, Samples, and Tutorials</description>
	<lastBuildDate>Mon, 15 Aug 2011 20:18:35 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.7.41</generator>
	<item>
		<title>Microsoft Active Accessibility Methods and Inconsistent Implementations</title>
		<link>https://www.northatlantawebdesign.com/index.php/2009/08/12/microsoft-active-accessibility-methods-and-inconsistent-implementations/</link>
		<comments>https://www.northatlantawebdesign.com/index.php/2009/08/12/microsoft-active-accessibility-methods-and-inconsistent-implementations/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 21:04:32 +0000</pubDate>
		<dc:creator><![CDATA[Jeff Gibeau]]></dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[get_accRole]]></category>
		<category><![CDATA[get_accState]]></category>
		<category><![CDATA[IAccessible]]></category>
		<category><![CDATA[Microsoft Active Accessibility]]></category>
		<category><![CDATA[MSAA]]></category>

		<guid isPermaLink="false">http://www.northatlantawebdesign.com/?p=143</guid>
		<description><![CDATA[The C++ IAccessible interface offers a handful of methods that allow you to gather information or perform actions on an object. Each of these methods are well documented on MSDN, but it is up to the creator of an object to implement them correctly. In this article, I&#8217;ll be talking about a couple of the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>The C++ IAccessible interface offers a handful of methods that allow you to gather information or perform actions on an object.  Each of these methods are well <a title="IAccessible Interface Documentation MSDN" href="http://msdn.microsoft.com/en-us/library/dd318466%28VS.85%29.aspx">documented on MSDN</a>, but it is up to the creator of an object to implement them correctly.  In this article, I&#8217;ll be talking about a couple of the inconsistencies you may run into when using these methods due to improper implementations and a lack of restrictions on how they should be implemented.<br />
<span id="more-143"></span></p>
<h3>IAccessible::get_accRole</h3>
<p>In the documentation for this method, it is clearly stated that it accepts two parameters.  The first is the accessible objects child id.  This variant is either equal to CHILDID_SELF, which defines that you are seeking information about the current object, or the child ID, which will get the role of the defined child.  This parameter should be of variant type VT_I4.  The second parameter is a variant pointer that will return the accessibility role of the object.  In the documentation this is stated as being an <a title="Object Role Constants MSDN" href="http://msdn.microsoft.com/en-us/library/dd373608%28VS.85%29.aspx">object role constant</a> such as ROLE_SYSTEM_WINDOW or ROLE_SYSTEM_CLIENT.  This parameter is where I have run into problems with how get_accRole has been implemented by the creator of the object.</p>
<p>In addition to stating the second parameter should return an object role constant, it also states that the variant type MUST be of type VT_I4.  This does not seem to be enforced though.  I have run into numerous situations (developing in Microsoft Office) where the variant type is VT_BSTR.  A string is considered invalid for this variant and can cause quite a headache when unexpected.  This occurs in a Microsoft product none the less, the creators of MSAA.  This is just one case that I have run into where the value is invalid, and it begs the question, what other variant types might this return?  That is totally up to the developer implemented get_accRole in his object.  The simple solution to this problem is to always check the variant type that is returned before doing any operations on it to avoid errors.</p>
<h3>IAccessible::get_accState</h3>
<p>After research into the get_accRole method, it came as no surprise the get_accState suffers from the same issues.  As with get_accRole, get_accState takes two parameters.  The first is the child id, and the second is the out variable to hold the state constant.  The <a title="IAccessible get_accState MSDN Documentation" href="http://msdn.microsoft.com/en-us/library/dd318487%28VS.85%29.aspx">documentation for get_accState</a> states that the second argument will return a variant type of VT_I4 that corresponds to one of the <a title="Object State Constants MSDN" href="http://msdn.microsoft.com/en-us/library/dd373609%28VS.85%29.aspx">object state constants</a>.  Though in using the accState with Microsoft Office and Lotus Notes I have run into times where the state is of variant type VT_BSTR (string).  Again the solution is to always check the variant type that is returned before using it in any operations.</p>
<p>&#8212;&#8211;</p>
<p>As I continue to dive deeper into the world of MSAA, I&#8217;ll keep this blog up to date with the inconsistencies I find.  If you have any that you have come across in working with MSAA tell me about them.  I&#8217;ll be glad to look into them to see if there is a workaround or a clean way to handle them.  I&#8217;ll leave with you with a code snippet that shows how to get the accRole and compare it with an object role constant.</p>
<p>Compare accessibility role:</p>
<pre class="brush: cpp; title: ; notranslate">
//Code below assumes that IAccessible object and ChildID are both passed in parameters.
bool CompareAccRole(IAccessible* pIAccessible, VARIANT childID, LONG objectRoleConstant)
{
	VARIANT accObjectRole;
	HRESULT hr = pIAccessible-&gt;get_accRole(childID, &amp;accObjectRole);
	if(hr == S_OK &amp;&amp; accObjectRole.vt == VT_I4)
	{
		if(accObjectRole.lVal &amp; objectRoleConstant)
			return true;
	}
	return false;	
}
</pre>
<p>Useful Links:</p>
<ul>
<li><a title="IAccessible MSDN Documentation" href="http://msdn.microsoft.com/en-us/library/dd318466%28VS.85%29.aspx">IAccessible MSDN Documentation</a></li>
<li><a title="IAccessible::get_accRole MSDN Documentation" href="http://msdn.microsoft.com/en-us/library/dd318485%28VS.85%29.aspx">IAccessible::get_accRole MSDN Documentation</a></li>
<li><a title="Object Role Constants MSDN" href="http://msdn.microsoft.com/en-us/library/dd373608%28VS.85%29.aspx">Object Role Constants MSDN</a></li>
<li><a title="IAccessible::get_accState MSDN Documentation" href="http://msdn.microsoft.com/en-us/library/dd318487%28VS.85%29.aspx">IAccessible::get_accState MSDN Documentation</a></li>
<li><a title="Object State Constants" href="http://msdn.microsoft.com/en-us/library/dd373609%28VS.85%29.aspx">Object State Constants MSDN</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://www.northatlantawebdesign.com/index.php/2009/08/12/microsoft-active-accessibility-methods-and-inconsistent-implementations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Access Microsoft Excel 2007 COM API through Microsoft Active Accessibility</title>
		<link>https://www.northatlantawebdesign.com/index.php/2009/07/15/access-microsoft-excel-2007-com-api-through-microsoft-active-accessibility/</link>
		<comments>https://www.northatlantawebdesign.com/index.php/2009/07/15/access-microsoft-excel-2007-com-api-through-microsoft-active-accessibility/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 00:47:49 +0000</pubDate>
		<dc:creator><![CDATA[Jeff Gibeau]]></dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[Microsoft Excel 2007]]></category>
		<category><![CDATA[Microsoft Office 2007]]></category>
		<category><![CDATA[AccessibleObjectFromWindow]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Microsoft Active Accessibility]]></category>

		<guid isPermaLink="false">http://www.northatlantawebdesign.com/?p=63</guid>
		<description><![CDATA[A couple days ago I showed you how to access the Microsoft Word 2007 COM API through Microsoft Active Accessibility (MSAA). Today, I&#8217;m going to switch it up just a little bit, and use the same method to access the Microsoft Excel 2007 COM API. Again, we&#8217;ll be using AccesssibleObjectFromWindow to get at the main [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>A couple days ago I showed you how to access the <a type="amzn">Microsoft Word 2007</a> COM API through Microsoft Active Accessibility (MSAA).  Today, I&#8217;m going to switch it up just a little bit, and use the same method to access the <a type="amzn">Microsoft Excel 2007</a> COM API.  Again, we&#8217;ll be using AccesssibleObjectFromWindow to get at the main Excel::Window object.  From that object, you can obtain the Excel Application, and Excel Workbook objects.  Some documentation from Microsoft can be <a href="http://msdn.microsoft.com/en-us/library/dd317978(VS.85).aspx">found here</a>.</p>
<p><span id="more-63"></span></p>
<p>First we obtain the hwnd of the Microsoft Excel Process:</p>
<pre class="brush: cpp; title: ; notranslate">
//The main window in Microsoft Excel has a class name of XLMAIN
HWND excelWindow = FindWindow(L&quot;XLMAIN&quot;, NULL);
</pre>
<p>We can then traverse the child windows until we find the one with classname EXCEL7:</p>
<pre class="brush: cpp; title: ; notranslate">
//Use the EnumChildWindows function to iterate through all child windows until we find EXCEL7
EnumChildWindows(excelWindow, (WNDENUMPROC) EnumChildProc, (LPARAM)1);
</pre>
<pre class="brush: cpp; title: ; notranslate">
static BOOL EnumChildProc(HWND hwnd, LPARAM)
{
     WCHAR szClassName[64];
     if(GetClassNameW(hwnd, szClassName, 64))
     {
          if(_wcsicmp(szClassName, L&quot;EXCEL7&quot;) == 0)
          {
               //Get AccessibleObject
               Excel::Window* pWindow = NULL;
               HRESULT hr = AccessibleObjectFromWindow(hwnd, OBJID_NATIVEOM, __uuidof(Excel::Window), (void**)&amp;pWindow);
               if(hr == S_OK)
               {
                    //Excel object is now in pWindow pointer, from this you can obtain the document or application
                    Excel::_Application* pApp = NULL;
                    pWindow-&gt;get_Application(&amp;pApp);
                    pWindow-&gt;Release();
               }
               return false;     // Stops enumerating through children
          }
     }
     return true;
}
</pre>
<p>Next we obtain our Excel::Window object through AccessibleObjectFromWindow:</p>
<pre class="brush: cpp; title: ; notranslate">
//Get AccessibleObject
Excel::Window* pWindow = NULL;
HRESULT hr = AccessibleObjectFromWindow(hwnd, OBJID_NATIVEOM, __uuidof(Excel::Window), (void**)&amp;pWindow);
</pre>
<p>That&#8217;s it!  We now have our Excel::Window COM Object.  From this object we can obtain the Excel::Application and Excel::Workbook objects, allowing us full interaction with the active document.  So with just a few lines of code, we now have access to automate an Excel 2007 document.</p>
<p>Full source code:</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;windows.h&gt;
#include &lt;oleacc.h&gt;
#include &quot;msexcel.h&quot;

static BOOL EnumChildProc(HWND hwnd, LPARAM)
{
     WCHAR szClassName[64];
     if(GetClassNameW(hwnd, szClassName, 64))
     {
          if(_wcsicmp(szClassName, L&quot;EXCEL7&quot;) == 0)
          {
               //Get AccessibleObject
               Excel::Window* pWindow = NULL;
               HRESULT hr = AccessibleObjectFromWindow(hwnd, OBJID_NATIVEOM, __uuidof(Excel::Window), (void**)&amp;pWindow);
               if(hr == S_OK)
               {
                    //Excel object is now in pWindow pointer, from this you can obtain the document or application
                    Excel::_Application* pApp = NULL;
                    pWindow-&gt;get_Application(&amp;pApp);
                    pWindow-&gt;Release();
               }
               return false;     // Stops enumerating through children
          }
     }
	 return true;
}
int main( int argc, CHAR* argv[])
{
     //The main window in Microsoft Excel has a class name of XLMAIN
     HWND excelWindow = FindWindow(L&quot;XLMAIN&quot;, NULL);

     //Use the EnumChildWindows function to iterate through all child windows until we find _WwG
     EnumChildWindows(excelWindow, (WNDENUMPROC) EnumChildProc, (LPARAM)1);

     return 0;
}
</pre>
<p>Useful Links for this post:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/dd317978%28VS.85%29.aspx">AccessibleObjectFromWindow Documentation</a></li>
<li><a title="Using Visual C++ to Automate Office" href="http://support.microsoft.com/kb/238972">Using Visual C++ to Automate Office</a></li>
<li><a title="EnumChildWindows Documentation" href="http://msdn.microsoft.com/en-us/library/ms633494%28VS.85%29.aspx">EnumChildWindows Documentation</a></li>
</ul>
<p>Key phrases: Accessing Excel 2007 COM object using AccessibleObjectFromWindow, Automating Excel 2007 with Microsoft Active Accessibility MSAA<br />
<em><strong>Update:</strong> I&#8217;ve updated the full source to utilize get_Application.  get_Document was in place previously, which was leftover from my Word source code.</em></p>
]]></content:encoded>
			<wfw:commentRss>https://www.northatlantawebdesign.com/index.php/2009/07/15/access-microsoft-excel-2007-com-api-through-microsoft-active-accessibility/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Getting the COM object from HWND using AccessibleObjectFromWindow in Microsoft Word 2007</title>
		<link>https://www.northatlantawebdesign.com/index.php/2009/07/14/getting-the-com-object-from-hwnd-using-accessibleobjectfromwindow-in-microsoft-word-2007/</link>
		<comments>https://www.northatlantawebdesign.com/index.php/2009/07/14/getting-the-com-object-from-hwnd-using-accessibleobjectfromwindow-in-microsoft-word-2007/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 01:31:44 +0000</pubDate>
		<dc:creator><![CDATA[Jeff Gibeau]]></dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[Microsoft Office 2007]]></category>
		<category><![CDATA[Microsoft Word 2007]]></category>
		<category><![CDATA[AccessibleObjectFromWindow]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Microsoft Active Accessibility]]></category>

		<guid isPermaLink="false">http://www.northatlantawebdesign.com/?p=30</guid>
		<description><![CDATA[After spending some time on this over the past few days, and sorting through the spotty documentation provided by Microsoft on Accessibility, I was able to get a handle on the COM object in Microsoft Word 2007.  It turns out to be pretty simple, and is actually in the documentation they provide here, but they [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>After spending some time on this over the past few days, and sorting through the spotty documentation provided by Microsoft on Accessibility, I was able to get a handle on the <a type="amzn">COM</a> object in <a type="amzn">Microsoft Word 2007</a>.  It turns out to be pretty simple, and is actually in the documentation <a href="http://msdn.microsoft.com/en-us/library/dd317978(VS.85).aspx">they provide here</a>, but they don&#8217;t make it clear as day.  I intend to do that here.</p>
<p><span id="more-30"></span></p>
<p>First we obtain the hwnd of the Microsoft Word Process:</p>
<pre class="brush: cpp; title: ; notranslate">
//The main window in Microsoft Word has a class name of OpusApp
HWND wordWindow = FindWindow(L&quot;OpusApp&quot;, NULL);
</pre>
<p>We can then traverse the child windows until we find the one with classname _WwG:</p>
<pre class="brush: cpp; title: ; notranslate">
//Use the EnumChildWindows function to iterate through all child windows until we find _WwG
EnumChildWindows(wordWindow, (WNDENUMPROC) EnumChildProc, (LPARAM)1);
</pre>
<pre class="brush: cpp; title: ; notranslate">
static BOOL EnumChildProc(HWND hwnd, LPARAM)
{
     WCHAR szClassName[64];
     if(GetClassNameW(hwnd, szClassName, 64))
     {
          if(_wcsicmp(szClassName, L&quot;_WwG&quot;) == 0)
          {
               //Get AccessibleObject
               Word::Window* pWindow = NULL;
               HRESULT hr = AccessibleObjectFromWindow(hwnd, OBJID_NATIVEOM, __uuidof(Word::Window), (void**)&amp;pWindow);
               if(hr == S_OK)
               {
                    //Word object is now in pWindow pointer, from this you can obtain the document or application
                    Word::_Document* pDoc = NULL;
                    pWindow-&gt;get_Document(&amp;pDoc);
               }
               return false;     // Stops enumerating through children
          }
     }
	 return true;
}
</pre>
<p>Next we obtain our Word::Window object through AccessibleObjectFromWindow:</p>
<pre class="brush: cpp; title: ; notranslate">
Word::Window* pWindow = NULL;
HRESULT hr = AccessibleObjectFromWindow(hwnd, OBJID_NATIVEOM, __uuidof(Word::Window), (void**)&amp;pWindow);
</pre>
<p>That&#8217;s it!  We now have our Word::Window COM Object.  From this object we can obtain the Word::Application and Word::Document objects, allowing us full interaction with the active document.  So with just a few lines of code, we now have access to automate a word 2007 document.</p>
<p>Full source code:</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;windows.h&gt;
#include &lt;oleacc.h&gt;
#include &quot;msword.h&quot;

static BOOL EnumChildProc(HWND hwnd, LPARAM)
{
	WCHAR szClassName[64];
	if(GetClassNameW(hwnd, szClassName, 64))
	{
		if(_wcsicmp(szClassName, L&quot;_WwG&quot;) == 0)
		{
			//Get AccessibleObject
			Word::Window* pWindow = NULL;
			HRESULT hr = AccessibleObjectFromWindow(hwnd, OBJID_NATIVEOM, __uuidof(Word::Window), (void**)&amp;pWindow);
			if(hr == S_OK)
			{
				//Word object is now in pWindow pointer, from this you can obtain the document or application
				Word::_Document* pDoc = NULL;
				pWindow-&gt;get_Document(&amp;pDoc);
			}
			return false;     // Stops enumerating through children
		}
	}
	return true;
}
int main( int argc, CHAR* argv[])
{
	//The main window in Microsoft Word has a class name of OpusApp
	HWND wordWindow = FindWindow(L&quot;OpusApp&quot;, NULL);

	//Use the EnumChildWindows function to iterate through all child windows until we find _WwG
	EnumChildWindows(wordWindow, (WNDENUMPROC) EnumChildProc, (LPARAM)1);

	return 0;
}
</pre>
<p>The logic to find the correct window can be changed for multiple instances of Word.  Also, you must have the Word type library imported to use the Word COM API.  We&#8217;ll leave those two for another topic on another date.  Check back later in the week for a follow up post on how to access Microsoft Excel 2007 in the same manner.</p>
<p>Useful Links for this post:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/dd317978%28VS.85%29.aspx">AccessibleObjectFromWindow Documentation</a></li>
<li><a title="Using Visual C++ to Automate Office" href="http://support.microsoft.com/kb/238972">Using Visual C++ to Automate Office</a></li>
<li><a title="EnumChildWindows Documentation" href="http://msdn.microsoft.com/en-us/library/ms633494%28VS.85%29.aspx">EnumChildWindows Documentation</a></li>
</ul>
<p>Key phrases: Accessing Word 2007 COM object using AccessibleObjectFromWindow, Automating Word 2007 with Microsoft Active Accessibility MSAA</p>
]]></content:encoded>
			<wfw:commentRss>https://www.northatlantawebdesign.com/index.php/2009/07/14/getting-the-com-object-from-hwnd-using-accessibleobjectfromwindow-in-microsoft-word-2007/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A trip into the depths of Microsoft Active Accessibility (MSAA) through C++</title>
		<link>https://www.northatlantawebdesign.com/index.php/2009/07/10/a-trip-into-the-depths-of-microsoft-accessibility-using-c/</link>
		<comments>https://www.northatlantawebdesign.com/index.php/2009/07/10/a-trip-into-the-depths-of-microsoft-accessibility-using-c/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 15:05:04 +0000</pubDate>
		<dc:creator><![CDATA[Jeff Gibeau]]></dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[Microsoft Access 2003]]></category>
		<category><![CDATA[Microsoft Access 2007]]></category>
		<category><![CDATA[Microsoft Excel 2007]]></category>
		<category><![CDATA[Microsoft Office 2003]]></category>
		<category><![CDATA[Microsoft Office 2007]]></category>
		<category><![CDATA[Microsoft Word 2007]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Cplusplus]]></category>
		<category><![CDATA[IAccessible]]></category>
		<category><![CDATA[Microsoft Access]]></category>
		<category><![CDATA[Microsoft Active Accessibility]]></category>
		<category><![CDATA[Microsoft Excel]]></category>
		<category><![CDATA[Microsoft Word]]></category>
		<category><![CDATA[MSAA]]></category>

		<guid isPermaLink="false">http://www.northatlantawebdesign.com/?p=16</guid>
		<description><![CDATA[Over the next few months, I will be interacting with Microsoft Access, Word, and Excel 2007 through Microsoft Active Accessibility (MSAA) in C++. As my journey progresses, I will be posting the neat little tricks and painful quirks that I run into along the way. To start, here are a few resources you can use [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Over the next few months, I will be interacting with Microsoft Access, Word, and Excel 2007 through Microsoft Active Accessibility (MSAA) in C++.  As my journey progresses, I will be posting the neat little tricks and painful quirks that I run into along the way.  To start, here are a few resources you can use to read up on Microsoft Active Accessibility.</p>
<p><span id="more-16"></span></p>
<ul>
<li><a title="Microsoft IAccessible Interface C++" href="http://msdn.microsoft.com/en-us/library/dd318466(VS.85).aspx">Microsoft&#8217;s documentation on IAccessible interface</a></li>
<li><a title="Sara Ford's Weblog - Microsoft Active Accessibility" href="http://blogs.msdn.com/saraford/archive/category/2507.aspx?p=2">Sara Ford&#8217;s Weblog on Accessibility</a></li>
<li><a title="User Interface Element References for Controls" href="http://msdn.microsoft.com/en-us/library/dd373675(VS.85).aspx">User Interface Element References for Control in Accessibility</a></li>
</ul>
<p>Over the past 6 months, I used MSAA to develop against <a type="amzn">Microsoft Access 2003</a>.  Although it was a painful process to get working, the end result gives quite a bit of flexibility in automating Access.  That being said, there are still a lot of hurdles to overcome, and Accessibility has definitely left many things to be desired.  In the next few weeks I will be posting about my first impressions of Accessibility and it&#8217;s inconsistencies.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.northatlantawebdesign.com/index.php/2009/07/10/a-trip-into-the-depths-of-microsoft-accessibility-using-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
