- Timestamp:
- 09/17/08 21:10:18 (5 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 08f0346
- Parents:
- 7e74e2c
- Location:
- helpers/systray_helper
- Files:
-
- 2 edited
-
TrayWidget.cpp (modified) (14 diffs)
-
TrayWidget.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
helpers/systray_helper/TrayWidget.cpp
ra34b229 r4bf9740 50 50 typedef BOOL (WINAPI *LPFN_CHANGEWINDOWMESSAGEFILTER) (UINT, DWORD); 51 51 LPFN_CHANGEWINDOWMESSAGEFILTER fnChangeWindowMessageFilter = NULL; 52 BOOL ChangeWindowMessageFilter (UINT message, DWORD what)52 BOOL ChangeWindowMessageFilter_(UINT message, DWORD what) 53 53 { 54 54 if (fnChangeWindowMessageFilter == NULL) { … … 85 85 LOG_MESSAGE_TRAY(_T("Attempting to launch system tray module for ") + channel_id_); 86 86 gTrayInstance = this; 87 try {88 shared_client_.reset(new nsclient_session::shared_client_session(channel_id_, this));89 if (shared_client_.get() != NULL)90 shared_client_->attach_to_session(channel_id_);91 } catch (nsclient_session::session_exception e) {92 LOG_ERROR_TRAY(_T("Failed to attach to shared session: ") + e.what());93 }94 87 } 95 88 TrayWidget::~TrayWidget() { … … 111 104 try { 112 105 shared_client_.reset(new nsclient_session::shared_client_session(channel_id_, this)); 113 if (shared_client_.get() != NULL) 106 if (shared_client_.get() != NULL) { 114 107 shared_client_->attach_to_session(channel_id_); 108 TrayIcon::addIcon(hDlgWnd); 109 } 115 110 } catch (nsclient_session::session_exception e) { 116 111 LOG_ERROR_TRAY(_T("Failed to attach to shared session: ") + e.what()); … … 124 119 return shared_client_->inject(command, arguments, splitter, escape, msg, perf); 125 120 } 121 std::pair<std::wstring,std::wstring> TrayWidget::get_client_name() { 122 if (shared_client_.get() == NULL) { 123 LOG_ERROR_TRAY(_T("No active shared instance!")); 124 return std::pair<std::wstring,std::wstring>(_T("NSClient++ system tray offline"), _T("")); 125 } 126 return shared_client_->get_client_name(); 127 } 126 128 127 129 … … 131 133 LOG_MESSAGE_TRAY(_T("Creating dialog...")); 132 134 ghInstance = hInstance; 133 //hDlgWnd = ::CreateDialog(hInstance,MAKEINTRESOURCE(IDD_NSTRAYDLG),NULL,TrayIcon::DialogProc);134 //if ((hDlgWnd == NULL)||!IsWindow(hDlgWnd)) {135 // LOG_ERROR_TRAY(_T("Failed to create windows: ") + error::lookup::last_error());136 // }137 135 138 136 WNDCLASSEX wndclass; … … 149 147 wndclass.lpszClassName=_T("NSClient_pp_TrayClass"); 150 148 wndclass.style=0; 151 // register task bar restore event after crash152 //WM_TASKBARCREATED=RegisterWindowMessage(TEXT("TaskbarCreated"));153 //MyChangeWindowMessageFilter(WM_TASKBARCREATED, MSGFLT_ADD);154 149 155 150 UINT UDM_TASKBARCREATED = RegisterWindowMessage(_T("TaskbarCreated")); … … 157 152 LOG_ERROR_TRAY(_T("Failed to register 'TaskbarCreated': ") + error::lookup::last_error()); 158 153 } 159 if (!ChangeWindowMessageFilter (UDM_TASKBARCREATED, MSGFLT_ADD)) {154 if (!ChangeWindowMessageFilter_(UDM_TASKBARCREATED, MSGFLT_ADD)) { 160 155 LOG_ERROR_TRAY(_T("Failed to cchange window filter: ") + error::lookup::last_error()); 161 156 } … … 185 180 } 186 181 return; 187 188 /*189 MSG Msg;190 BOOL bRet;191 while((bRet = ::GetMessage(&Msg, NULL, 0, 0)) != 0)192 {193 if (Msg.message == WM_MY_CLOSE) {194 ::DestroyWindow(hDlgWnd);195 } else if (Msg.message == UDM_TASKBARCREATED) {196 LOG_MESSAGE_TRAY(_T("Recreating systray icon..."));197 TrayIcon::addIcon(Msg.hwnd);198 } else if (bRet == -1) {199 // handle the error and possibly exit200 LOG_ERROR_TRAY(_T("Wonder what this is... please let me know..."));201 return;202 } else {203 //} else if (!::IsWindow(hDlgWnd) || !::IsDialogMessage(hDlgWnd, &Msg)) {204 ::TranslateMessage(&Msg);205 ::DispatchMessage(&Msg);206 }207 }208 */209 182 } 210 183 211 184 void TrayWidget::session_error(std::wstring file, unsigned int line, std::wstring msg) { 212 185 log(_T("error"), file.c_str(), line, msg); 186 } 187 void TrayWidget::session_info(std::wstring file, unsigned int line, std::wstring msg) { 188 log(_T("info"), file.c_str(), line, msg); 213 189 } 214 190 … … 353 329 SetDlgItemText(hWnd, IDC_MSG, msg.c_str()); 354 330 SetDlgItemText(hWnd, IDC_PERF, perf.c_str()); 331 } else if (cmd == _T("connect-service")) { 332 gTrayInstance->connectService(); 355 333 } 356 334 return 0; … … 364 342 } 365 343 344 static void connectService() { 345 Thread<worker_thread> *pThread = new Thread<worker_thread>(_T("tray-worker-thread")); 346 pThread->createThread(worker_thread::init(_T("connect-service"), NULL)); 347 } 366 348 static void updateServiceStatus(HMENU hMenu) { 367 349 Thread<worker_thread> *pThread = new Thread<worker_thread>(_T("tray-worker-thread")); … … 586 568 if (uMsg == UDM_TASKBARCREATED) { 587 569 addIcon(hwndDlg); 588 LOG_MESSAGE_TO_TRAY(_T("UDM_TASKBARCREATED"));589 570 } 590 571 … … 600 581 case WM_CREATE: 601 582 case WM_INITDIALOG: 602 LOG_MESSAGE_TO_TRAY(_T("WM_INITDIALOG"));603 604 605 583 UDM_TASKBARCREATED = RegisterWindowMessage(_T("TaskbarCreated")); 606 584 if (UDM_TASKBARCREATED == 0) { 607 585 LOG_MESSAGE_TO_TRAY(_T("Failed to register 'TaskbarCreated': ") + error::lookup::last_error()); 608 586 } 609 if (!ChangeWindowMessageFilter (UDM_TASKBARCREATED, MSGFLT_ADD)) {587 if (!ChangeWindowMessageFilter_(UDM_TASKBARCREATED, MSGFLT_ADD)) { 610 588 LOG_MESSAGE_TO_TRAY(_T("Failed to cchange window filter: ") + error::lookup::last_error()); 611 589 } 612 590 613 591 addIcon(hwndDlg); 592 worker_thread::connectService(); 614 593 break; 615 594 … … 619 598 { 620 599 case ID_POPUP_CONNECT: 621 gTrayInstance->connectService();600 worker_thread::connectService(); 622 601 break; 623 602 case ID_POPUP_CLOSE: … … 680 659 ndata.uCallbackMessage=WM_ICON_NOTIFY; 681 660 ndata.hIcon=::LoadIcon(ghInstance,MAKEINTRESOURCE(IDI_NSCP)); 682 std::wstring title = _T("NSClient++ SystemTray (TODO)"); //NSCModuleHelper::getApplicationName() + _T(" - ") + NSCModuleHelper::getApplicationVersionString(); 661 std::pair<std::wstring,std::wstring> version = gTrayInstance->get_client_name(); 662 std::wstring title = version.first + _T(" - ") + version.second; 683 663 wcsncpy_s(ndata.szTip, 64, title.c_str(), min(64, title.size())); 684 664 Shell_NotifyIcon(NIM_ADD,&ndata); -
helpers/systray_helper/TrayWidget.h
ra34b229 r4bf9740 60 60 void log(std::wstring category, const TCHAR* file, const int line, std::wstring message); 61 61 void session_error(std::wstring file, unsigned int line, std::wstring msg); 62 void session_info(std::wstring file, unsigned int line, std::wstring msg); 62 63 void session_log_message(int msgType, const TCHAR* file, const int line, std::wstring message); 63 64 int session_inject(std::wstring command, std::wstring arguments, TCHAR splitter, bool escape, std::wstring &msg, std::wstring & perf) { 64 65 return -1; 66 } 67 std::pair<std::wstring,std::wstring> session_get_name() { 68 return std::pair<std::wstring,std::wstring>(_T("NSClient++ systray"),_T("")); 65 69 } 66 70 … … 69 73 HWND getLogWindow() const { return hLogWnd; } 70 74 int inject(std::wstring command, std::wstring arguments, TCHAR splitter, bool escape, std::wstring &msg, std::wstring & perf); 75 std::pair<std::wstring,std::wstring> get_client_name(); 71 76 72 77
Note: See TracChangeset
for help on using the changeset viewer.








