diff --git a/README.md b/README.md index 1ec6d23..9873b3b 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Works well on: * Windows XP or newer (shellapi.h) * MacOS (Cocoa/AppKit) -There is also a stub implementation that returns errors on attempt to create a tray menu. +The code is C++ friendly and will compile fine in C++98 and up. # Setup @@ -20,7 +20,7 @@ Before you can compile `tray`, you'll need to add an environment definition befo #include #include -#define TRAY_WINAPI 1 +#define TRAY_WINAPI #include "tray.h" ... @@ -31,7 +31,7 @@ Before you can compile `tray`, you'll need to add an environment definition befo #include #include -#define TRAY_APPINDICATOR 1 +#define TRAY_APPINDICATOR #include "tray.h" ... @@ -42,12 +42,14 @@ Before you can compile `tray`, you'll need to add an environment definition befo #include #include -#define TRAY_APPKIT 1 +#define TRAY_APPKIT #include "tray.h" ... ``` +Failure to define one of the three above will result in a compile-time error. + # Demo The included example `.c` files can be compiled based on your environment. @@ -67,12 +69,16 @@ $> a [Enter] # Example ```c +struct tray_menu menus[] = { + { "Toggle me", 0, 0, toggle_cb, NULL }, + { "-" , 0, 0, NULL , NULL }, + { "Quit" , 0, 0, quit_cb , NULL }, + { NULL , 0, 0, NULL , NULL } +}; + struct tray tray = { .icon = "icon.png", - .menu = (struct tray_menu[]){{"Toggle me", 0, 0, toggle_cb, NULL}, - {"-", 0, 0, NULL, NULL}, - {"Quit", 0, 0, quit_cb, NULL}, - {NULL, 0, 0, NULL, NULL}}, + .menu = menus, }; void toggle_cb(struct tray_menu *item) { diff --git a/tray.h b/tray.h index 4ba47ea..ee9ce07 100644 --- a/tray.h +++ b/tray.h @@ -4,12 +4,12 @@ struct tray_menu; struct tray { - char *icon; + const char *icon; struct tray_menu *menu; }; struct tray_menu { - char *text; + const char *text; int disabled; int checked; @@ -279,7 +279,7 @@ static HMENU _tray_menu(struct tray_menu *m, UINT *id) { item.fState |= MFS_CHECKED; } item.wID = *id; - item.dwTypeData = m->text; + item.dwTypeData = (LPSTR)m->text; item.dwItemData = (ULONG_PTR)m; InsertMenuItem(hmenu, *id, TRUE, &item); @@ -361,10 +361,7 @@ static void tray_exit() { UnregisterClass(WC_TRAY_CLASS_NAME, GetModuleHandle(NULL)); } #else -static int tray_init(struct tray *tray) { return -1; } -static int tray_loop(int blocking) { return -1; } -static void tray_update(struct tray *tray) {} -static void tray_exit(); +#error Please define TRAY_WINAPI, TRAY_APPINDICATOR or TRAY_APPKIT before including this file. #endif #endif /* TRAY_H */