Tray Icon

Started by Haakon Birkeland, May 04, 2005, 02:09:51 AM

Previous topic - Next topic

Haakon Birkeland

Couple of probably stupid questions
There are quite a few example of tray icons on PB's site. They all seem to make use of %WM_InitDialog and %WM_TrayIcon events. I don't see know where those events are in FF.
Where do you define Global variable in FF ?

bert
Haakon 8o)

Roger Garstang

WM_INITDIALOG is for DDT/Dialog Windows, in FF/SDK it is WM_CREATE.  %WM_TrayIcon is a user defined equate that is given to the Tray Icon Function in a NOTIFYICON Type and is the message sent to the Window Hwnd that is also given in the Type.

Globals you can actually define anywhere...PB doesn't care and is a 2-pass compiler, but to keep it Clean and help FF out in parsing it would be good to put them in what VB would call the General section that is outside and above any functions in the code window...and luck would have it Paul calls it the same thing.

Haakon Birkeland

Ok From what I gather here is what I have in WM_CREATE

Function FORM1_WM_CREATE ( _
                        hWndForm As Dword, _  ' handle of Form
                        ByVal UserData As Long _  'optional user defined Long value
                        ) As Long
       ti.cbSize           = SIZEOF(ti)
       ti.hWnd             = hWndForm
       ti.uID              = hWndForm
       ti.uFlags           = %NIF_ICON OR %NIF_MESSAGE OR %NIF_TIP
       ti.uCallbackMessage = %WM_TRAYICON
       ti.hIcon            = LoadIcon(hWndForm, "c:\pbtools\firefly\projects\pbcards.ico")
       ti.szTip            = "Task Tray Example"
       Shell_NotifyIcon %NIM_ADD, ti
       DestroyIcon ti.hIcon
       Function =1


I think my problem is in ti.hIcon, the parameter for loadicon is wrong. SDK is really chinese to me.can somebody tell me where to get this value

bert
Haakon 8o)

Roger Garstang

c:\pbtools\firefly\projects\pbcards.ico is a filename.  You need to make it a resource identifier.  And thus need it in a Resource.

TechSupport

Quote from: Roger Garstangc:\pbtools\firefly\projects\pbcards.ico is a filename.  You need to make it a resource identifier.  And thus need it in a Resource.
Roger is right. You will need to add a new "Resource Module" to your project and then add the following line to it.


TRAYICON    ICON DISCARDABLE "PBCARDS.ICO"


Then you can refer to it in your code like this:

ti.hIcon            = LoadIcon(App.hInstance, "TRAYICON")


If LoadIcon does not work well then you may wish to look at the LoadImage API call - it is more versatile.

Notice also that I used App.hInstance instead of hWndForm. You need to pass the handle to the application's instance rather than a Window handle.

Also, if you have specified a code output directory other than the project directory then you will need to copy your icon to that directory as well, otherwise the RC Compiler will not be able to find the icon and it will GPF.

Haakon Birkeland

Thank again. I still have to learn a lot of the basics.

bert
Haakon 8o)

Haakon Birkeland

Hi there again. I have had my application works for a few days. Basically it checks for email without having the email program open. Basically it is a clone of Popwiz from Don Dickenson. As a learning program it was great.
Now what I would like to do is when I launch the application, I would like no window to open and only the icon added to the tray.
When I press minimize the app minimizes to the tray icon and doesn't show in the taskbar(great).
But what am I missing for it to go directly to the trayicon on startup?

Bert
Haakon 8o)

Roger Garstang

WS_VISIBLE Style of the form.

Haakon Birkeland

Haakon 8o)