How to implement a global WinAPI overlay interface - c#

We need to implement a universal autocomplete for users at our company. Basically when someone starts with # and then types a name, we want to help them with autocomplete options (some sort of list showing).
This needs to work in any application in windows.
The plan is capture all keypresses, look for the # character, and if they have typed that start helping them with the autocomplete. If they select an option then we SendKeys the rest of the name down to the current cursor location, thereby finishing the name for them.
We have the keypress part working, but we aren't sure how to display the autocomplete feature. How can we implement a UI for this with the Win32 API?

Edit controls have the IAutoComplete and you can also use UWP TextBox and AutoSuggestBox.

Related

Spying / pressing buttons with C#

In BluePrism it is possible to spy buttons, fields etc. of any windows application and then click those buttons automatically. For example, if you look at the screenshot you can see the attributes of the calculator's button "1" as spied in the Win32-mode (there are also HTML-, Accessibility-, Region- and UI Automation-modes) by which BluePrism will be able to identify and click the according button. Furthermore, BluePrim is compatible with C# and I wonder whether (and how) I could also get those attributes via C# instead or at least use the spied attributes as can be seen on the screenshot to press the same button with C# instead?
EDIT:
It would be highly appreciated if someone could provide the C# code for pressing the calculator's button "1" to get me started (I'm a C# newbie :-) Thanks!
You do not need C# for that, you can just use a Reader stage and action Get AA Attribute or Get Window Attribute.
EDIT:
But if you really want to do it using .NET only, have a look at UI Automation or Active Accessibility Automation (older one)
This seems like a nice example.
You will also find a tool called Inspect.exe very handy to spy elements without using BP. This
You can use the Application Model that you just spied, put it in a navigate stage in your object, then select Click Mouse Centre as the action. This will result in the button you have spied being clicked. Generally, to use Sendkeys is with C# syntax, i.e. use the root element (root element and top of list in Application Modeller tree) and select Global SendKeys as the action inside a navigate stage. In the Text input field you can enter your C# sendkey code, like for example for Ctrl + Alt + Delete use: "^%{DELETE}". I think this is what you may be looking for? Otherwise, if I understand correctly, you might be looking to use a C# code-stage inside BP to pass sendkeys to an application attached to a BP process, which would possibly involve referencing each and every attribute of the host application in C# and then using (for example) the C# Enum properties of each keyboard key, etc... this would be a massively redundant exercise since BP already provides the functionality inside the navigate stage as explained above.

Custom search tab in Windows start menu search with C#

I am interested to know how can I do the same thing that the apllication listed below does:
Start Menu Calculator
I want to know how can I create an custom tab in Start Menu Search and then handle it with my WPF application. It should only be enabled until my application is running.( Just like what The calculator does )
I read something about windows API Code Pack and I downloaded it but I don't know how can I use it. I searched through it but I didn't find anything.( If you know how I could do this using with Windows API Code Pack, please write an example that explains how to do it in C#)
The main exe "Start Menu Calculator.exe" installs a windows hook (using SetWindowsHookEx) into explorer.exe. The hook is implemented as usual in SBLib.dll which is then injected into Windows Explorer's memory space.
This hook searches for window handles belonging to the search box. See a discussion around this here:
How do I get a "handle" on the Windows Search textbox? and probably sub classes the search box windows (if you kill the "Start Menu Calculator.exe" process abruptly, it crashes Windows Explorer too... which kinda confirms this)
It then reacts to key presses, and I suppose it butchers up the result window. In the hierarchies of Windows, I think it's a Window named "Desktop Search Open View", you can get to it with SPY++ under "Start Menu", aside the windows mentioned in the msdn forum above.
So, no nice API behind this nice application. Massive hacks instead :-)
I think however, some level of integration is possible, using documented behavior, with the search box. I have not dug further, but there is the notion of federated search in Windows (Windows 7 Federated Search). I don't see if this would be capable of reacting instantaneously to what the user types in though...
As a side note, if you're also looking for a way to run javascript code from C#, there is a question here on SO that says it all: parse and execute JS by C#
When making Start Menu Calculator I initially tried to use federated search and Managed (.NET) code however you can't integrate into the start menu, only the shell search (for web service based search which lets you return custom results based on a search string). The problem is that the federated search is structured such that all the search data is pre-indexed so for the calculator to work I would have had to pre index every possible calculation! The reason it all works this way is to make sure that clicking the start menu is always fast and responsive (you don't want a web service call everytime you press start in the shell).
I ended up hiring someone to write a native windows app that places a IE control into the Start menu search area and passes the searched text in with the source. All the visual stuff is just css made to look like the start menu rendering and the calculations handled in javascript.
So yes, a bit of a hack but it seems to work and I havent had/heard of any crashing issues so far.

accessing another app's elements using C# WinForms app

I'd like to be able to do following actions within another application:
to change Tabs
to Copy text from within a TextBox
to click on a Button
to enter text into a TextBox
to select DropDownList element
Right now I'm using separate methods such as:
mouse_event() to change mouse coordinates and click on a button
another mouse_event(LeftMouseClick followed by the RightMouseClick) to copy a text within a TextBox
Clipboard.GetText(System.Windows.Forms.TextDataFormat.Text) to Copy what's inside the clipboard
SendInput (for each key) - enter the text into a TextBox
Disadvantages of this approach are:
(not crucial) PC becomes unusable (you can't work while script is running)
I have to know exact pixels (read - position/coordinates) of EVERY element within an app
slow execution time (each key has to be typed separately)
I'm looking forward to create an application which can click on a TextBox/Button/List without the need of having exact coordinates of these elements.
Is such task possible with C# WinForms? My current approach works but it has it's flaws.
Any advice?
Read about Mutex. If you plan on scale-ability, read about network communication (for example, the TCP protocol. TcpListner, and TcpClient).
This sounds like a job for UI Automation. I have only used it to get text from another application, but it has functions to activate controls by name or to navigate the control tree if there is no name.
You can get text and interact with controls using AutomationElements that you find using patterns or navigating the control tree.
There is a complete framework for doing exactly this kind of thing, and it's called the UI Automation Framework
Here's some examples on how to use it.
And you can also apply this technique to generic windows's using the UI Spy to determine the automation elements.

How to make a right-click translation dictionary application?

I'm trying to write a dictionay application on C#. There is a scenarios that user selects a text and press a hot-key, I want to pop-up a quick windows that display the search result of the selected word (just like Lingoes does)
How would I do it in C#?
Thanks in advance
Start with Google this:
hooks, global hotkeys (for monitoring global keyboard and mouse events)
WinAPI (to do such tricks as grab any selected text)
I've written program you're talking about. You can check the code here - IDictionary.
Regards

filtering autocomplete options in windows mobile app

i'm working on windows mobile app (c#, .net 2.0). i would like to make use of the device's autocomplete features for a specific textbox, but i want to be more specific than the device provides by default.
for example, i want to autocomplete to suggest a word of a specific length. it would also be nice to have several options given at once.
can anyone give me some help on this, or a link to helpful references?
The built-in autocomplete is, unfortunately, quite limited in capability. It would be great if we had some form of callback or hook that we could use to intercept and alter its behavior, but there isn't. The only way to get the granularity of control that you're after is to roll your own (or find a thrid-party) auto-complete control.

Categories

Resources