|
I realy enjoy this interesting article. But it does not display unicode. Can you tell me why ? I have tried it with a [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode] but it's not work.
Thank for your read !
|
|
|
|
|
Since I think the .NET CLR/runtime uses unicode strings then the code should work with unicode already.
What problems are you having with the code as is?
Joel
|
|
|
|
|
Good day. Indeed, the tray balloon does not display Unicode characters properly on XP; they display as '?' characters on my machine.
To fix this, add the CharSet=CharSet.Auto attribute to the "NotifyIconData" StructLayout declaration AND the "Shell_NotifyIcon" DLLImport declaration. For more details, see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcharsetobjectfield.asp
After this modification, Unicode characters should display just fine.
Joel - thanks for the great work on this control.
|
|
|
|
|
Windows XP has the ability to hide unused tray icons. Balloon tooltip is not displaying for such hidden icons. I need to show the icon temporarily, display balloon and hide it again. How to do this? How to determine whether icon is hidden or not?
|
|
|
|
|
Good question! I have no idea, I would have to research it using MSDN. Let us know if you find anything out.
Thanks - Joel
|
|
|
|
|
At least not on W2K. I tried debugging my way out of it, but it seems the ClickBalloonNotify handler is never even initialized. What the hey?
|
|
|
|
|
I am also having the same problem.
|
|
|
|
|
It seems to work fine on XP. What OS are you using. I will try to test it on Windows 2000.
Joel
|
|
|
|
|
Well it looks like the balloon click is not fired on Windows 2000 with IE5, maybe IE6 needs to be installed or some other update (you know how these things are, it may need MS Office or something like that!)
Joel
|
|
|
|
|
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
|
|
|
|