WPF and NotifyIcon?

Using (or providing) Microsoft.NET Classes

WPF and NotifyIcon?

Postby Dick Bowman on Tue Aug 02, 2011 1:55 pm

Please would somebody tell me what I'm missing here?

I want to have a little bubble of text show up in the Windows Taskbar (just like FireFox does when it tells me there's a new version every couple of hours) when my application, running in the background, has something to tell me.

NotifyIcon looks like just what I want.

I look at Microsoft's WPF "documentation" and it tells me that NotifyIcon isn't part of WPF, but to go ahead and use the NotifyIcon of .Net. A little more hunting around gets me a code snippet. So I apply my transliteration "skills" and make a Dialog version...

Code: Select all
foo w
 ⎕USING←,⊂'System.Windows.Forms,System.Windows.Forms.dll'
 ⎕USING,←⊂'System.Drawing,system.drawing.dll'
 n←⎕NEW NotifyIcon
 n.BalloonTipText←'Hidihi'
 n.Text←'Hodiho'
 n.NotifyIcon←⎕NEW Icon(⊂w)
 n.Visible←1
 n.ShowBalloonTip 3000

⍝ MSDN sample code below -----------------------------------------------------

NotifyIcon notifyIcon = new NotifyIcon(); // Declaration
⍝ this.notifyIcon.BalloonTipText = "Hello, NotifyIcon!"; // Text of BalloonTip
⍝ this.notifyIcon.Text = "Hello, NotifyIcon!"; // ToolTip of NotifyIcon
⍝ this.notifyIcon.Icon = new System.Drawing.Icon("NotifyIcon.ico"); // Shown Icon
⍝ this.notifyIcon.Visible = true;
⍝ this.notifyIcon.ShowBalloonTip(1000); // Shows BalloonTip


The idea being to feed it the name of an icon file as argument, verify that it's working then transfer to my application (and pump a bit of writeup into my "how to use WPF from Dyalog" pages).

But - nothing happens. It seems to run - if I deliberately introduce stupid errors I get the expected failures. So it all seems legitimate. But I don't get to see a TaskBar icon and I don't see any bubbling text.

Makes me think that - once again - the bleeding obvious has escaped me.

Environment - 64-bit Windows 7 and 64-bit Dyalog 13.0. I've tried various Taskbar properties - like turning off autohide - seems to make no difference.
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm

Re: WPF and NotifyIcon?

Postby PGilbert on Tue Aug 02, 2011 5:07 pm

Hello Dick, what you did is not working for me either. The following is working however:

Code: Select all
      ⎕USING←,⊂'System.Windows.Forms,System.Windows.Forms.dll'
      ⎕USING,←⊂'System.Drawing,system.drawing.dll'
     n←⎕NEW NotifyIcon
     n.ShowBalloonTip 30 ⍝ seconds
     n.Icon←⎕NEW Icon(⊂'C:\MyIcon.ico')
     n.Text←'This is my Tooltip Text'
     n.Visible←1


I hope this is helpfull
User avatar
PGilbert
 
Posts: 362
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: WPF and NotifyIcon?

Postby Dick Bowman on Wed Aug 03, 2011 6:57 am

Thank you - as usual my error was crassly stupid, I'd set "NotifyIcon" when I should have set "Icon", hence a new version which does what I want...

Code: Select all
 foo w
 ⎕USING←,⊂'System.Windows.Forms,System.Windows.Forms.dll'
 ⎕USING,←⊂'System.Drawing,system.drawing.dll'
 n←⎕NEW NotifyIcon
 n.BalloonTipText←'Hidihi'
 n.Icon←⎕NEW Icon(⊂w)
 n.Visible←1
 n.ShowBalloonTip 3000   


What's interesting is that when I tried your code I got Status Window messages about "BalloonTipText cannot be empty", and I need to set a much higher value for the display period (documentation says milliseconds). I'm wondering whether there's some environmental sensitivity at work here.
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm

Re: WPF and NotifyIcon?

Postby MikeHughes on Wed Aug 03, 2011 10:33 am

I'm not sure about the MSDN sample but if you look at properties/methods I believe you should have used

n←⎕new NotifyIcon
n.Icon←⎕new Icon (⊂w)
n.Visible←1 ⍝ Icon becomes visible
n.BalloonTipText←'Hidihi'
n.ShowBalloonTip 3000

n.Dispose ⍝ to remove it
User avatar
MikeHughes
 
Posts: 80
Joined: Thu Nov 26, 2009 9:03 am
Location: Market Harborough, Leicestershire, UK

Re: WPF and NotifyIcon?

Postby MikeHughes on Wed Aug 03, 2011 10:34 am

Sorry didnt see Pierre's reply - was working from the Forum daily email
User avatar
MikeHughes
 
Posts: 80
Joined: Thu Nov 26, 2009 9:03 am
Location: Market Harborough, Leicestershire, UK

Re: WPF and NotifyIcon?

Postby Dick Bowman on Thu Aug 04, 2011 9:58 am

Dispose - in this situation - appears to have an unhelpful (side)effect...
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm

Re: WPF and NotifyIcon?

Postby MikeHughes on Fri Aug 05, 2011 6:49 am

Which is?

I think I missed that - mine seemed Ok.
If I deleted it (or it went out of scope) and I hadn't used Dispose, the icon stayed in the system bar until I cleared the ws but was not accessible.
User avatar
MikeHughes
 
Posts: 80
Joined: Thu Nov 26, 2009 9:03 am
Location: Market Harborough, Leicestershire, UK

Re: WPF and NotifyIcon?

Postby Dick Bowman on Mon Aug 08, 2011 4:04 pm

Apologies for the delay - decided that turning over my compost heap was more appealing than looking at WPF. Then I had to go rioting and looting.

Anyhow - when I use Disclose the NotifyIcon disappears immediately after it's shown. Maybe the right thing to do is to make sure the disposing is done after a suitable delay. There is something peculiar about the ShowBalloonTip time argument, which seems to be susceptible to overrides from other global (not APL-global) settings - this might explain why it seems to linger forever for you.
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm


Return to Microsoft.NET

Who is online

Users browsing this forum: No registered users and 1 guest