|
IE 6 is not the reason. I use Windows Xp with IE6 and the balloon is not shown...also MS Office con not be the reason because i also have Office XP.
|
|
|
|
|
DaPan, Your balloon does not show? I had the same problem with WinXP but it was because I had disabled Balloon Tips in the registry (using TweakXP). You can search on the net for enableBalloonTips to find out how to renable.
|
|
|
|
|
Is there a way to accomplish this in C++? Please post it.
|
|
|
|
|
I do not have a C++ version but it would not be too hard to port it. In fact interacting with the tray is easier in C++ since you don't have to deal with interop (defining the data structures etc.)
Joel
|
|
|
|
|
Hi Joel,
I think you have forgotten an important command in your Create routine. You set the data.dwState = NotifyState.Hidden but you have forgotten to set the data.uFlags to change that value. That means you should change your code to:
private void Create(uint id)
{
....
data.uFlags |= NotifyFlags.State;
if(!m_visible)
data.dwState = NotifyState.Hidden;
data.dwStateMask |= NotifyState.Hidden;
....
}
Regards Ulli
|
|
|
|
|
Yes I think you are correct. Thanks.
Joel
|
|
|
|
|
Well I downloaded the source and the exe demo. Both have the same problem on my system.
I get a unhandled exception when I click on "Add", it breaks and takes me to line 219 of Form1.cs which is "NotifyIcon = new NotifyIconEx();"
Since the Default and Empty constructor is throwing an exception, something you are initializing in the NotifyIconEx is throwing an exception. I am having trouble tracking this down. Though I would post it so others could see it, I will continue to see if I can fix it, if I do I will post the fix. However I am new to C# and trying to learn, so I am not sure if I will. hehe
Just an FYI for my System Configuration:
MS Visual Studio version 7.0.9466
MS .NET Framework version 1.0.3705
Windows XP Pro 2002
Thanks,
Aalst
|
|
|
|
|
This is strange indeed as this article has been posted for some time now and nobody has reported a problem. I tested it again and found no problems. Maybe you can give me the exact sequence of events that cause the exception. Also the exact text of the exception would be handy.
Joel
|
|
|
|
|
Well the exact sequence of events are simple. I run the exe I downloaded and click the "Add" button, then BOOM, it blows up. That's all. When I download the source, and open the solution, I do a debug build, then run and click the "Add" button, then BOOM again.
This is the details from the EXE:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.TypeInitializationException: The type initializer for "JCMLib.NotifyIconEx" threw an exception. ---> System.Security.SecurityException: Request for the permission of type System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
at JCMLib.NotifyIconEx..cctor()
--- End of inner exception stack trace ---
at JCMLib.NotifyIconEx..ctor()
at NotifyIconTest.Form1.OnClickCreate(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/windows/microsoft.net/framework/v1.0.3705/mscorlib.dll
----------------------------------------
NotifyIconTest
Assembly Version: 1.0.831.37168
Win32 Version: 1.0.831.37168
CodeBase: file:///S:/Applications/C%23%20Source%20Code/NotifyIcon%20Class%20Wrapper%20Example/NotifyIconTest.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/windows/assembly/gac/system.windows.forms/1.0.3300.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/windows/assembly/gac/system/1.0.3300.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/windows/assembly/gac/system.drawing/1.0.3300.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.
This is the error info from running in debug mode:
::Call Stack Window::
> NotifyIconTest.exe!NotifyIconTest.Form1.OnClickCreate(System.Object sender = {Text="Add"}, System.EventArgs e = {System.EventArgs}) Line 219 + 0x14 bytes C#
system.windows.forms.dll!System.Windows.Forms.Control::OnClick(System.EventArgs e = {System.EventArgs}) + 0x63 bytes
system.windows.forms.dll!System.Windows.Forms.Button::OnClick(System.EventArgs e = {System.EventArgs}) + 0x38 bytes
system.windows.forms.dll!System.Windows.Forms.Button::OnMouseUp(System.Windows.Forms.MouseEventArgs mevent = {X=107 Y=11 Button=Left}) + 0x11c bytes
system.windows.forms.dll!System.Windows.Forms.Control::WmMouseUp(System.Windows.Forms.Message m = {System.Windows.Forms.Message}, System.Windows.Forms.MouseButtons button = Left, __int32 clicks = 1) + 0x235 bytes
system.windows.forms.dll!System.Windows.Forms.Control::WndProc(System.Windows.Forms.Message m = {System.Windows.Forms.Message}) + 0x481 bytes
system.windows.forms.dll!System.Windows.Forms.ButtonBase::WndProc(System.Windows.Forms.Message m = {System.Windows.Forms.Message}) + 0x11a bytes
system.windows.forms.dll!System.Windows.Forms.Button::WndProc(System.Windows.Forms.Message m = {System.Windows.Forms.Message}) + 0x8d bytes
system.windows.forms.dll!ControlNativeWindow::OnMessage(System.Windows.Forms.Message m = {System.Windows.Forms.Message}) + 0x19 bytes
system.windows.forms.dll!ControlNativeWindow::WndProc(System.Windows.Forms.Message m = {System.Windows.Forms.Message}) + 0xda bytes
system.windows.forms.dll!System.Windows.Forms.NativeWindow::DebuggableCallback(__int32 hWnd = 1247558, __int32 msg = 514, __int32 wparam = 0, __int32 lparam = 721003) + 0x39 bytes
system.windows.forms.dll!System.Windows.Forms.Application::ComponentManagerSystem.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(__int32 dwComponentID = 1, __int32 reason = -1, __int32 pvLoopData = 0) + 0x2c1 bytes
system.windows.forms.dll!ThreadContext::RunMessageLoop(__int32 reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x1c5 bytes
system.windows.forms.dll!System.Windows.Forms.Application::Run(System.Windows.Forms.Form mainForm = {NotifyIconTest.Form1}) + 0x37 bytes
NotifyIconTest.exe!NotifyIconTest.Form1.Main() Line 207 C#
::Output Window::
'DefaultDomain': Loaded 'c:\windows\microsoft.net\framework\v1.0.3705\mscorlib.dll', No symbols loaded.
'NotifyIconTest': Loaded 'S:\Applications\C# Source Code\NotifyIcon Class Wrapper Example\NotifyIconTest\bin\Debug\NotifyIconTest.exe', Symbols loaded.
'NotifyIconTest.exe': Loaded 'c:\windows\assembly\gac\system.windows.forms\1.0.3300.0__b77a5c561934e089\system.windows.forms.dll', No symbols loaded.
'NotifyIconTest.exe': Loaded 'c:\windows\assembly\gac\system\1.0.3300.0__b77a5c561934e089\system.dll', No symbols loaded.
'NotifyIconTest.exe': Loaded 'c:\windows\assembly\gac\system.drawing\1.0.3300.0__b03f5f7f11d50a3a\system.drawing.dll', No symbols loaded.
'NotifyIconTest.exe': Loaded 'c:\windows\assembly\gac\accessibility\1.0.3300.0__b03f5f7f11d50a3a\accessibility.dll', No symbols loaded.
An unhandled exception of type 'System.Security.SecurityException' occurred in NotifyIconTest.exe
Additional information: Request for the permission of type System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
I hope this helps, I am still at a loss also.
|
|
|
|
|
Sorry, but at the moment I have no idea. What kind of user rights do you have. Do you have admin rights?
Joel
|
|
|
|
|
Yes, I have admin rights to my local computer and to my domain.
That should not matter, or using NotifyIcon would be useless, since not everyone has admin access when they are in a comapny.
My .NET security settings are at what ever the default is when you install, and what ever SP2 may have updated them to.
|
|
|
|
|
Joel, are you using the latest .NET Framework with SP2? Is your VS.NET the latest version? or are you still working with the beta VS?
Did you upgrade from Beta to Release? Or did you completely remove the beta, before install the release?
Everything I have is latest versions, and patches, on XP Pro. This error seems more like the java Serurity where you have a sercurity properties file that can loosen or tighten the internal security. .NET has a similar thing, and this seems to be related. Your code is trying to do something in violation of the .NET security policy which are currently set to default settings. I have never had the Beta software for .NET Framework or VS.NET on this computer. I wonder if MS made security changes when they released, and if you upgrade they do not implement them, because they just move your exisiting security settings.
This is all I can think of. I tried your previous simpler Balloon code from your other article and it gives the same problem.
I do not know enough C# or .NET yet to help more than this.
Aalst
|
|
|
|
|
I am running RTM .NET, with SP2, XP Pro with all critical updates. It was a clean install (not an upgrade from beta).
I would assume that the problem is pretty isolated as this page has had 18000 hits and only one report of problems such as yours. Don't you just love computers?
Try to step through the code (using step into) and find out which line of source code it gets to before it throws an exception.
Joel
|
|
|
|
|
Well I set a break point at line 217 of Form1.cs, just before the line it breaks at with the exception. I stepped-into and it still gives an exception at line 219. It doesn't even step into the constructor of NotifyIconEx(). I thought that was strange but maybe its normal.
The exact error message in the box is:
=======================================
An unhandled exception of type 'System.Security.SecurityException' occurred in NotifyIconTest.exe
Additional information: Request for the permission of type System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
=======================================
I can not even catch this exception, if I try to it just seems to ignore my try catch block.
I am going to keep looking into this, if you have any other sugestions let me know, I want to help any way I can.
Aalst
|
|
|
|
|
Joel,
I asked for help in the main C# forum here, and I got a response for Leppie. Leppie's message pointed me in the right direction. The sercurity violation is that the program is running from a network share.
I it to my local drive and it works fine. Now I am concerned what is a security violation in the application that it can't be runned from a network share. I run other C# apps from there all the time never a problem until now.
Then I wonder once the problem is know, if it can be fixed.
Well there we have it, at the present time your project has to be run from a local physical drive.
Aalst
|
|
|
|
|
Yeah I checked, and there are no compiler options to fix this. I only have 3 choices.
1 - Don't run code from network shares.
2 - Increase the trust level on a assembly by assembly bases.
3 - Adjust the Intranet Zone security to Full Trust.
I did 3 and it works fine. In my mind, Intranet and Local machine security are the same since I am the Admin. So I do not usually consider this. So I should not have this problem again.
Thanks for your help...
Aalst
|
|
|
|
|
Now you mention it I have heard of this issue before but have not researched it. You will find that it seems to be the creation of the hidden NotifyWindow class that is the problem. But I have no idea what is so special about this class!
You will find that security is one of the most little understood aspects of programming (due to the 'yawn factor' I would guess).
Sorry I can't be more insightful.
Joel
|
|
|
|
|
Just wanted to say that this control works on VB.NET very easily. Thank you for creating it.
kl
|
|
|
|
|
I was looking thru your code, and in the CreateOrUpdate procedure, something has me worried:
Create(m_nextId++);
since m_nextId is static... wouldn't it be possible for this to cause threading issues?
maybe it should be something like:
lock( typeof( NotifyIconEx ) ) {
Create( m_nextId );
m_nextId++;
}
and while we're on the subject... what is the point of having the hidden window and the nextId be static?
I don't profess to know a whole lot about threading in general, so just slap me down as needed
|
|
|
|
|
First off you are correct about the potential threading issue. However it would only be a problem if you were creating more than one icon using multiple threads which is not going to be something most people need to do. So I probably should have mentioned that this class is not thread safe as is. It would probably be trivial to fix thise using something like you have suggested (I have not played with lock() yet so I can't comment on it).
The reason that these members are static is that for each instance of the application I wanted one hidden window to handle all icons associated with that app. Also for every instance of notify icon created you need to make sure that you don't try to add an icon to the notify area with the same id, i.e. the id for each icon must be unique. The easiest way to do this is to make the next id static.
Hope this makes sense - Joel
|
|
|
|
|
How to send message to notification icon from other program such as Windows Service?
|
|
|
|
|
You really need a seperate service GUI app to do this. The biggest hurdle is deciding how to communicate with the service. You can use a variety of methods depending on how complex and numerous the communication needs to be. Methods include:
1. Shared memory. (Service and GUI must run on same machine).
2. Windows messages (data is limited unless you use 1.)
3. Socket communication (requires some work, but GUI and service need not be on the same machine).
4. .NET remoting may be a good choice for complex data passing. Learning curve but GUI and service may be on different machines.
5. Registry in tandem with window messages (yuck)
5. Window messages and shared data files.
Hope this gives you some ideas.
Joel
|
|
|
|
|
Joel,
A seventh option that would work with "legacy" applications and ".NET" applications alike, is to use DCOM. From the ".NET" perspective, this is virtually identical to use remoting.
--
Paul
"I drank... WHAT?"
|
|
|
|
|
1) the uint( UInt32 ) data type is not CLS compliant. I suggest you use Int64 or Int32 instead in the public ShowBallon method, and then convert it to an uint internally.
2) I believe the Dispose override should call base.Dispose() after Remove()
3) Make more virtual methods, so we can subclass this effectively.
4) I suggest you take a look at the standard pattern for event raising across the BCL. things you should consider doing along this line:
4a) make the NotifyIconHandler delegate a void NotifyIconTargetEventHandler( Object sender, NotifyIconTargetEventArgs e )
4b) subclass EventArgs to make NotifyIconTargetEventArgs with the Id as a get-only property.
4c) make the OnEVENT methods protected, virtual, and only receive the NotifyIconTargetEventArgs
4d) use the onEVENT methods to determine wether the event is null, and raise it with "this"
4e) use EventArgs.Empty instead of new EventArgs()
5) maybe change ClickBalloon event to BalloonClick, the former sounds more like a method that _does_ the clicking.
overall, very usefull code. good job.
|
|
|
|
|
In answer to your points:
1) the uint( UInt32 ) data type is not CLS compliant. I suggest you use Int64 or Int32 instead in the public ShowBallon method, and then convert it to an uint internally.
- Picky but point taken.
2) I believe the Dispose override should call base.Dispose() after Remove()
- I will fix this.
3) Make more virtual methods, so we can subclass this effectively.
- I am married with 4 kids so you do it
4) I suggest you take a look at the standard pattern for event raising across the BCL. things you should consider doing along this line:
4a) make the NotifyIconHandler delegate a void NotifyIconTargetEventHandler( Object sender, NotifyIconTargetEventArgs e )
4b) subclass EventArgs to make NotifyIconTargetEventArgs with the Id as a get-only property.
- Somebody needs to explain why I should do this since it is just more work than passing the id. Maybe I am missing something. Why bother creating a new class just to pass an id. Just because that's what the .NET library does?
4c) make the OnEVENT methods protected, virtual, and only receive the NotifyIconTargetEventArgs
4d) use the onEVENT methods to determine wether the event is null, and raise it with "this"
- That would be just the way you would do it maybe. You need to give good reasons if you are going to make this kind of suggestion.
4e) use EventArgs.Empty instead of new EventArgs()
- Why? To save memory on the heap? The docs don't say this but I assume it does otherwise what's the point?
Wow, you are pretty picky dude
|
|
|
|