Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,454 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
System Tray Icon #221357
08/13/08 17:18
08/13/08 17:18
Joined: Aug 2008
Posts: 17
P
PiLX Offline OP
Newbie
PiLX  Offline OP
Newbie
P

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

Code:
#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


Code:
#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] #221361
08/13/08 17:34
08/13/08 17:34
Joined: Apr 2004
Posts: 516
USA
Trooper119 Offline
User
Trooper119  Offline
User

Joined: Apr 2004
Posts: 516
USA
Well thanks for the contribution, but I think you've shot for the moon and hit mars. Hopefully someone can use this smile


A clever person solves a problem.
A wise person avoids it.
--Einstein

Currently Codeing: Free Lite-C
Re: System Tray Icon (Lite-C) [Re: Trooper119] #221375
08/13/08 18:09
08/13/08 18:09
Joined: Aug 2008
Posts: 17
P
PiLX Offline OP
Newbie
PiLX  Offline OP
Newbie
P

Joined: Aug 2008
Posts: 17
i know.... not much to it right now.. im going to add on to it. lets just call this part 1.

a context menu..and callback functions are in its future..

and possibly a working example when im done.

Re: System Tray Icon (Lite-C) [Re: PiLX] #221512
08/14/08 12:55
08/14/08 12:55
Joined: Aug 2008
Posts: 17
P
PiLX Offline OP
Newbie
PiLX  Offline OP
Newbie
P

Joined: Aug 2008
Posts: 17
updated.

just copy the code above and run it.

Re: System Tray Icon (Lite-C) [Re: PiLX] #221540
08/14/08 16:05
08/14/08 16:05
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
haven't tried it, but it's useful for sure, thanks smile i remember earlier i had to write a dll to achive this

Re: System Tray Icon (Lite-C) [Re: Shadow969] #221725
08/15/08 19:42
08/15/08 19:42
Joined: Aug 2008
Posts: 17
P
PiLX Offline OP
Newbie
PiLX  Offline OP
Newbie
P

Joined: Aug 2008
Posts: 17
well it could have been coded alot better. its a mess in my opinion, i hacked it up fairly quick. alot of it was experimental and i just left it that way.

i expect people would write their own anyway.

EDIT:

this would be a good one to put in the magazine.

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 Offline
Serious User
Blade280891  Offline
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 Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
very thanks, i im doing application and this is really what i looking for..

smile


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: MMike] #245302
01/09/09 10:34
01/09/09 10:34
Joined: Aug 2008
Posts: 2,838
take me down to the paradise c...
Cowabanga Offline
Expert
Cowabanga  Offline
Expert

Joined: Aug 2008
Posts: 2,838
take me down to the paradise c...
Thanks!

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 Offline
Serious User
croman  Offline
Serious User

Joined: Nov 2007
Posts: 1,032
Croatia
great contribution. someone will find use of it for sure.
thnx smile



Ubi bene, ibi Patria.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1