How could I force windows to handle my program first - c#

I developed a desktop program (C#) with the purpose to notice me every 30 minutes a message (a message box appear on topMost and the program icon on taskbar blinks), then the OK_klick event remove the property topMost and the counter restart from zero.
But sometimes:
my form doesn't appear topMost, but other applications (generally Web pages) cover it (I bypassed this with flashing the icon on task bar)
my application semms hasn't pryority on other process (for example a web page is loading) with the result the form appear at later time.
Is it possible to give to my app an higer priority in order to, whatever the system is doing, the form appear in time?
My app runs on Vista, DotNet4.0, language C#
Thanks in advance for any suggestion.

Related

Way to tell if my winforms app has become a Background Process

I have a winforms app that is capable of showing forms, and even upon closing the last visible form will continue to run in the background - and I make use of a notify tray (system tray) icon to show that it is running.
I have code in place to prevent right click\Exit on this icon if any forms are visible. I check that
System.Windows.Forms.Application.OpenForms > 0
and while this seems to work for the most part, it may not be reliably (testing this application on other machines seems to yield unexpected results). Is there a way to check if a winforms app is running as a background process (as opposed to counting the number of open forms)?

UAC Window On Top

I seem to be running into a dead end here. I have a project that does the following:
just runs and stays in notification area
when user presses middle mouse button, it shows a form
user can then chose whatever from the form, and be happy.
This is working just fine, however what is NOT working is that when the form is shown, it does NOT activate.
Now, prior to me modifying the app.manifest to requireAdmin, it was working fine. Any time the form was shown, boom it was active.
But now that i'm running the form as Administrator, given that I need to be able to control one of our other applications with it (that is ran as admin as well), the form comes up just fine, but doesn't activate.
I have tried:
- TopMost = true inside of the Form_Load method
- Calling SetForegroundWindow with the forms handle on Form_Load
- Calling ShowDialog both on Form_Load and also tried it when the form was built.
- Calling Activate on Form_Load as well as when the form was built
Here's my layout:
Program runs, requires UAC permissions due to the manifest, user agrees, and it kicks off
Only a notification icon appears, shows a nice little bubble saying it's running
Program.cs monitors the keyboard/mouse hooks
When middle mouse button, or any of the keyboard hooks are triggered, it creates a new form object
sets the location of where the form should appear
and then finally shows the form.
Again, without UAC and requireAdmin inside of the app.manifest, this works fine. But once it is running as admin, nope, wont stay in front.
I know that MS has made the SetForegroundWindow requirements much stricter with later versions of windows (Vista, 7, 8), but i really need to be able to make this form show as the top most, active window (like a context menu).
How can i do that properly?
You could split your program into two, a non-admin requiring half that sits in the tray and watches for the middle button, and the half that requires admin permission that you launch when the mouse button is pressed. The non-elevated half could then call SetForegroundWindow or AllowSetForegroundWindow as needed.
If you want to avoid a UAC prompt every time you can cache a COM elevation object via the CoCreateInstanceAsAdmin method and use it repeatedly.

How to hide the wait cursor while loading windows mobile program

I have an application written in C# and running on Windows Mobile 5. It currently takes several seconds to load all of the assemblies. During that time the wait cursor spins on top of the screen. I would like to show a splash screen with a progress bar instead. How can I prevent the cursor from being displayed?
You can't. The CF execution engine (i.e. mscoree) itself makes the call to set the wait cursor, and this happens before it even starts JITting code. There's no way to hook into that and no registry entry (known or undocumented) that can turn the behavior off.

Screensaver Hides Desktop

we would like to build a screensaver that shows the desktop and the running applications but prevents user input by showing the login screen. The idea was to build a windows app with no window or a transparent window. However, as soon as the screensaver gets activated the desktop and all applications are hidden from the screen.
Is it possible to start the screensaver without hiding the desktop?
Thx,
bja
Is it possible for you to implement this as something other than a screensaver? I'm assuming that the Windows API does have a method that allows you to tell how long the computer has been idle (otherwise, how does the stuff that manages screensavers do it?), so if you use that you could just set up your application such that it's continuously running as a background process, and will pop up a modal dialog box (or your idea of a transparent window) or something that prompts for the user's login info when the computer has been idle for a certain amount of time.
Why can't you just grab an image of the screen when the SS kicks off. Then use that as the backdrop of your SS.
Vista has a bubbles screen saver that just starts putting bubbles on the screen. Not sure how they do it.
You are better off just creating a full-screen application with a transparent window that starts up on a timer like a screensaver. The screensaver functionality while similar to what you are doing, functions much differently.
As an alternative suggestion, you could always use a service (or background app) to gather the information you want these monitoring tools to display, or even just to grab periodic screenshots of the (hidden) desktop, and then have your screensaver query that app to get the data it needs to display.
That way, you get the benefit (the secure desktop, the usual Windows login sequence, etc.) of a screensaver, but still get to display what you need to.

How do I determine program interupt in Windows Mobile

I have an game application I have written for Windows Mobile and I want to have a timer associated with the puzzle. If the program loses focus for any reason (call comes in, user switches programs, user hits the Windows button) then I want a pop up dialog box to cover the puzzle and the timer to stop. When the user closes the pop up dialog the timer can start up again.
Does anyone know how to do this?
Thanks
Take a look at the article over at OpenNETCF's Community site on determining when a Form or Process changes.
A quick way would be to use PInvoke to call GetForegroundWindow() and GetWindowText() whenever your timer ticks (once a second?).
GetForegroundWindow() returns a windows handle which you can use to call GetWindowText(). If the text of the foreground window matches your form's Text property (its caption), you know your app has the focus. You can then show or hide your puzzle in each timer tick.

Categories