Custom Icons

New to FreeBASIC? Post your questions here.
Post Reply
Peter W
Posts: 19
Joined: Jan 19, 2008 2:29
Location: Tasmania, Australia

Custom Icons

Post by Peter W »

I would like to be able to show custom icons in the system tray which vary
according to the status of my program.

I want to be able to draw to a buffer and then show that buffer in the system tray
but I do not know how to convert it into an icon.

I have simplified the following code to demonstrate what I want to do.
Can anyone help please ?

Thankyou for any help.
Peter W.

Code: Select all

#define WIN_INCLUDEALL
#include once "windows.bi"

SCREENRES 200,200,32

DIM SHARED AS HWND hWin

Dim SHARED As HWND hWndTaskBar
hWndTaskBar = FindWindow("Shell_TrayWnd", NULL) 'GET HANDLE OF TASKBAR
hWin = FindWindow("Shell_TrayWnd", NULL) 'GET HANDLE OF TASKBAR NOTIFICATION AREA

Dim Shared As NOTIFYICONDATA NID
With NID
    .cbSize         = SizeOf (NOTIFYICONDATA)
    .hWnd           = hWin
    .hIcon          = LOADIMAGE(NULL, MAKEINTRESOURCE(32512),IMAGE_ICON, 0, 0, LR_SHARED)
    .uFlags         = NIF_INFO or NIF_ICON or NIF_TIP or NIF_MESSAGE
    .szTip          = ""
    .szInfoTitle    = ""
    .szInfo         = ""
End With

SUB SHOW_ICON
    SetWindowPos(hWndTaskBar,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE Or SWP_NOMOVE)
    Shell_NotifyIcon (NIM_ADD, @NID)
    Shell_NotifyIcon (NIM_MODIFY, @NID)
    SLEEP 1000
    Shell_NotifyIcon(NIM_DELETE,@NID)
END SUB

PRINT "SHOW ICON EXAMPLE 1"
SHOW_ICON

PRINT "SHOW ICON EXAMPLE 2"
NID.hIcon = LOADIMAGE(NULL, MAKEINTRESOURCE(32513),IMAGE_ICON, 0, 0, LR_SHARED)
SHOW_ICON

PRINT "SHOW ICON EXAMPLE 3"
NID.hIcon = LOADIMAGE(NULL, MAKEINTRESOURCE(32514),IMAGE_ICON, 0, 0, LR_SHARED)
SHOW_ICON

'CREATE CUSTOM IMAGE FOR ICON
DIM IMAGE AS ANY PTR = IMAGECREATE (16,16,RGB(0,255,0),32)
DRAW STRING IMAGE,(4,4),"A",0
PUT (0,50),IMAGE    'DISPLAY TO SCREEN
NID.hIcon = " MAKE MY IMAGE INTO AN ICON "
SHOW_ICON

SLEEP
led-bloon
Posts: 33
Joined: Jan 06, 2010 8:16

Re: Custom Icons

Post by led-bloon »

Here's a link that may be of use:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx

I also note in your sub show() you do a NIM_ADD and a NIM_MODIFY. You only need to do an initial
NIM_ADD and from there on the NIM_MODIFY should do the work for you.

Good luck with it
Rgds
lost-led
Post Reply