Windows aplication that lives only in the taskbar - c#

I'm new to windows programming (any win 32 API).
I want to create a windows application that listens to the clipborad all the time and reacts to keyboard shortcuts (for example you copy text from the ClipBoard and press Ctrl-F and something is done on the text in the clipboard).
I know how to make a window app in win32 and in C# (.NET) but it's a windowed application which has a window and appears in the window panel.
I want an pplication that will only be visible in the taskbar right part so you can close it (like most antivirus do) and keeps on running from start will it's closed.
Anyone got some code template, or can reffer me to a tutorial ? i don't mind if it's C\C+ or C#.
10x.

It can be another windows application in which the form's ShowInTaskbar property is set to false and you add a NotifyIcon component to put it into tray. Here is an article from CodeProject. You can find many more on codeproject or on other programming related sites.

You may find this useful, although it's in C.
Or this in C#.

Related

Manage Alt+Tab in .net application

I am developing a simple chat application which works in LAN. I have a problem in ALt+Tab.
When I open 2 applications (One is mine and another one say Firefox), now it switches properly between two windows when I press Alt+Tab.
Now I will minimize firefox. So now my app is the only one in foreground. Now if I press Alt+Tab, firefox comes foreground which is not expected (or I dont expect).
How to make Alt+Tab not work when all windows are in minimized state ?
I am using vb.net but c# is also OK for me and for example I have given firefox; there may be n number of windows in minimized state.
Please help me.
Pressing ALT + TAB in Windows (or other OS) is supposed to switch between every active application that is running and has a top-level Window. So the behavior you are describing is actually working the way it is supposed to.
More on Wikipedia about that.
However, it is possible to hack this behavior by capturing the ALt-Tab event. It is actually used by several remote control application so they can transmit commands from one computer to another.
Here is a start up guide, but beware that you get into Windows weird APIs and low-level functionnality. Use at your own risk...

Automatically pop up tablet touch keyboard on WinForms input focus

When I run a WinForms (or Delphi, see at the end) application on Windows 10 in a tablet mode, a touch keyboard does not pop up automatically, when an input box is focused.
I believe that this should happen automatically, without any additional code/setup.
For a test, I have the simplest VS 2015 WinForms desktop application with a single TextBox control.
It's simply the default Windows Forms Application C# project as created by Visual Studio. No code added, no properties changed. Just the TextBox was added, by dropping from the Toolbox (again no properties changed):
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox1.Location = new System.Drawing.Point(64, 27);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 0;
To verify my assumption that the pop up should be automatic:
I've tried to run Windows XP version of notepad.exe on Windows 10. It automatically pops up the touch keyboard. I doubt the Windows XP had any explicit support for touch keyboards.
I've also tried some ancient MFC applications (for example FileZilla 2.2.15 from 2005). It also pops up the touch keyboard on all its input boxes. Again, I'm pretty sure, the MFC had no explicit support for touch keyboards either.
The same for applications built on wxWidgets (for example FileZilla 3.x).
It looks like there's something broken in WinForms that prevents the automatic popup. Interestingly, the automatic pop up works:
for (editable) combo boxes (ComboBox with DropDownStyle = DropDown)
for text boxes in a password mode (TextBox.PasswordChar)
for rich text boxes (RichTextBox)
when the input box has focus at the moment the hardware keyboard is "removed" (I test this by flipping the screen on Lenovo Yoga notebook), but never after.
I've seen all the hints about an explicit popup by running the TabTip.exe. E.g.:
How to use Windows On-Screen Keyboard in C# WinForms
Open and close Windows 8 touch keyboard tabtip under desktop
How do I close the on-screen keyboard process from C# winform correctly?
Keyboard Winforms on Windows 10 (surface)
Most of the "solutions" offer a code like this:
var progFiles = #"C:\Program Files\Common Files\Microsoft Shared\ink";
var keyboardPath = Path.Combine(progFiles, "TabTip.exe");
this.keyboardProc = Process.Start(keyboardPath);
But I cannot believe this could be the "official" way. If for nothing else, then because there's no clean way to hide the keyboard opened by running the TabTip.exe (solutions include hacks like killing the process or sending Esc key).
And actually the above hack does not seem to work anymore in Windows 10 Anniversary Update:
Show touch keyboard (TabTip.exe) in Windows 10 Anniversary edition
Interestingly, I see the same behavior with Delphi/C++ Builder/VCL applications. The keyboard does not pop up for edit boxes (TEdit). It does pop up for combo boxes (TComboBox) and for edit boxes in a password mode (PasswordChar). Interestingly not for TRichEdit, what is notable difference to .NET RichTextBox, that maybe worth investigating.
This (unanswered) question describes an identical behavior:
Application written Delphi XE8 touch in edit boxes keyboard not appear in Windows 10.
The root cause seems to be that Winforms' textBox is not an AutomationElement, while the rest of the mentioned controls (ComboBoxes etc) are.
Quoting Markus von und zu Heber's accepted answer here:
We found it in the article "Automatic Touch Keyboard for TextBoxes in
WPF Applications on Windows 8+", but it also works very good (and even
easier!) for winforms. Thank you, Dmitry Lyalin!
Insert a reference to UIAutomationClient.dll to your project
In the form-load-handler of the application's main window, insert the following code:
var asForm = System.Windows.Automation.AutomationElement.FromHandle(this.Handle);
I've been down this road a few times and have only ever been able to implement the taptip.exe option. And in turn close the window by killing the process. I also found out that with some registry hacks you can get the keyboard to default to the handwriting panel if you so choose. But then that only works in Win8 and fails in Win10. Here is what I've done in case anyone else finds this useful:
RegistryKey registryKey = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\TabletTip\\1.7");
registryKey?.SetValue("KeyboardLayoutPreference", 0, RegistryValueKind.DWord);
registryKey?.SetValue("LastUsedModalityWasHandwriting", 1, RegistryValueKind.DWord);
Process.Start(#"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe");
I need to give credit to this post for the registry idea: Windows 8 Desktop App: Open tabtip.exe to secondary keyboard (for numeric textbox)
As far as I can tell, launching osk.exe or tabtip.exe pretty much is the "standard" way of making this work. I've found no "official" solution so far.
However, if it were me doing this, I wouldn't be killing the process or sending keys to try and dismiss the keyboard. Instead, you can obtain the window handle when you launch the process, and use that to minimize the window and hide it from the taskbar.
Someone here has gotten the window handle just to close it, but it gives you the idea: Show & hiding the Windows 8 on screen keyboard from WPF
If you need me to, let me know and I'll see if I can find the time to do up a full example.
As hinted by Ofek Shilon's answer, it seems that the touch keyboard can leverage the UI automation.
One can use implementation of UI automation from UIAutomationClient.dll.
For the UI automation to be magically injected into an application, class initializer of the assembly internal class UiaCoreApi have to be triggered.
On can achieve that for example by calling seeming no-op:
AutomationElement.FromHandle(IntPtr)(-1)
Another way is to implement automation UI explicitly. For that implement the ITextProvider/IValueProvider interfaces for the respective input control.
To bind the implementation of the interfaces to the control, handle WM_GETOBJECT window message with lParam = RootObjectId.
For an example of implementation, see
tombam's answer to How to use Windows On-Screen Keyboard in C# WinForms
or directly poster's article Implementing TextBox with on-screen touch keyboard.
Though interestingly, controls, for which touch keyboard works out-of-the-box (like combo box or password edit box, see the answer), do not implement the WM_GETOBJECT/RootObjectId. There must be a different machinery behind them.
Use a RichTextBox instead of a TextBox control. The RichTextBox supports the touch keyboard and will automatically pop up the keyboard when focus is gained. (similar to other input controls such as the combo box)
The RichTextBox also supports the same properties as the TextBox so it should be a drop in change in most cases. (Both controls derive from TextBoxBase)
I have noticed that if the touch keyboard has been dismissed after it pops up, you may have to tap twice on the control to get it to pop back up.

my C# winform needs to detect when other applications enter/exit/run-in TRUE fullscreen, prefer by events

my C# winform application needs put itself in standby mode during time other application runs in true fullscreen mode (not only maximized), like video games, video movies, powerpoint.
I need a method to detect if currently there is other application in fullscreen.
Is there a possibility to register to events which will fire when other application enters/exits fullscreen?
for both needs, I'll appreciate to have code snippets.
According to this question "full screen mode" is not that special, just create the right type of window and the OS will treat it as full screen. Once you know that, you can see here how to detect such windows.

Application not receiving event when clicked on taskbar

I have a .NET application (C#, WinForms) application running on Windows XP. If i minimize my application, and have several other windows minimized to the taskbar, and click on my application (in the taskbar) then often i see the taskbar "icon" blink but my application fails to "restore" its window. Any suggestions to what might cause this? Any hints on how to check if my application is not getting an event from the mouse-click.
UPDATE: Could anybody give an example of, how to output any incoming events to an application. Something that allows me to e.g. print the received events using Console.Writeline() to see, if my application gets an event when I click on the taskbar?
http://www.catch22.net/software/winspy-17
I venture to guess that your app will become in focus.
AFAIK this should not have anything to do with your application. Is there any other application running which always remains on top?
You dont handle maximising and minimising to and from the taskbar in your app. That is to say you dont have to. Windows deals with this and so this would appear to be in no way related to your app not handling an event, rather Windows doing something (or not doing something).

Detect and Prevent Overlapping Windows in C#

Anyone know of an efficient way of detecting movement of any windows currently open on a windows system? I need to detect a window's movement, determine if it collides with my applications Form, and bump it out from underneath if necessary.
I know I can scan through an enumerated list and check each window -- but that is way to intensive to perform constantly.
Background:
I have a taskbar-esque application that docks on the side of a user's screen. When the "Always on Top" feature is on, maximized windows will take up the remaining available space without covering the toolbar, as expected.
However, if you drag a non-maximized window over the toolbar, the application goes behind the toolbar (also expected), but you can no longer grab onto the title bar to move it back -- the window is stuck unless you disable "Always on Top" and then move it. So, I want to bump the window out from underneath.
Although not a direct answer, one possible solution to this is to create your application as an application desktop toolbar rather than a regular window. From the docs:
An application desktop toolbar(also called an appbar) is a window that is similar to the Microsoft Windows taskbar. It is anchored to an edge of the screen... The system prevents other applications from using the desktop area occupied by an appbar. (emphasis added)
This may not be a great fit for your scenario because it is oriented towards COM and unmanaged code rather than managed apps: however see this CodeProject article for info about using this feature from C#.
Failing that, you could try installing a hook (see SetWindowsHookEx) and listening for move messages but this is pretty low-level...
Try checking your PaintEventArgs ClipRectangle ..
(edit: and/or WindowFromPoint shooting match)
You can get notification of window movements using a CBT Hook: http://msdn.microsoft.com/en-us/library/ms644977(VS.85).aspx
http://www.codeproject.com/KB/dialog/FindWindow.aspx?msg=3262771
"FindWindow By Jörg Bausch"
Will get you the external (not your app's) window ID (IntPtr) the mouse went up over from within your C# application. For the desktop, and everything else on the desktop, it will return the same pointer (you can't distinguish, using this code, between as mouse-up on a folder, the desktop, the Recycle Bin).
http://www.codeproject.com/KB/cs/globalhook.aspx
"Processing Global Mouse and Keyboard Hooks in C# By George Mamaladze"
Will allow you to create GlobalHook for keyboard and mouse-events in C#. I've used it recently in VS 2010 beta 2 : it is NOT USABLE compiled against FrameWork 4.0, but does compile and work okay against FrameWork 3.5 and lower. If you download only George's demo app, be aware the download doesn't include the required dll, and will fail when you launch the .exe file (which I have brought to George's attention).
I've never worked with a "desktop application toolbar;" I hope this is relevant.
best,

Categories