tray latest
Cross-platform, super tiny C99 implementation of a system tray icon with a popup menu and notifications.
tray_windows.c File Reference

System tray implementation for Windows. More...

#include <Windows.h>
#include <shellapi.h>
#include "tray.h"
Include dependency graph for tray_windows.c:

Classes

struct  icon_info
 Icon information. More...
 

Macros

#define ID_TRAY_FIRST   1000
 First tray identifier.
 
#define WC_TRAY_CLASS_NAME   "TRAY"
 Tray window class name.
 
#define WM_TRAY_CALLBACK_MESSAGE   (WM_USER + 1)
 Tray callback message.
 

Enumerations

enum  IconType { REGULAR = 1 , LARGE , NOTIFICATION }
 Icon type. More...
 

Functions

struct icon_info _create_icon_info (const char *path)
 Create icon information.
 
void _destroy_icon_cache ()
 Destroy icon cache.
 
HICON _fetch_cached_icon (struct icon_info *icon_record, enum IconType icon_type)
 Fetch cached icon.
 
HICON _fetch_icon (const char *path, enum IconType icon_type)
 Fetch icon.
 
void _init_icon_cache (const char **paths, int count)
 Initialize icon cache.
 
void tray_exit (void)
 Terminate UI loop.
 
HWND tray_get_hwnd (void)
 Get the tray window handle.
 
int tray_init (struct tray *tray)
 Create tray icon.
 
int tray_loop (int blocking)
 Run one iteration of the UI loop.
 
void tray_show_menu (void)
 Force show the tray menu (for testing purposes).
 
void tray_update (struct tray *tray)
 Update the tray icon and menu.
 

Detailed Description

System tray implementation for Windows.

Enumeration Type Documentation

◆ IconType

enum IconType

Icon type.

Enumerator
REGULAR 

Regular icon.

LARGE 

Large icon.

NOTIFICATION 

Notification icon.

Function Documentation

◆ _create_icon_info()

struct icon_info _create_icon_info ( const char * path)

Create icon information.

Parameters
pathPath to the icon.
Returns
Icon information.

◆ _fetch_cached_icon()

HICON _fetch_cached_icon ( struct icon_info * icon_record,
enum IconType icon_type )

Fetch cached icon.

Parameters
icon_recordIcon record.
icon_typeIcon type.
Returns
Icon.

◆ _fetch_icon()

HICON _fetch_icon ( const char * path,
enum IconType icon_type )

Fetch icon.

Parameters
pathPath to the icon.
icon_typeIcon type.
Returns
Icon.

◆ _init_icon_cache()

void _init_icon_cache ( const char ** paths,
int count )

Initialize icon cache.

Parameters
pathsPaths to the icons.
countNumber of paths.

◆ tray_get_hwnd()

HWND tray_get_hwnd ( void )

Get the tray window handle.

Returns
The window handle.

◆ tray_init()

int tray_init ( struct tray * tray)

Create tray icon.

Parameters
trayThe tray to initialize.
Returns
0 on success, -1 on error.

◆ tray_loop()

int tray_loop ( int blocking)

Run one iteration of the UI loop.

Parameters
blockingWhether to block the call or not.
Returns
0 on success, -1 if tray_exit() was called.

◆ tray_update()

void tray_update ( struct tray * tray)

Update the tray icon and menu.

Parameters
trayThe tray to update.