Control taskbar blinking event of an other application - c#

I want to build a c# desktop application which checks the taskbar blinking event of a specific program. When ever the programs taskbar blinking event occurs my application will play an alarm sound. Is it possible and where to start please ?

One way would be to use something like EasyHook and basically replace the processes call to FlashWindowEx function.
However because you don't directly control this application it is likely to be error prone.

Related

Windows Forms Update Dialogs/Sub Windows Dynamically

In a simulator I am writing I use SFML and OpenGL to create a visualization with some basic OpenGL based GUI. Now I need to add a File Chooser Dialog. I was wondering if I could use System.Windows.Forms.OpenFileDialog and update it's events dynamically similarly to the way OpenCV allows you to update windows by using cv::waitkey().
Since OpenFileDialog.ShowDialog() does not return until the window is dismissed, all I have to do is somehow close the Dialog by updating it's events.
I would rather not have to call Application.Run() and leave it in the background because my application is already built around a main loop and Application.Run() takes over the main thread.
The equivalent call to cv::waitkey is:
Application.DoEvents()
However after reading Use of Application.DoEvents() it appears that Application.DoEvents() is much more fragile then cv::waitkey. It can cause an application to crash if there is no open win form.
Alternative Approach
I decided to switch to GTK# since it lets you process events as they occur by checking whether any events exist in the event queue by calling Gtk.Application.EventsPending(). Then the events can be processed with Gtk.Application.RunIteration() in a while loop like this:
while (Gtk.Application.EventsPending())
{
Gtk.Application.RunIteration();
}

Reading characters in a background application

Hi I'm trying to make a simple program that read keys from keyboard even if my application is running in the background.
Situation
I want make a timer to help me in a game. I already have the program with the timer, the problem is I can not start the timer without switching of the game window to my app window. So I configured the game keyboard to release the keys F11, F12. Now in game this keys do nothing.
Problem
I built a windows forms containing a listener for keydown event and a conditional for F11. But when I trigger another window (eg the game window) my application no longer hears the keyboard, cuz it's in the background.
Question
How can I build a app that hears the keyboard, even if it's not active window?
You need to install a global, low-level keyboard hook using the SetWindowHookEx API call. Using the WH_KEYBOARD_LL hook will set your application up to intercept keyboard events at all times, even when your application is not active.
This post on MSDN shows an example of how to achieve something close to what you want from C#.

Handling minimized programs

I need help handling minimized programs when using a custom/self made explorer.exe file .. because unless properly handled, minimized programs will just shrink to something like 100x50px and stay on screen. I worked out a Timer in C# to check for "iconic" processes, list their mainWindowHandler, and move them outside the screen with "MoveWindow". To bring them back I use the handler and the "ShowWindow" function wich works AWESOME .. but as I said, it involves a constantly running Timer, so there must be a cleaner/easier way of achieving this.
Any ideas? Some way to hook and raise an event when a window is minimized?
*please note: show and movewindow are functions from user32.dll. I'm not trying to catch when MY forms are minimized, but when the OTHERS programs are.
You can create a hook to check when windows are being minimized.
I found a CodeProject article that uses hooks to check when the user opens a system menu (ALT+SPACE) on any window, and then appends an extra item to it. You can use that code to check when the user hits the minimize button, and run whatever code you need there.
The CodeProject article is written in C++, but you can adapt the same method for C# (or use P/Invoke).

Emulate Key Presses On an App that takes no Win Messages

I want to send an Application Key Presses, To Automate some stuff that has to be done repeatedly and So I don't always have to cramp my fingers.
In C#, it's nice to use SendKeys.Send(), but this won't work because the Application doesn't take Windows Messages. SendKeys.SendWait() does nothing at all.
How would I STILL Simulate the Keyboard events?
Come To Think of It, I was going to use some P/Invoke to simulate Mouse Events too, but If it takes no messages, How Can I get around that?
EDIT - I can use mouse and keyboard to interact with the program, I just cannot manipulate it with Windows Messages sent from my own Code.
Have you tried AutoIt?
Is it a console app? If so, maybe you should be SendKeys'ing to the command shell instance it is running in.

Sending a mouse click to a button in the taskbar using C#

In an application that I am currently working on, a requirement is to bring a window of an external application to the foreground. Making Win32 API calls such as BringWindowToTop and SetForeground window do not work all the time. This is due to some restrictions within Windows XP. What I would like to do instead is send simulate a mouse click the window's button on the taskbar which I am hoping will bring the window to the front. Does anyone know how this is possible?
Check out the section "How to steal focus on 2K/XP" at http://www.codeproject.com/KB/dialog/dlgboxtricks.aspx, as this is exactly what you need. I wouldn't go the taskbar route as the taskbar could be hidden or simply not there.
It's possible. But it's extremely sketchy. Your application may also break with the next version of Windows, since it's undocumented. What you need to do is find the window handle of the taskbar, then find the window handle of the child window representing the button, then send it a WM_MOUSEDOWN (I think) message.
Here's a bit on finding the window handle of the taskbar:
http://www.codeproject.com/
FWIW, the restrictions on BringWindowToTop/SetForeground are there because it's irritating when a window steals focus. That may not matter if you're working on a corporate environment. Just keep it in mind. :)
I used this in a program where I needed to simulate clicks and mouse movements;
Global Mouse and Keyboard Library
To be honest I've never had an issue bringing a window to the foreground on XP/Vista/2003/2000.
You need to make sure you do the following:
Check if IsIconic (minimized)
If #1 results in true then call
ShowWindow passing SW_RESTORE
Then call SetForegroundWindow
I've never had problems that I can think of doing it with those steps.

Categories

Resources