UIAutomation - Scroll and Text Issues - c#

I made a small uiautomation app that scrolls through a forms windows searching for a specific richtextbox. Once it finds the richtextbox, it would extract the text and verify against a constant. I already coded the entire program but I have two issues:
The FindAll function sometimes misses the textbox. I believe its due to scrolling too fast since if I step through my app, it works everytime.
The TextPattern applied to the richtextbox provides me with DocumentRange.GetText function. However, it doesn't retrieve any returns/new lines.
Is there anything I can implement to consistently catch my textbox without slowing down the scroll?
Is there any option to extract the text with returns/new lines included? I can consider Copy/Paste since some of my textboxes aren't selectable.
Update 1/19/2015
For problem 1, I placed a couple Thread.Sleep(500) . I'm not sure where it would indicate the pane is still loading due to scrolling.
For problem 2, I found out that the textboxes I thought were unselectable are selectable. However, I still don't want to use the copy option since one event that changes my projects focus will copy the wrong location. I barely keep the SendKeys option as it is.

Related

winforms designer hand code bring to front

I'm converting some VB6 forms to C# and have created an utility which generates C# designer files from the VB6 source files. It's going well, but I've ran into some trouble with ordering.
I have an option button and an updown beside each other and the right side of the option button is slightly overlapping the updown. I tried resizing the option button, but no usable size seems to leave the caption visible.
I've considered changing the option button to have a transparent background, but unfortunately the solution isn't viable for all of my forms.
However, what I think would definitely work is bringing the updown to the front or sending the option button to the back, but I can't figure out how to do this from within the designer code only.
How can I bring controls to the front or send them to the back from the designer code? If anyone has a different solution for having the caption visible I'm open for suggestions. It must be done from within the designer code only, as that is what my tool generates.
The order in which controls are added to their parent determines the initial Z-order. The control added first will be in front of controls added later:
this.Controls.Add(updownButton);
this.Controls.Add(optionButton);

VS 2013 Quick Find loses focus when switching to my application - how do I preserve/restore it programmatically?

I have whipped up a C# clipboard application that stores multiple 'clippings' for later use. I use low-level keyboard hooks to pop open my application's window(s) on command. When the window is closed (or a clipping is double-clicked), it is supposed to paste the selected clipping into the last active window (the window prior to my application's window). I use low-level WINAPI methods to determine the last active application, snag its handle, and then return focus to it before simulating a Ctrl+V keystroke to paste.
This typically works except in one very unique scenario: I am in a WPF application project, Quick Finding in a XAML file, the cursor automatically switches to the body text, not the Quick Find textbox, and pastes it there. It seems to have something to do with the loss of focus/activation, as it moves the cursor whenever I activate another window, regardless of my own application's running.
VB files, C# files, what have you, and XAML opened in WinForm projects do not steal the Quick Find focus when switching between the VS2013 application and my own; upon returning to the last active application, the text pastes into the Quick Find box.
Only the XAML in WPF application projects gives me this problem.
So far. I know it is a fringe case, but I expect to run into more. This program is meant to be used in a coding environment and it's pretty important that it be able to handle these kinds of scenarios.
I've tried getting the internal control handle using code from http://www.codeproject.com/Articles/34752/Control-in-Focus-in-Other-Processes, so that I can return the focus to it, but it seems that the handle for the body text and the handle for the Quick Find text box are the same.
A partial solution is found in: How do I prevent the original form from losing focus when I show another form? The popup window I use is navigated primarily through my low-level shortcuts, and therefore has no need of explicit activation.
Using the mouse on it or any of my other windows (as I expect my users will sometime), will cause it to gain activation and circumvent this fix. However, it's such a fringe case it doesn't seem to matter. Hopefully this helps anyone in a similar situation (if not necessarily specifically this one).

Selecting an item from pop-up menu

I'm trying to make an application that will test some features of an existing app and I wanted it not to be window-size dependent and not to require focusing the window or etc.
I've already figured out how to get window handles for different controls in the tested app so I can click buttons, enter text to textboxes etc. with Send/Post Message but still got a few unsolved problems.
The first is selecting an item from a pop-up menu that can be triggered by button click (TAdvGlowMenuButton class) or right click somewhere- I can't even see any messages related to it in Spy++ so I have no idea how to do it, is it possible to select an item by name? as I don't have it's id
The second thing is clicking next to something, for example 10 pixels to the right of a button.
I have the button handle so I can get it's size and it's parent but I still don't know how to get it's position inside the parent - any ideas?:)
And also a quick one but I don't believe it is possible - can I somehow get position of a label in the tested app? I can't even see it in Spy++ .
I hope you can help me to find it out ;)
Edit: I forgot about the most important thing:P , I'd like to achieve it with Send/Post Message if only it is possible.
My recommendation would be to abandon the message sending/posting model altogether and instead use UI Automation. Automated testing tools is exactly what the UI Automation APIs were designed for, and they are much more capable than SendMessage/PostMessage.
Yes, I realize that this is exactly the opposite of the answer you were looking for. But you will have no end of trouble getting messages to do what you want. A fair number of them rely on the application having the focus, and it is completely reasonable for your code to make this assumption when you receive e.g. a WM_KEYDOWN message. A testing tool should not flag that as a bug.
I notice you've tagged this question with the C# and .NET tags. In that case, you may be interested to learn that the UI Automation APIs have been wrapped in the .NET Framework.

Tracking down the case of the missing keyboard caret

On certain windows in our application the keyboard caret disappears when we check in / checkout objects. This makes the UI readonly or editable.
So if I am on a text field and it is editable, and I check it in the blinking caret disappears. I check it back out and the caret is still gone. Both before and after I can use Shift+Left arrow or right arrow to see that the control still has focus (a .NET textbox control).
The odd thing is that it seems to happen all controls on certain windows but works fine for all controls on other windows.
I know this is a little vague, but I'm just looking for ideas of what could possibly make the keyboard caret disappear like this. (or how to troubleshoot or debug this issue)
We don't have any Cursor.Hide calls, there is not any code that calls ShowCaret or HideCaret ( I looked and we have no code with the word "caret" it it anywhere.
I've checked on both the good and bad controls and done some debugging to see that the cursor is "IBeam", and I've put some calls to GetCaretPos and GetCaretBlinkTime in, but in both the good and bad cases the values seem reasonable.
DevExpress has confirmed that this will be fixed in the next release and offered me a temporary build if I need one. Excellent customer support.

Updating single characters in large TextBox programmatically

Reading lots of characters and updating a textbox was suggested to me when I created this question, and it was exactly what I was looking for (couldn't find it by just searching). However a couple of points need clarifying.
I am looking to upgrade to a ListBox or even RichTextBox. For now I want to be able to replace as little of the onscreen (and off, as an added bonus) text as possible.
In the first link Guffa wrote:
If the data is line based, use a list instead of a text box, so that you only have to update the last line when you add a character.
I have a split pane where updates to one TextBox are translated and shown on the other side, and vice-versa. I've briefly toyed with a ListBox but it doesn't provide the intrinsic text-editing funcionality of a TextBox so I went back.
What component should I be using? I wouldn't have thought that with all of .NET available I should have to consider Win32.
Ok, no one else has offered an answer so I will propose a solution which is the last one open to me short of refactoring back to Win32 API calls.
The solution is to use two textboxes. Instead of replacing the text element of the on-screen one you replace that of its dupe, which at the time is hidden, you then toggle the visible flags of both.
I'll let you know how it goes but it is major work for not much advantage, I'll prolly just live with a bit of flicker for now.

Categories

Resources