Well, here's a starting point.
Running this will display the icon in the system tray and you will see its tooltip by holding your cursor over it.
For further interactions you could just read up on the MSDN articles and set the members of the NOTIFYICONDATA and message parameter of the Shell_NotifyIcon() function accordingly. You will have to receive and interpret windows messages sent from the tray icon to handle it further. This is easily done using BlueGUI if you have that, but there are other ways as well.
To run this code you will need to have Matrix1Utilities. An example icon is attached to this post.
// Constants
#constant true 1
#constant false 0
// WINAPI Constants
#constant IMAGE_BITMAP 0
#constant IMAGE_ICON 1
#constant IMAGE_CURSOR 2
#constant LR_CREATEDIBSECTION 0x00002000
#constant LR_DEFAULTCOLOR 0x00000000
#constant LR_DEFAULTSIZE 0x00000040
#constant LR_LOADFROMFILE 0x00000010
#constant LR_LOADMAP3COLORS 0x00001000
#constant LR_LOADTRANSPARENT 0x00000020
#constant LR_MONOCHROME 0x00000001
#constant LR_SHARED 0x00008000
#constant LR_VGACOLOR 0x00000080
// Message types used with Shell_NotifyIcon()
#constant NIM_ADD 0x00000000
#constant NIM_MODIFY 0x00000001
#constant NIM_DELETE 0x00000002
#constant NIM_SETFOCUS 0x00000003
#constant NIM_SETVERSION 0x00000004
// NOTIFYICONDATA flags
#constant NIF_MESSAGE 0x00000001
#constant NIF_ICON 0x00000002
#constant NIF_TIP 0x00000004
#constant NIF_STATE 0x00000008
#constant NIF_INFO 0x00000010
#constant NIF_GUID 0x00000020
#constant NIF_REALTIME 0x00000040
#constant NIF_SHOWTIP 0x00000080
// NOTIFYICONDATA states
#constant NIS_HIDDEN 0x00000001
#constant NIS_SHAREDICON 0x00000002
// NOTIFYICONDATA versions
#constant NOTIFYICON_LEGACY 0x00000000
#constant NOTIFYICON_VERSION 0x00000003
#constant NOTIFYICON_VERSION_4 0x00000004
// NOTIFYICONDATA info flags
#constant NIIF_NONE 0x00000000
#constant NIIF_INFO 0x00000001
#constant NIIF_WARNING 0x00000002
#constant NIIF_ERROR 0x00000003
#constant NIIF_USER 0x00000004
#constant NIIF_NOSOUND 0x00000010
#constant NIIF_LARGE_ICON 0x00000020
#constant NIIF_RESPECT_QUIET_TIME 0x00000080
#constant NIIF_ICON_MASK 0x0000000f
// Load libraries
#constant user32 1
#constant gdi32 2
#constant ole32 3
#constant shell32 4
load dll "user32.dll", user32
load dll "gdi32.dll", gdi32
load dll "ole32.dll", ole32
load dll "shell32.dll", shell32
// Attempt to create a system tray notification
hWnd = get dbpro window()
hIcon = LoadImage(0, "moose.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE)
pGuid = GUID_Generate()
pNid = CreateNotifyIconData()
NID_SetHWND(pNid, hWnd)
NID_SetFlags(pNid, NIF_ICON || NIF_TIP || NIF_GUID || NIF_SHOWTIP)
NID_SetHIcon(pNid, hIcon)
NID_SetTooltip(pNid, "This is a short tooltip message.")
NID_SetInfo(pNid, "Info text." + crlf$() + "This should have room for up to 255 characters.")
NID_SetVersion(pNid, NOTIFYICON_VERSION_4)
NID_SetTitle(pNid, "Title")
NID_SetInfoFlags(pNid, NIIF_USER)
NID_SetGUID(pNid, pGuid)
NID_SetBalloonIcon(pNid, hIcon)
Shell_NotifyIcon(NIM_ADD, pNid)
print "Press any key to quit...."
wait key
Shell_NotifyIcon(NIM_DELETE, pNid)
DeleteNotifyIconData(pNid)
DestroyIcon(hIcon)
GUID_Destroy(pGuid)
end
// WINAPI wrapper function
function LoadImage(hinst as dword, name as string, uType as dword, cxDesired as integer, cyDesired as integer, fuLoad as dword)
buffer = alloc(fast len(name) + 1)
poke string buffer, name
poke byte buffer + fast len(name), 0
handle = call dll(user32, "LoadImageA", hinst, buffer, uType, cxDesired, cyDesired, fuLoad)
free buffer
endfunction handle
function DeleteObject(hObject as dword)
success = call dll(gdi32, "DeleteObject", hObject)
endfunction success
function DestroyCursor(hCursor as dword)
success = call dll(user32, "DestroyCursor", hCursor)
endfunction success
function DestroyIcon(hIcon as dword)
success = call dll(user32, "DestroyIcon", hIcon)
endfunction success
function Shell_NotifyIcon(dwMessage as dword, lpData as dword)
success = call dll(shell32, "Shell_NotifyIconA", dwMessage, lpData)
endfunction success
// Functionality for managing a NOTIFYICONDATA memory structure
// Offsets
#constant NID_CBSIZE 0
#constant NID_HWND 4
#constant NID_UID 8
#constant NID_UFLAGS 12
#constant NID_UCALLBACKMESSAGE 16
#constant NID_HICON 20
#constant NID_SZTIP 24
#constant NID_DWSTATE 152
#constant NID_DWSTATEMASK 156
#constant NID_SZINFO 160
#constant NID_UNION_TIMEOUT_VERSION 416
#constant NID_SZINFOTITLE 420
#constant NID_DWINFOFLAGS 484
#constant NID_GUIDITEM 488
#constant NID_HBALLOONICON 504
#constant NID__SIZEOF 508
// Creates a zero-initialized memory area large enough to accommodate the NOTIFYICONDATA structure.
// The members are set through individual function calls in order to make a more readable constructor declaration.
function CreateNotifyIconData()
ptr = alloc zeroed(NID__SIZEOF)
poke dword ptr + NID_CBSIZE, NID__SIZEOF
endfunction ptr
// Deletes a NOTIFYICONDATA struct previously created with CreateNotifyIconData().
// Any open handles should have been released prior to calling this function.
function DeleteNotifyIconData(pNID as dword)
free pNID
endfunction
// Setter functions
function NID_SetHWND(pNID as dword, hWnd as dword)
poke dword pNID + NID_HWND, hWnd
endfunction
function NID_SetID(pNID as dword, uID as dword)
poke dword pNID + NID_UID, uID
endfunction
function NID_SetFlags(pNID as dword, uFlags as dword)
poke dword pNID + NID_UFLAGS, uFlags
endfunction
function NID_SetCallbackMessage(pNID as dword, uCallbackMessage as dword)
poke dword pNID + NID_UCALLBACKMESSAGE, uCallbackMessage
endfunction
function NID_SetHIcon(pNID as dword, hIcon as dword)
poke dword pNID + NID_HICON, hIcon
endfunction
function NID_SetTooltip(pNid as dword, tooltip as string)
poke string pNID + NID_SZTIP, tooltip, 127
endfunction
function NID_SetState(pNID as dword, dwState as dword)
poke dword pNID + NID_DWSTATE, dwState
endfunction
function NID_SetStateMask(pNID as dword, dwStateMask as dword)
poke dword pNID + NID_DWSTATEMASK, dwStateMask
endfunction
function NID_SetInfo(pNID as dword, info as string)
poke string pNID + NID_SZINFO, info, 255
endfunction
// As of Windows Vista, this member is deprecated
function NID_SetTimeout(pNID as dword, uTimeout as dword)
poke dword pNID + NID_UNION_TIMEOUT_VERSION, uTimeout
endfunction
// Only used when Shell_NotifyIcon is used to send a NIM_SETVERSION message
function NID_SetVersion(pNID as dword, uVersion as dword)
poke dword pNID + NID_UNION_TIMEOUT_VERSION, uVersion
endfunction
function NID_SetTitle(pNID as dword, title as string)
poke string pNID + NID_SZINFOTITLE, title, 63
endfunction
function NID_SetInfoFlags(pNID as dword, dwInfoFlags as dword)
poke dword pNID + NID_DWINFOFLAGS, dwInfoFlags
endfunction
// Only applicable starting with Windows 7; should be set to 0 for earlier versions
// Takes a pointer to a GUID structure; the data is copied and as such the provided pointer may be released
// after calling this function.
function NID_SetGUID(pNID as dword, pGUID as dword)
poke dword pNID + NID_GUIDITEM, peek dword(pGUID)
poke dword pNID + NID_GUIDITEM + 4, peek dword(pGUID + 4)
poke dword pNID + NID_GUIDITEM + 8, peek dword(pGUID + 8)
poke dword pNID + NID_GUIDITEM + 12, peek dword(pGUID + 12)
endfunction
// Only applicable starting from Windows Vista
function NID_SetBalloonIcon(pNID as dword, hBalloonIcon as dword)
poke dword pNID + NID_HBALLOONICON, hBalloonIcon
endfunction
// Creates a GUID memory structure and returns a pointer to it
function GUID_Create(dw as dword, w1 as word, w2 as word, b1 as byte, b2 as byte, b3 as byte, b4 as byte, b5 as byte, b6 as byte, b7 as byte, b8 as byte)
ptr = alloc(16)
poke dword ptr, dw
poke word ptr + 4, w1
poke word ptr + 6, w2
poke byte ptr + 8, b1
poke byte ptr + 9, b2
poke byte ptr + 10, b3
poke byte ptr + 11, b4
poke byte ptr + 12, b5
poke byte ptr + 13, b6
poke byte ptr + 14, b7
poke byte ptr + 15, b8
endfunction ptr
// Generates a GUID and returns a pointer to it.
function GUID_Generate()
pGUID = alloc zeroed(16)
hr = call dll(ole32, "CoCreateGuid", pGUID)
endfunction pGUID
// Deletes a GUID structure
function GUID_Destroy(pGUID as dword)
free pGUID
endfunction
"Why do programmers get Halloween and Christmas mixed up?" Because Oct(31) = Dec(25)