Desktop Development : Remember Target After Losing Focus - c#

Is it possible to take focus from another program to respond to an event, but then once the response has been handled, switch back to the previous program and restore the cursor where it was?
This sounds like a weird question, but think of it along the lines of
User is typing in a text box in Program A.
A window for Program B pops up and user presses a few buttons to confirm something.
Program B returns control to Program A and restores the selection of the textbox.
If there is a complete C# solution, then great, but this sounds like it might require a little more effort than usual.
Any thoughts?

Personally, doing this could very likely result in the user selecting undesired values in the popup window. For example, someone is typing away in Word. Your application pops up a window, where hitting "Enter" selects a value ... such as the default button. Without wanting to, the user "selected" an incorrect value on your form.
Windows itself tends to do this, and it's very annoying. Quickly double-clicking a desktop shortcut to open an application and then switching back to (for example) an e-mail before the app launches, will tend to remove focus from the focused e-mail window and put focus in the just-opened application, causing your e-mail text or keyboard strokes to go to the just-opened window.

In my experience windows programs work just this way. It often appears that they don't because the user is returning focus with a mouse-click, which itself resets the focus. If it's a winforms app you can probably do something with the lost focus/got focus events at the form level.

Related

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).

How to capture keystrokes before the foreground window gets it?

I'm doing an application like Google Transliteration (Google input tools) tool in C#. It displays the suggestion window on the top of whatever window we are typing (finds caret location & display just window below it). But the focus (foreground process) is still on the application in which we type (for eg. Ms Word, Notepad etc.).
I want to implement these features of Google Transliteration:
It captures the keystrokes before another process gets it.
While renaming a folder or file, we can select words from the suggestions
window show up by using up & down arrow keys and press enter key. But the
rename text field will be still active. The keystrokes will be
captured before it reaches rename text field.
I want to implement a universal text suggestion list (window) like that of Google Transliteration.
How to capture keystrokes before another process gets it (block foreground process from getting it)? (Main Question)
How to capture keystrokes (up & down arrow keys and enter key) and select an option from the words list without focusing on the 'words list' window?
(Caret should remain active and blinking on the foreground process text field. eg. Folder rename text field)
Someone please help me to solve this problem.
I already found this one, but it not helped me to solve my problem.
Capturing keystrokes without focus
You mix two different problems. The first problem - to catch keyboard input - nothing to do with the second - to make an unfocusable window.
The solution to the first problem is very simple - as stated in your link, there is no other way to do it other than Low-Level windows hooks.
The second problem is more difficult, the solution may require a little experimentation, creativity and knowledge of WinAPI. Examples are here, here and here.

Form loses focus and rocker switch key down event handler when clicking on a text box

Environment
Windows XP x32 Visual Studio 2005 Standard Edition
Honeywell Dolphin 9500 running Windows Mobile 2003 (Pocket PC 2003)
.NET Compact Framework 1.0 SP3 and .NET Framework 1.1
Using VC#
Goal
I have a form with a bunch of labels and text boxes on it. This form is populated by "Work Order" objects and is repopulated with the next or previous "Work Order" when the left or right hardware rocker buttons are pressed on the device. I want to allow the user to edit a combo/text box and then put focus back on the form so the the form's KeyDown event handler takes precedence.
Problem
On initial application load, when the form has focus, the rocker switch functions perfectly and the user can index back and forth through the work orders by hitting the hardware left or right buttons. When the user selects a text/combo box to edit the value, the form loses focus and the combo/text box's KeyDown event takes precedence.
Question
How can I force the controls to return focus to the form object without inhibiting a user's ability to edit the values?
Things I Have Tried
I tried setting up each control with a LostFocus() event handler that only contained the line: this.Focus() in order to return focus to the form once the current control lost focus. However, I "clicked" around and couldn't get the control to lose focus.
Code
In my past questions I have always put the code in a friendpaste.com document because the auto-generated form code makes the document somewhat lengthy. If the code needs to be in the body, just let me know and I will paste it here. Otherwise, the code is located at the friend paste link below.
http://friendpaste.com/CJ8CblLebHRXqA7UMLyvc
Also...
Feel free to critique any code you see for any reason but ideally do it as a comment to the question as opposed to an answer to keep the thread on topic. I am a new programmer and I am very new to Pocket PC Visual C# development and welcome, no plead for, any feedback/criticism I can get a hold of.
Additionally, let me know if further information is required and I will do my best to include it as soon as possible.
Thanks!
Override the ProcessCmdKey() method or set the form's KeyPreview property to true.
I just switched to a "moded" editing design and returned focus when "done editing".

CF UI design - How best to display validation failures

I am thinking of using a messagebox to display validation failure messages in the windows mobile app. that I am currently working on. My thinking here is that there is such limited screen realestate that I'd struggle to dedicate an area on the main form specifically for displaying these validation failures. I am a little concerned as to the usability aspect as the user will be force to close the validation messagebox after a validation failure.
Does anyone have any thoughts on this approach or experience that would suggest that there is a better way of doing this?
I know the ErrorProvider is not available within the compact framework. But maybe this would be a starting point on how to do it.
Like the ErrorProvider i would show a simple icon next to the input box that shows something is wrong. Due to the fact, that you don't have a mouse cursor to hover over it, i would in case of clicking on that icon show a concrete error message in a text box docked at the bottom that will hide again if you simply click it.
So the user gets a hint that something is wrong (maybe he already knows what) and can hit on the icon to get a clue. While the clue is showing he can still insert something within the form (he can't see everything, but currently he is only interested in this single box) and one click further (on the appeared text box) he gets back to full screen.
At a last step the box should maybe also automatically disappear if the focus is changed to another input box or the error is fixed.
I would show a message at the top of the screen (as browsers do) that summarizes the errors encountered, in the likes of "X required fields where not filled". And then a more detailed error closer to each of the fields that could not be validated.
That way, the information about the mistakes is still visible while the user is correcting them.

Non intrusive notification without audio?

i have a C# app that registers a protocol. When you click BLAH://djfhgjfdghjkd in a browser it launches my app. However you can click multiple links and each link is a note added into the app.
How can i inform the user that he did fully click the link? Right now i have a console app showing up for 1sec (basically pops up and goes away as fast as possible) which felt better then a hidden console since you are unsure if it went through. The 1 second takes a lot of time when you are trying to rapidly click many notes/links and the console gets in the way. What can i do that is noticeable?
I'm thinking have a box that comes up (and is semi transparent) but the click passes through it. Maybe there is a better way? Also i wouldnt know where to start with transparent windows or pass through clicks
I'd look at putting an icon in the SysTray, combined with balloon tips, that's the Windows way I think. Especially since it's even been renamed to the Notification Area.
Look at the NotifyIcon Class.

Categories

Resources