0 registered members (),
1,454
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
System Tray Icon
#221357
08/13/08 17:18
08/13/08 17:18
|
Joined: Aug 2008
Posts: 17
PiLX
OP
Newbie
|
OP
Newbie
Joined: Aug 2008
Posts: 17
|
System Tray Icon Example for Lite-C (pure) youll need to provide the icon. ive been using this in pure mode and it works well.. havent tested in legacy yet. anyway System_Tray.h could be either merged with the included header files(litec.h,windows.h, etc.) or seperate .. whatever, you decide System_Tray.h #define bool BOOL
#define IMAGE_ICON 1
#define LR_SHARED 0x00008000
#define LR_LOADFROMFILE 0x00000010
#define LR_VGACOLOR 0x00000080
typedef long HICON;
typedef char CHAR;
typedef struct _NOTIFYICONDATA{
DWORD cbSize;
HWND hWnd;
UINT uID;
UINT uFlags;
UINT uCallbackMessage;
HICON hIcon;
CHAR szTip[128];
}NOTIFYICONDATA;
typedef long PNOTIFYICONDATAA;
#define STDAPICALLTYPE __stdcall
#define SHSTDAPI_(type) EXT type STDAPICALLTYPE
SHSTDAPI_(BOOL) Shell_NotifyIcon(DWORD dwMessage, PNOTIFYICONDATAA lpData);
#define ShellAPI(name,lib) #define PRAGMA_API name;lib!name
ShellAPI(Shell_NotifyIcon,shell32)
System_Tray.c #include <acknex.h>
#include <windows.h>
#include "System_Tray.h"
NOTIFYICONDATA _nid;
HMENU hMenu, hSubMenu;
#define ID_MENU_EXIT 100
#define ID_MINIMIZE_TO_TRAY 101
#define ID_MENU_ITEM 102
#define ID_SUBMENU_ITEM 103
#define ID_RESTORE 104
bool minimized = false;
bool minimized_to_tray = false;
void _exit()
{
/* delete the tray icon.*/
Shell_NotifyIcon(NIM_DELETE, &_nid);
sys_exit(NULL);
}
HWND system_tray_menu()
{
hMenu = CreatePopupMenu();
hSubMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "Menu Item");
AppendMenu(hSubMenu, MF_STRING, ID_SUBMENU_ITEM, "Sub Menu Item");
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hMenu, MF_STRING, ID_RESTORE, "Restore");
AppendMenu(hMenu, MF_STRING, ID_MINIMIZE_TO_TRAY, "Minimize to tray");
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hMenu, MF_STRING, ID_MENU_EXIT, "Exit");
return 0;
}
long CallbackMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
{
switch(wParam)
{
case ID_RESTORE:
{
minimized_to_tray = false;
ShowWindow(hWnd, SW_RESTORE);
/* show the tray icon.*/
Shell_NotifyIcon(NIM_ADD, &_nid);
/* disable the "restore" menu item */
EnableMenuItem(hMenu,ID_RESTORE, MF_GRAYED);
/* enable the "minimize to tray" menu item */
EnableMenuItem(hMenu,ID_MINIMIZE_TO_TRAY, MF_ENABLED);
}
break;
case ID_MINIMIZE_TO_TRAY:
{
minimized_to_tray = true;
ShowWindow(hWnd, SW_HIDE);
/* show the tray icon.*/
Shell_NotifyIcon(NIM_ADD, &_nid);
/* disable the "minimize to tray" menu item */
EnableMenuItem(hMenu,ID_MINIMIZE_TO_TRAY, MF_GRAYED);
/* enable the "restore" menu item */
EnableMenuItem(hMenu,ID_RESTORE, MF_ENABLED);
}
break;
case ID_SUBMENU_ITEM:
{
MessageBox(hWnd, "System Tray Icon Example", "", MB_OK);
}
break;
case ID_MENU_EXIT:
{
_exit();
}
break;
}
}
break;
case WM_SIZE:
{
if(wParam == SIZE_MINIMIZED)
{
minimized = true;
}
}
break;
case WM_CLOSE:
{
minimized_to_tray = true;
ShowWindow(hWnd, SW_HIDE);
/* show the tray icon.*/
Shell_NotifyIcon(NIM_ADD, &_nid);
/* disable the "minimize to tray" menu item */
EnableMenuItem(hMenu,ID_MINIMIZE_TO_TRAY, MF_GRAYED);
/* enable the "restore" menu item */
EnableMenuItem(hMenu,ID_RESTORE, MF_ENABLED);
}
break;
}
if(message == _nid.uCallbackMessage)
{
switch(lParam)
{
/* (if minimized or minimize to tray) double clicking the icon shows the window */
case WM_LBUTTONDBLCLK:
{
if(minimized_to_tray)
{
minimized_to_tray = false;
ShowWindow(hWnd, SW_SHOW);
/* delete the tray icon.*/
Shell_NotifyIcon(NIM_DELETE, &_nid);
EnableMenuItem(hMenu,ID_RESTORE, MF_ENABLED);
}
if(minimized)
{
minimized = false;
ShowWindow(hWnd, SW_RESTORE);
}
}
break;
case WM_RBUTTONUP:
{
POINT cursor_position;
GetCursorPos(&cursor_position);
TrackPopupMenu(hMenu, 0, cursor_position.x, cursor_position.y, 0, hWnd, 0);
}
break;
}
}
return 0;
}
void disable_close()
{
return;
}
int main()
{
video_window(nullvector,nullvector,112,"System Tray Icon Example");
mouse_pointer = 2;
_nid.cbSize = sizeof(NOTIFYICONDATA);
_nid.hWnd = hWnd;
_nid.uID = WM_USER + 2;
_nid.uFlags = NIF_TIP | NIF_ICON | NIF_MESSAGE;
_nid.uCallbackMessage = WM_USER + 1;
_nid.hIcon = (HICON)LoadImage(GetModuleHandle(NULL),"icon.ico", IMAGE_ICON, 16, 16, LR_SHARED | LR_LOADFROMFILE | LR_VGACOLOR);
strcpy(_nid.szTip, "System Tray Icon Menu");
Shell_NotifyIcon(NIM_ADD, &_nid);
system_tray_menu();
/* disable the "restore" menu item */
EnableMenuItem(hMenu,ID_RESTORE, MF_GRAYED);
on_scanmessage = CallbackMessage;
while(1)
{
/* clicking the close icon will hide the application instead of closing it*/
on_close = disable_close;
if(key_esc){
_exit();
}
wait(1);
}
return 0;
}
|
|
|
Re: System Tray Icon (Lite-C)
[Re: PiLX]
#221754
08/16/08 03:05
08/16/08 03:05
|
Joined: Jan 2008
Posts: 1,580
Blade280891
Serious User
|
Serious User
Joined: Jan 2008
Posts: 1,580
|
nice cont , although not really for games more for apps i think . But keep up the work.
My Avatar Randomness V2"Someone get me to the doctor, and someone call the nurse And someone buy me roses, and someone burned the church"
|
|
|
Re: System Tray Icon (Lite-C)
[Re: Blade280891]
#245248
01/09/09 02:03
01/09/09 02:03
|
Joined: Jul 2004
Posts: 1,710
MMike
Serious User
|
Serious User
Joined: Jul 2004
Posts: 1,710
|
very thanks, i im doing application and this is really what i looking for.. btw , while on tray.. the engine keeps running right?
Last edited by MMike; 01/09/09 02:04.
|
|
|
Re: System Tray Icon (Lite-C)
[Re: Cowabanga]
#245305
01/09/09 10:42
01/09/09 10:42
|
Joined: Nov 2007
Posts: 1,032 Croatia
croman
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,032
Croatia
|
great contribution. someone will find use of it for sure. thnx
Ubi bene, ibi Patria.
|
|
|
|