Applied Felix's tray icon patch.
authorThomas Lopatic <thomas@lopatic.de>
Mon, 17 Jan 2005 11:52:36 +0000 (11:52 +0000)
committerThomas Lopatic <thomas@lopatic.de>
Mon, 17 Jan 2005 11:52:36 +0000 (11:52 +0000)
13 files changed:
gui/win32/Frontend.ncb
gui/win32/Frontend.opt
gui/win32/Main/Frontend.cpp
gui/win32/Main/Frontend.dsp
gui/win32/Main/Frontend.h
gui/win32/Main/Frontend.rc
gui/win32/Main/FrontendDlg.cpp
gui/win32/Main/FrontendDlg.h
gui/win32/Main/TrayIcon.cpp [new file with mode: 0755]
gui/win32/Main/TrayIcon.h [new file with mode: 0755]
gui/win32/Main/res/Tray1.ico [new file with mode: 0644]
gui/win32/Main/res/Tray2.ico [new file with mode: 0644]
gui/win32/Main/resource.h

index bd47218..90aa940 100644 (file)
Binary files a/gui/win32/Frontend.ncb and b/gui/win32/Frontend.ncb differ
index 5176ff2..3834301 100644 (file)
Binary files a/gui/win32/Frontend.opt and b/gui/win32/Frontend.opt differ
index 29eacb7..dbecb58 100644 (file)
  * to the project. For more information see the website or contact\r
  * the copyright holders.\r
  *\r
- * $Id: Frontend.cpp,v 1.6 2004/11/21 17:10:27 tlopatic Exp $\r
+ * $Id: Frontend.cpp,v 1.7 2005/01/17 11:52:35 tlopatic Exp $\r
  */\r
 \r
 #include "stdafx.h"\r
 #include "Frontend.h"\r
 #include "FrontendDlg.h"\r
+#include "TrayIcon.h"\r
 \r
 #ifdef _DEBUG\r
 #define new DEBUG_NEW\r
@@ -106,6 +107,8 @@ BOOL CFrontendApp::InitInstance()
 \r
        CFrontendDlg dlg;\r
 \r
+       tray_icon = new TrayIcon( dlg, AfxGetInstanceHandle() );\r
+\r
        dlg.ConfigFile = CmdLineInfo.m_strFileName;\r
 \r
        m_pMainWnd = &dlg;\r
index 9766774..89f04f7 100644 (file)
@@ -147,6 +147,10 @@ SOURCE=.\NodeEntry.cpp
 SOURCE=.\StdAfx.cpp\r
 # ADD CPP /Yc"stdafx.h"\r
 # End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\TrayIcon.cpp\r
+# End Source File\r
 # End Group\r
 # Begin Group "Header Files"\r
 \r
@@ -211,6 +215,10 @@ SOURCE=.\Resource.h
 \r
 SOURCE=.\StdAfx.h\r
 # End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\TrayIcon.h\r
+# End Source File\r
 # End Group\r
 # Begin Group "Resource Files"\r
 \r
index a67f751..37b5426 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact\r
  * the copyright holders.\r
  *\r
- * $Id: Frontend.h,v 1.4 2004/11/21 17:10:27 tlopatic Exp $\r
+ * $Id: Frontend.h,v 1.5 2005/01/17 11:52:36 tlopatic Exp $\r
  */\r
 \r
 #if !defined(AFX_FRONTEND_H__8033A41F_6FDC_4054_A582_AB7B6AC5EEAE__INCLUDED_)\r
@@ -52,6 +52,8 @@
 \r
 #include "resource.h"\r
 \r
+class TrayIcon;\r
+\r
 class CFrontendApp : public CWinApp\r
 {\r
 public:\r
@@ -61,6 +63,7 @@ public:
        unsigned int RedirectThreadFunc(void);\r
 \r
        HANDLE OutRead;\r
+       TrayIcon* tray_icon;\r
 \r
        //{{AFX_VIRTUAL(CFrontendApp)\r
        public:\r
index 4e19767..37dc3a3 100644 (file)
@@ -1,4 +1,4 @@
-//Microsoft Developer Studio generated resource script.\r
+// Microsoft Visual C++ generated resource script.\r
 //\r
 #include "resource.h"\r
 \r
@@ -13,7 +13,7 @@
 #undef APSTUDIO_READONLY_SYMBOLS\r
 \r
 /////////////////////////////////////////////////////////////////////////////\r
-// English (U.S.) resources\r
+// Englisch (USA) resources\r
 \r
 #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r
 #ifdef _WIN32\r
@@ -27,18 +27,18 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
 // TEXTINCLUDE\r
 //\r
 \r
-1 TEXTINCLUDE DISCARDABLE \r
+1 TEXTINCLUDE \r
 BEGIN\r
     "resource.h\0"\r
 END\r
 \r
-2 TEXTINCLUDE DISCARDABLE \r
+2 TEXTINCLUDE \r
 BEGIN\r
     "#include ""afxres.h""\r\n"\r
     "\0"\r
 END\r
 \r
-3 TEXTINCLUDE DISCARDABLE \r
+3 TEXTINCLUDE \r
 BEGIN\r
     "#define _AFX_NO_SPLITTER_RESOURCES\r\n"\r
     "#define _AFX_NO_OLE_RESOURCES\r\n"\r
@@ -65,11 +65,11 @@ END
 //\r
 \r
 IDD_FRONTEND_DIALOG DIALOGEX 0, 0, 399, 289\r
-STYLE DS_MODALFRAME | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | \r
-    WS_SYSMENU\r
+STYLE DS_SETFONT | DS_MODALFRAME | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | \r
+    WS_CAPTION | WS_SYSMENU\r
 EXSTYLE WS_EX_APPWINDOW\r
 CAPTION "olsr.org Switch 0.4.8"\r
-FONT 8, "MS Sans Serif"\r
+FONT 8, "MS Sans Serif", 0, 0, 0x1\r
 BEGIN\r
     CONTROL         "Tab1",IDC_TAB1,"SysTabControl32",0x0,7,7,383,256\r
     PUSHBUTTON      "Start",IDC_BUTTON1,228,268,50,14\r
@@ -77,8 +77,8 @@ BEGIN
     PUSHBUTTON      "Exit",IDC_BUTTON3,340,268,50,14\r
 END\r
 \r
-IDD_DIALOG1 DIALOG DISCARDABLE  0, 0, 377, 240\r
-STYLE WS_CHILD | WS_VISIBLE\r
+IDD_DIALOG1 DIALOG  0, 0, 377, 240\r
+STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE\r
 FONT 8, "MS Sans Serif"\r
 BEGIN\r
     EDITTEXT        IDC_EDIT1,7,25,363,208,ES_MULTILINE | ES_READONLY | \r
@@ -89,8 +89,8 @@ BEGIN
     PUSHBUTTON      "Clear",IDC_BUTTON1,320,7,50,14\r
 END\r
 \r
-IDD_DIALOG2 DIALOG DISCARDABLE  0, 0, 377, 240\r
-STYLE WS_CHILD | WS_VISIBLE\r
+IDD_DIALOG2 DIALOG  0, 0, 377, 240\r
+STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE\r
 FONT 8, "MS Sans Serif"\r
 BEGIN\r
     CONTROL         "List1",IDC_LIST1,"SysListView32",LVS_LIST | WS_BORDER | \r
@@ -153,8 +153,8 @@ BEGIN
     RTEXT           "Window size:",IDC_STATIC,251,171,43,8\r
 END\r
 \r
-IDD_DIALOG3 DIALOG DISCARDABLE  0, 0, 377, 240\r
-STYLE WS_CHILD | WS_VISIBLE\r
+IDD_DIALOG3 DIALOG  0, 0, 377, 240\r
+STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE\r
 FONT 8, "MS Sans Serif"\r
 BEGIN\r
     CONTROL         "List1",IDC_LIST1,"SysListView32",LVS_REPORT | \r
@@ -169,8 +169,8 @@ BEGIN
     LTEXT           "Node information",IDC_STATIC,257,7,59,8\r
 END\r
 \r
-IDD_DIALOG4 DIALOG DISCARDABLE  0, 0, 377, 240\r
-STYLE WS_CHILD | WS_VISIBLE\r
+IDD_DIALOG4 DIALOG  0, 0, 377, 240\r
+STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE\r
 FONT 8, "MS Sans Serif"\r
 BEGIN\r
     CONTROL         "List1",IDC_LIST1,"SysListView32",LVS_REPORT | WS_BORDER | \r
@@ -185,7 +185,7 @@ END
 //\r
 \r
 #ifdef APSTUDIO_INVOKED\r
-GUIDELINES DESIGNINFO DISCARDABLE \r
+GUIDELINES DESIGNINFO \r
 BEGIN\r
     IDD_FRONTEND_DIALOG, DIALOG\r
     BEGIN\r
@@ -237,15 +237,17 @@ END
 \r
 // Icon with lowest ID value placed first to ensure application icon\r
 // remains consistent on all systems.\r
-IDI_ICON1               ICON    DISCARDABLE     "res\\Frontend.ico"\r
+IDI_ICON1               ICON                    "res\\Frontend.ico"\r
+IDI_ICON3               ICON                    "res\\Tray2.ico"\r
+IDI_ICON2               ICON                    "res\\Tray1.ico"\r
 \r
 /////////////////////////////////////////////////////////////////////////////\r
 //\r
-// 24\r
+// RT_MANIFEST\r
 //\r
 \r
-IDR_241                 24      DISCARDABLE     "Switch.exe.manifest"\r
-#endif    // English (U.S.) resources\r
+IDR_241                 RT_MANIFEST             "Switch.exe.manifest"\r
+#endif    // Englisch (USA) resources\r
 /////////////////////////////////////////////////////////////////////////////\r
 \r
 \r
index ca16466..cf91f78 100644 (file)
  * to the project. For more information see the website or contact\r
  * the copyright holders.\r
  *\r
- * $Id: FrontendDlg.cpp,v 1.8 2004/11/21 01:21:10 tlopatic Exp $\r
+ * $Id: FrontendDlg.cpp,v 1.9 2005/01/17 11:52:36 tlopatic Exp $\r
  */\r
 \r
 #include "stdafx.h"\r
 #include "Frontend.h"\r
 #include "FrontendDlg.h"\r
+#include "TrayIcon.h"\r
 \r
 #include "Ipc.h"\r
 \r
@@ -190,6 +191,11 @@ Restart3:
                NodeList.GetNext(Pos);\r
        }\r
 \r
+       if( NodeList.IsEmpty() )\r
+               TrayIcon::getInstance()->setStatus( TrayIcon::ON, "No nodes found" );\r
+       else\r
+               TrayIcon::getInstance()->setStatus( TrayIcon::CONNECTED, "Nodes available" );\r
+\r
        m_TabCtrl.m_Dialog3.UpdateNodeInfo(NodeList);\r
 }\r
 \r
@@ -874,6 +880,8 @@ int CFrontendDlg::StartOlsrd()
 \r
 int CFrontendDlg::StopOlsrd()\r
 {\r
+       TrayIcon::getInstance()->setStatus( TrayIcon::OFF, "Off" );\r
+\r
        ::SetEvent(Event);\r
 \r
        ::WaitForSingleObject((HANDLE)LogThread, INFINITE);\r
@@ -976,6 +984,8 @@ void CFrontendDlg::OnStopButton()
 \r
 void CFrontendDlg::OnExitButton()\r
 {\r
+       delete TrayIcon::getInstance();\r
+\r
        if (StopOlsrd() < 0)\r
                return;\r
 \r
index d13fcc6..17d37a2 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact\r
  * the copyright holders.\r
  *\r
- * $Id: FrontendDlg.h,v 1.5 2004/11/21 01:21:10 tlopatic Exp $\r
+ * $Id: FrontendDlg.h,v 1.6 2005/01/17 11:52:36 tlopatic Exp $\r
  */\r
 \r
 #if !defined(AFX_FRONTENDDLG_H__7D68FBC0_7448_479B_81F0_3FBBDE291395__INCLUDED_)\r
@@ -68,13 +68,13 @@ public:
        unsigned int NetThreadFunc(void);\r
 \r
        CString ConfigFile;\r
+protected:\r
 \r
        //{{AFX_VIRTUAL(CFrontendDlg)\r
-       protected:\r
        virtual void DoDataExchange(CDataExchange* pDX);\r
        //}}AFX_VIRTUAL\r
 \r
-protected:\r
+public:\r
        //{{AFX_MSG(CFrontendDlg)\r
        virtual BOOL OnInitDialog();\r
        afx_msg void OnOK();\r
@@ -84,8 +84,12 @@ protected:
        afx_msg void OnExitButton();\r
        //}}AFX_MSG\r
 \r
+protected:\r
        DECLARE_MESSAGE_MAP()\r
 \r
+       int StartOlsrd(void);\r
+       int StopOlsrd(void);\r
+\r
        int GetInterfaces(void);\r
 \r
        HANDLE Event;\r
@@ -94,9 +98,6 @@ protected:
 \r
        SOCKET SockHand;\r
 \r
-       int StartOlsrd(void);\r
-       int StopOlsrd(void);\r
-\r
        int PipeMode;\r
        int ExecutePipe(const char *, HANDLE *, HANDLE *, HANDLE *);\r
 \r
diff --git a/gui/win32/Main/TrayIcon.cpp b/gui/win32/Main/TrayIcon.cpp
new file mode 100755 (executable)
index 0000000..149a808
--- /dev/null
@@ -0,0 +1,185 @@
+#include "stdafx.h"\r
+#include "TrayIcon.h"\r
+\r
+#include <windows.h>\r
+#include <shellapi.h>\r
+\r
+#include "Frontend.h"\r
+#include "FrontendDlg.h"\r
+#include "Resource.h"\r
+\r
+#define TRAYICONID 987435\r
+\r
+HWND s_hWnd;\r
+TrayIcon* TrayIcon::instance = NULL;\r
+\r
+LRESULT CALLBACK TrayIconProc( HWND, UINT, WPARAM, LPARAM lParam )\r
+{\r
+       switch (lParam)\r
+       {\r
+               case WM_LBUTTONDOWN:\r
+               case WM_RBUTTONDOWN:\r
+                       TrayIcon::instance->displayPopup();\r
+                       break;\r
+       }\r
+\r
+       return 1;\r
+}\r
+\r
+void TrayIcon::displayPopup()\r
+{\r
+       HMENU hMenu = CreatePopupMenu();\r
+\r
+       MENUITEMINFO item;\r
+       memset(&item, 0, sizeof(MENUITEMINFO));\r
+       item.cbSize = sizeof(MENUITEMINFO);\r
+       item.fMask = MIIM_TYPE | MIIM_ID;\r
+       item.fType = MFT_STRING;\r
+\r
+       item.wID = 1;\r
+       item.dwTypeData = "&Start";\r
+       InsertMenuItem(hMenu, 1, TRUE, &item);\r
+\r
+       item.wID = 2;\r
+       item.dwTypeData = "&Stop";\r
+       InsertMenuItem(hMenu, 2, TRUE, &item);\r
+\r
+       item.wID = 3;\r
+       item.dwTypeData = "&Configure";\r
+       InsertMenuItem(hMenu, 3, TRUE, &item);\r
+\r
+       item.wID = 4;\r
+       item.dwTypeData = "&Exit";\r
+       InsertMenuItem(hMenu, 4, TRUE, &item);\r
+\r
+       POINT pt;\r
+\r
+       GetCursorPos(&pt);\r
+\r
+       SetForegroundWindow( s_hWnd );\r
+\r
+       int cmd = TrackPopupMenu(hMenu, \r
+                       TPM_RIGHTBUTTON | TPM_RETURNCMD, \r
+                       pt.x, \r
+                       pt.y, \r
+                       0, \r
+                       s_hWnd, \r
+                       NULL);\r
+\r
+   PostMessage(s_hWnd, WM_NULL, 0, 0); \r
+\r
+       switch(cmd)\r
+       {\r
+               case 4:\r
+                       PostQuitMessage(0);\r
+                       break;\r
+       \r
+               case 3:\r
+                       main_dlg.OpenIcon();\r
+                       break;\r
+\r
+               case 2:\r
+                       main_dlg.OnStopButton();\r
+                       break;\r
+\r
+               case 1:\r
+                       main_dlg.OnStartButton();\r
+                       break;\r
+       }\r
+\r
+       DestroyMenu(hMenu);\r
+}\r
+\r
+void TrayIcon::setStatus( status con_stat, const char* message )\r
+{\r
+       switch( con_stat )\r
+       {\r
+               case CONNECTED:\r
+                       setTrayAppearance( false, IDI_ICON2, message );\r
+                       break;\r
+\r
+               case OFF:\r
+                       setTrayAppearance( false, IDI_ICON3, message );\r
+                       break;\r
+\r
+               case ON:\r
+                       setTrayAppearance( false, IDI_ICON1, message );\r
+                       break;\r
+       }\r
+}\r
+\r
+void TrayIcon::setTrayAppearance( bool start, unsigned int res_id, const char* message )\r
+{\r
+       NOTIFYICONDATA notifyIconData;\r
+\r
+       notifyIconData.cbSize = sizeof(notifyIconData);\r
+       notifyIconData.hWnd = s_hWnd;\r
+\r
+       notifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;\r
+       notifyIconData.uCallbackMessage = 123456;\r
+       notifyIconData.uID = TRAYICONID; \r
+       notifyIconData.hIcon = (HICON)LoadIcon( hInst, MAKEINTRESOURCE( res_id ) );  \r
+       strcpy( notifyIconData.szTip, message ); \r
+\r
+       if( start )\r
+               Shell_NotifyIcon( NIM_ADD, &notifyIconData );\r
+       else\r
+               Shell_NotifyIcon( NIM_MODIFY, &notifyIconData );\r
+}\r
+\r
+TrayIcon::TrayIcon( CFrontendDlg& dlg, HINSTANCE hInst ) : main_dlg( dlg ), hInst( hInst )\r
+{\r
+       instance = this;\r
+       WNDCLASS wndClass;\r
+\r
+       wndClass.style = 0; \r
+       wndClass.lpfnWndProc = TrayIconProc;\r
+       wndClass.cbClsExtra = 0;\r
+       wndClass.cbWndExtra = 0;\r
+       wndClass.hInstance = hInst;\r
+       wndClass.hIcon = NULL;\r
+       wndClass.hCursor = NULL;\r
+       wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);\r
+       wndClass.lpszMenuName = NULL;\r
+       wndClass.lpszClassName = "OLSRdTrayIcon";\r
+\r
+   if (0 != RegisterClass(&wndClass))\r
+   {\r
+      s_hWnd = CreateWindow( \r
+                "OLSRdTrayIcon", \r
+         "Invisible Message Window", \r
+         WS_OVERLAPPEDWINDOW,\r
+         CW_USEDEFAULT,\r
+         CW_USEDEFAULT,\r
+         CW_USEDEFAULT,\r
+         CW_USEDEFAULT,\r
+         NULL,\r
+         NULL,\r
+         hInst,\r
+         NULL);\r
+\r
+      if (s_hWnd)\r
+      {\r
+         ShowWindow(s_hWnd, SW_HIDE);\r
+         \r
+         UpdateWindow(s_hWnd);\r
+      }\r
+   }\r
+\r
+   setTrayAppearance( true, IDI_ICON3, "Starting..." );\r
+}\r
+\r
+TrayIcon::~TrayIcon()\r
+{\r
+       NOTIFYICONDATA notifyIconData;\r
+\r
+       notifyIconData.cbSize = sizeof(notifyIconData);\r
+       notifyIconData.hWnd = s_hWnd;\r
+\r
+       notifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;\r
+       notifyIconData.uCallbackMessage = 123456;\r
+       notifyIconData.uID = TRAYICONID; \r
+       notifyIconData.hIcon = NULL;\r
+\r
+       Shell_NotifyIcon( NIM_DELETE, &notifyIconData );\r
+}\r
diff --git a/gui/win32/Main/TrayIcon.h b/gui/win32/Main/TrayIcon.h
new file mode 100755 (executable)
index 0000000..c69813c
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef TRAYICON_H_171149531\r
+#define TRAYICON_H_171149531\r
+\r
+class CFrontendDlg;\r
+\r
+class TrayIcon\r
+{\r
+public:\r
+       TrayIcon( CFrontendDlg&, HINSTANCE );\r
+       ~TrayIcon();\r
+\r
+       void displayPopup();    \r
+\r
+       static TrayIcon* getInstance()  { return instance; }\r
+\r
+       enum status { CONNECTED, ON, OFF };\r
+\r
+       void setStatus( status con_status, const char* message );\r
+\r
+private:\r
+       void setTrayAppearance( bool, unsigned int, const char* message );\r
+\r
+       HINSTANCE hInst;\r
+\r
+       CFrontendDlg& main_dlg;\r
+\r
+       friend LRESULT CALLBACK TrayIconProc( HWND, UINT, WPARAM, LPARAM );\r
+       static TrayIcon* instance;\r
+};\r
+\r
+#endif // TRAYICON_H_171149531\r
diff --git a/gui/win32/Main/res/Tray1.ico b/gui/win32/Main/res/Tray1.ico
new file mode 100644 (file)
index 0000000..79b4101
Binary files /dev/null and b/gui/win32/Main/res/Tray1.ico differ
diff --git a/gui/win32/Main/res/Tray2.ico b/gui/win32/Main/res/Tray2.ico
new file mode 100644 (file)
index 0000000..f53a74a
Binary files /dev/null and b/gui/win32/Main/res/Tray2.ico differ
index 9c0e68a..0ef9b2b 100644 (file)
@@ -1,5 +1,5 @@
 //{{NO_DEPENDENCIES}}\r
-// Microsoft Developer Studio generated include file.\r
+// Microsoft Visual C++ generated include file.\r
 // Used by Frontend.rc\r
 //\r
 #define IDD_FRONTEND_DIALOG             102\r
@@ -11,6 +11,8 @@
 #define IDD_DIALOG4                     132\r
 #define IDI_ICON1                       132\r
 #define IDR_241                         138\r
+#define IDI_ICON3                       141\r
+#define IDI_ICON2                       142\r
 #define IDC_TAB1                        1000\r
 #define IDC_BUTTON1                     1001\r
 #define IDC_EDIT1                       1003\r
@@ -48,7 +50,7 @@
 // \r
 #ifdef APSTUDIO_INVOKED\r
 #ifndef APSTUDIO_READONLY_SYMBOLS\r
-#define _APS_NEXT_RESOURCE_VALUE        140\r
+#define _APS_NEXT_RESOURCE_VALUE        141\r
 #define _APS_NEXT_COMMAND_VALUE         32771\r
 #define _APS_NEXT_CONTROL_VALUE         1030\r
 #define _APS_NEXT_SYMED_VALUE           101\r