I am developing a Wpf application. On installing my application, shortcut icons are created in the desktop and the program menu.
When i click the desktop icon for the time, my application opens. Now i minimize my application in the tray/task bar. On clicking my desktop icon, my application is not maximized. It still minimized in the tray/task bar. For ex, you can take a look at Skype, adobe reader etc..
Requirement - where ever the application icon is present in the PC such as desktop or program menu or etc., my application should be maximized when the user clicks the shortcut icon.
A desktop link will open a new application every time you click on it. If you want your application to open only once and change position/size of the original one once you start a new one, you will have to do this yourself:
Once you application starts, check if another version is already running.
Send your running application a message.
End itself.
If there was no other application started, run normally and liste for the message.
On arrival of the message, check if minized and if so, maximize (or change size/position to whatever you need).
Try to implement it and if you have a very specific problem with any of the steps, come to SO and ask a very specific question about it :)
Related
I have a C#/winforms application that runs minimized to the system tray. If I double click the EXE for this app it runs as it is supposed to, I see the process in task manager and the icon appears in the system tray. I also have a windows service which acts as a watchdog for the other app. If the winforms app gets closed the service restarts is using process.start
If the app is started from the service using process.start, firing off the same EXE file the process runs but the tray icon doesnt appear.
Just to be clear the winforms app puts the tray icon in place not the windows service.
Any idea why the app would react differently to a process.start than to a double click?
Edit: I may have partially answered my own question. The service is running as local system. Not sure some run as local system would be able to add an icon to my users system tray in the same manner a double click would. Does this sound like I am on the right track?
Yes, you're on the right track. Services run in a different session (session 0). If they open a window (which is highly discouraged), they are now called "interactive services". In that case, Windows pops up a dialog (see MSDN blog for a screenshot).
Similar things probably happen to the tray icon. Since you don't have a window, you don't get the popup dialog for interactive services, but the tray icon still exists in session 0, so you cannot see it.
If you're on Windows 8, interactive services have been disabled (MSDN) completely.
I have a C# console app that is trying to start a legacy desktop app. I want this legacy desktop app to start and display even if the current foreground window is the Windows 8 Start Screen or a Start Screen application.
If I start the legacy desktop app, it will launch, but it launches behind the Windows 8 Start Screen and does not show. If I click on the "Desktop" tile, I see the app has launched. But I want the app to launch /AND/ show.
Is there a way to both start a legacy desktop application and show it, even if the Windows 8 Start Screen is showing??
Any ideas??
Show desktop
From https://amalhashim.wordpress.com/2012/04/13/c-show-desktop/
Using C# we can write code to Show Desktop. Same effect as clicking on “Show Desktop” icon on Taskbar.
First, add reference to “Microsoft Shell Controls And Automation” from COM tab of “Add Reference” dialog
Shell32.ShellClass shell = new Shell32.ShellClass();
shell.MinimizeAll();
Or use this approach: Minimizing all open windows in C#
Check if Windows 8 start screen is active
IMetroMode::IsLauncherVisible in C# via pInvoke?
I have tried two installers - Setup2go, and Installmate Builder, and I have the same problem. At the last window of the install, I select the option to "Open program after installation finish", and sometimes (about 10% of the time?), my (Winforms) app's main window will open behind the Windows Explorer directory window I used to open the installation exe from.
The frustrating thing is - I am having trouble reproducing the problem reliably (the problem seems to occur around 10-20% of the time). I am using Windows 7 if that makes any difference. To clarify, if I open up the executable directly (rather than from the installation exe), the problem never occurs.
My knowledge on this kind of thing is limited - I recall a similar frustration happening with the MessageBox from this question
Any ideas?
It does not happen when you launch the app directly from installer because the shell allows it to “steal” the focus. When you launch it from the installer, the last interaction happens in the installer app. The system prevents the new window from stealing the focus from your installer. If installer window closes, then the explorer window which you used to start the installer is activated. Since the switch of the foreground window happened recently, the system does not allow to change the foreground window.
On the other hand, if your application window is shown before the installer window disappears from the screen, the the app will be placed below the installer in the Z-order; and when the installer window is finally hidden, the application window is activated.
So it's all related to timing between showing and hiding windows.
Although I am not expert in this area. You can use message tracers and WinAPI calls tracers like Spyxx which can give you more details on what happens in the system and why the new window of your application is placed below the Explorer window.
Make sure the window's title isn't changed, until the last possible moment. I moved the Text = "blahblah" line out of the Form_load event, and into the Form1_Shown event, and now the hidden taskbar icon problem has vanished. Also, the window doesn't flicker when it's loading.
I have a working Windows app that appears as an icon in the Windows system tray. When I click on my icon in the system tray it opens my application window, but the expanded system tray doesn't disappear. How do I tell the expanded system tray to hide itself once I've launched my application?
You don't. The notification area (often called "system tray") manages that stuff by itself, and applications shouldn't mess with it (that's why there are no APIs to affect substantially its behavior); read e.g. here.
I have started prgramming a windows service. I have added a notify icon from the toolbox.
It has the small notify icon that appears in the systray as a member of those icons.
It works so far.
So far I have a blank form. I have used the DoubleClick for the notifyIcon to bring up
the form (I will use the form for something later).
Now I have a list of things I want to accomplish to make this work like a true windows
service.
First of all, if possible, I owuld like to remove the maximize and cancel button on the form.
Most windos service apps that I have seen offer the ability to close the app by right-mouse-button clicking on the notify icon which brings up a menu of options.
I see in the properties of the form under Misc there is an CancelButton. But I do not see how do deactivate it. In the Properties of the forum I see under Window Style there is a ControlBox option that, if I turn to false, all three buttons, (minimize, maximize and cancel) go away.
These are not what i am looking for. I would not like the option for them to resize,
maximize or close the form here. I suspect people will close the box intending to
make the box go away while still wanting the app to run.
Under the "Focus" caption in Properties, there id "Deactivate". I have created my own
event/method/function for this and in debug I noticed that when you click on the x-box in the upper right corner, this function is called. The problem is that after the function is
over, the app closes anyway. How do I over-ride this function?
Secondly, how do you catch the right button click event on the notify icon in the
systray?
I can see how to create events for "Click" and "MouseClick" etc. but how so I determine
which button was click?
Using the right buton click is how such programs know when to pull up a menu. So I would
like to know how to do this as well.
Windows services should not display notification icons, nor show forms. You'll find out very soon that post Vista they are explicitly forbid from doing so.
You need to split your application into a user program that may show an icon in the notification tray and shows forms, and the service. They need to be distinct processes and communicate via IPC (shared memory, named pipes, sockets etc).
As to how to react to a righ-click on the notification icon question, you simply need to assign something in your designer to the ContextMenu property:
The menu is shown when the user
right-clicks an icon in the
notification area of the taskbar.
Shortcut menus also are known as
pop-up menus.
Standard Windows services do not run with any user interface at all. Generally speaking, your Windows service project type in Visual Studio won't contain any UI components whatsoever.
The UIs you see when working with other services are secondary applications designed to manage those services. Those may run in the system notification area ("tray"), or may run as minimized windows, may be MMC snap-ins, or may be separate applications the administrator launches on an ad-hoc basis.
As an example, SQL Server runs as a service, whether or not Management Studio or any of the other ancillary UI apps are running.
In any event, the user interface "component" of a service needs to be an entirely separate application. This is particularly important in the post-Vista world, for reasons cited by Remus Rusanu. You'll create a separate WinForms project to do this, and have it send messages to the service to control. (This may include the basics such as start, stop and restart; it usually also includes other service-specific commands.)
You may want to consider reading the following other questions here on StackOverflow for some guidance on the standard Windows Service/UI helper application pattern:
What can Services do under Windows?
What is the difference between a windows service and a regular application?
Creating a user interface for monitoring and interacting with a running windows service
Running an exe from windows service that interacts the the user’s desktop
Why do forms fail in Windows Services