<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>UI Automation</title>
        <link>http://geekswithblogs.net/CalinTatar/category/10090.aspx</link>
        <description>UI Automation</description>
        <language>en-US</language>
        <copyright>CalinTatar</copyright>
        <managingEditor>tatar_calin@yahoo.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Automatically add Sharepoint subfolders when adding a new Folder Content Type</title>
            <link>http://geekswithblogs.net/CalinTatar/archive/2009/06/07/automatically-add-sharepoint-subfolders-when-adding-a-new-folder-content.aspx</link>
            <description>&lt;p&gt;&lt;font size="2"&gt;Last week I was asked on one of my CodeProject article, about how to implement a Sharepoint feature that will automatically add subfolders to a parent folder in a document library.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;To add subfolders when a new Folder(or derived Content Type from Folder) was created, we have to write a feature, that will handle the &lt;strong&gt;ItemAdded&lt;/strong&gt; event. When this event gets fired, we can get the current folder item and add subfolders to it.&lt;br /&gt;
&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;The following feature adds subfolders( the ones from folders array) when a new Project Folder is created.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;img height="505" alt="SubFoldersCreatorFeature" width="900" src="/images/geekswithblogs_net/CalinTatar/SubFoldersFeaature/SubFoldersCreatorFeature.png" /&gt;&lt;/p&gt;
&lt;p&gt;Basically, what the above method is doing is:&lt;/p&gt;
&lt;p&gt;- we get the current document library that we are working on.&lt;/p&gt;
&lt;p&gt;- test if the current Item is derived from our Content Type; with this we can restrict the feature to work only on some of the folder content types&lt;/p&gt;
&lt;p&gt;- by getting the url of the current folder, we can add a new folder on the current &lt;strong&gt;SPDocumentLibrary&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Calin Tatar&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=132664"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=132664" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/CalinTatar/aggbug/132664.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>CalinTatar</dc:creator>
            <guid>http://geekswithblogs.net/CalinTatar/archive/2009/06/07/automatically-add-sharepoint-subfolders-when-adding-a-new-folder-content.aspx</guid>
            <pubDate>Sun, 07 Jun 2009 16:48:06 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/CalinTatar/comments/132664.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/CalinTatar/archive/2009/06/07/automatically-add-sharepoint-subfolders-when-adding-a-new-folder-content.aspx#feedback</comments>
            <slash:comments>18</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/CalinTatar/comments/commentRss/132664.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Switching from Win32 to UI Automation</title>
            <link>http://geekswithblogs.net/CalinTatar/archive/2009/05/16/switching-from-win32-to-ui-automation.aspx</link>
            <description>&lt;p&gt;&lt;font size="2"&gt;If you are about to write another p/invoke (Win32 calls) to access existing Windows, Controls,...you should consider switching to UI Automation framework, which provides programmatic access to most user interface (UI) elements on the desktop, by writing managed code.  Some time ago I wrote an article about UI Automation, have a look at:  &lt;font face="Arial"&gt;&lt;a href="http://www.codeproject.com/KB/WPF/WPF_UI_Automation.aspx"&gt;http://www.codeproject.com/KB/WPF/WPF_UI_Automation.aspx&lt;/a&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;In this post, I'll try to compare two ways of implementing Windows automation applications, by using unmanaged code (Win32 interoperability) and by using the UI Automation framework (managed code).&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;OK, let's take a simple example. Suppose we want to write a piece of code that gets the active window and some details about this window.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Instead of writing Win32 calls for &lt;strong&gt;GetWindow&lt;/strong&gt;, &lt;font face="Arial"&gt;&lt;strong&gt;GetWindowRect&lt;/strong&gt;, different structures, etc, with UI Automation we can write simple managed code to accomplish the same task.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Basically, we just need to get &lt;strong&gt;AutomationElement.FocusedElement&lt;/strong&gt; and this will provide us useful informations about the focused control which might be a simple control(Button, TextBox, etc) or a Window. Let's assume that the returned FocusedControl is a Textbox, a not a Window; we still can get the parent Window of that control, by getting first the ProcessId property. Based on the process Id, we can create an instance of Process class and access &lt;strong&gt;process.MainWindowHandle&lt;/strong&gt;, to get the Window handle. Now, based on the Window handle, we can call the static method AutomationElement.FromHandle() and you'll get the AutomationElement for the window. To get the window bounds, just call &lt;strong&gt;windowElement.Current.BoundingRectangle&lt;/strong&gt; and you'll obtain a &lt;strong&gt;Rect&lt;/strong&gt; object. After that you may use the bounds to capture the window, etc.&lt;/font&gt;&lt;/p&gt;
&lt;font size="2"&gt;&lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;p&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;AutomationElement&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; controlElement = &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;AutomationElement&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.FocusedElement;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (controlElement != &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &amp;amp;&amp;amp; controlElement.Current.ControlType != &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ControlType&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.Window)&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;p&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Process&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; process = &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Process&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.GetProcessById(controlElement.Current.ProcessId);&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;AutomationElement&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; windowElement = &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;AutomationElement&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.FromHandle(process.MainWindowHandle);&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (windowElement != &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;)&lt;/font&gt;&lt;/p&gt;
&lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;p&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Rect&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; r = windowElement.Current.BoundingRectangle;&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;&lt;/blockquote&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Another example would be to get the user control based on the cursor position. So we want to find a managed solution for &lt;strong&gt;WindowFromPoint &lt;/strong&gt;Win32 function. We can accomplish this without writing Interop code, by calling and passing a Point to &lt;strong&gt;AutomationElement.FromPoint();&lt;/strong&gt;  &lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/font&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=132151"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=132151" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/CalinTatar/aggbug/132151.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>CalinTatar</dc:creator>
            <guid>http://geekswithblogs.net/CalinTatar/archive/2009/05/16/switching-from-win32-to-ui-automation.aspx</guid>
            <pubDate>Sat, 16 May 2009 14:40:03 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/CalinTatar/comments/132151.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/CalinTatar/archive/2009/05/16/switching-from-win32-to-ui-automation.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/CalinTatar/comments/commentRss/132151.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>