Application not receiving event when clicked on taskbar - c#

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

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

Windows aplication that lives only in the taskbar

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

Multimonitor taskbar in .Net

I have an idea to write a multimotor taskbar application in c# for windows xp. So, does anyone have any information how
to put a taskbar on the second
monitor,
to make it use windows styles,
to prevent aplications running on the
second monitor to appear in default
taskbar,
so on...
Any help would be ...helpful )))
You can P/Invoke SHAppBarMessage() to create a task bar. The APPBARDATA.hWnd you'll need could simply be the Handle of a Form class. Anything goes as far as what you display.
Getting the notifications you'll need to make the task bar display active windows is going to be a whole lot more difficult. You'll need to use the global WH_SHELL hook, set by SetWindowsHookEx() to receive the notifications you'll need. You cannot set this hook in C#, it requires an unmanaged DLL that you can inject into a process. You'll find crucial help in this project.
Getting the Windows taskbar to not do its normal job is going to be impossible unless you somehow find the undocumented information you'll need. Microsoft doesn't document this for a good reason, the taskbar is an important part of the way they innovate on the Windows look-and-feel. Quite visible in Win7. They don't want any code to take a dependency on this, they'd have a near-impossible job of keeping the next version of Windows compatible. I'd have to recommend you completely disable the Windows taskbar and replace it by your own.

Programming a windows service

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

What event is sent to a Windows Forms window when its button from the taskbar is clicked?

When the user clicks the window title/button in the taskbar, what .NET event (or Windows API message) is sent to the window?
I'm using C#/.NET 2.0/Windows Forms.
Thank you
To discover the messages that are send to a window at various points you should consider using Microsoft Spy++. On my machine it is located at the following path
"D:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\spyxx.exe"
Note I am using 64bit OS hence the (x86).
The type and number of messages is quite big and I am sure varies slightly between OS versions like XP and Windows 7. However the key events/mesages would probably remain pretty constant.
WM_ACTIVATE (When activating and deactivating)
WM_WINDOWPOSCHANGING
WM_WINDOWPOSCHANGED
etc.
Another good tool is ManagedSpy, but I have not tried it on anything other than XP, it does not seem to run on Windows 7 64bit, but I have not done much investigation (Yet!).
http://msdn.microsoft.com/en-us/magazine/cc163617.aspx
The Activated and Deactivate events usually occur when you click on the taskbar button, but not always. They also occur when you just click on the window or click away to another window.
The one time I found that they don't occur is when the window is active, you click on the taskbar button to minimize the app, and Deactivate occurs as well as Activated. Then when you click on the taskbar button to restore the window, the Activated event doesn't fire. This seems weird to me.

Categories