- Timestamp:
- 09/09/08 10:11:36 (5 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 7221dc8
- Parents:
- dc59b0e
- Location:
- helpers/systray_helper
- Files:
-
- 1 added
- 1 deleted
- 2 edited
-
ReadMe.txt (deleted)
-
TrayWidget.cpp (modified) (10 diffs)
-
TrayWidget.h (modified) (1 diff)
-
res/standby.ico (added)
Legend:
- Unmodified
- Added
- Removed
-
helpers/systray_helper/TrayWidget.cpp
rbc97cd8 ra34b229 33 33 34 34 logging::file_logger g_log_instance(_T("nsclient++"),_T("systray.log")); 35 HINSTANCE ghInstance = NULL; 36 TrayWidget *gTrayInstance = NULL; 35 37 36 38 #define LOG_ERROR_FILE(x) g_log_instance.log(_T("error"), __FILEW__, __LINE__, std::wstring(x).c_str()); … … 41 43 42 44 #define LOG_ERROR_TO_TRAY(x) gTrayInstance->log(_T("error"), __FILEW__, __LINE__, std::wstring(x).c_str()); 45 #define LOG_MESSAGE_TO_TRAY(x) gTrayInstance->log(_T("message"), __FILEW__, __LINE__, std::wstring(x).c_str()); 43 46 44 47 #if WINVER < 0x0600 … … 52 55 HMODULE hMod = GetModuleHandle(TEXT("user32")); 53 56 if (hMod == NULL) 54 return false;57 return FALSE; 55 58 fnChangeWindowMessageFilter = (LPFN_CHANGEWINDOWMESSAGEFILTER)GetProcAddress(hMod,"ChangeWindowMessageFilter"); 56 59 } 57 60 if (fnChangeWindowMessageFilter == NULL) { 58 return true; 59 } 61 LOG_ERROR_FILE(_T("Could not find ChangeWindowMessageFilter: ") + error::lookup::last_error()); 62 return TRUE; 63 } 64 LOG_ERROR_FILE(_T("registred windows thingy...")); 60 65 return fnChangeWindowMessageFilter(message,what); 61 66 } … … 72 77 return _T(""); 73 78 } 74 HINSTANCE ghInstance = NULL;75 TrayWidget *gTrayInstance = NULL;76 79 TrayWidget::TrayWidget(std::wstring cmdLine) { 77 80 strEx::splitList list = strEx::splitEx(cmdLine, _T(" ")); … … 124 127 125 128 129 126 130 void TrayWidget::createDialog(HINSTANCE hInstance) { 131 LOG_MESSAGE_TRAY(_T("Creating dialog...")); 127 132 ghInstance = hInstance; 128 hDlgWnd = ::CreateDialog(hInstance,MAKEINTRESOURCE(IDD_NSTRAYDLG),NULL,TrayIcon::DialogProc); 129 if ((hDlgWnd == NULL)||!IsWindow(hDlgWnd)) { 130 LOG_ERROR_TRAY(_T("Failed to create windows: ") + error::lookup::last_error()); 131 } 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 138 WNDCLASSEX wndclass; 139 wndclass.lpszMenuName=NULL; 140 wndclass.cbSize=sizeof(wndclass); 141 wndclass.lpfnWndProc=TrayIcon::DialogProc; 142 wndclass.cbClsExtra=0; 143 wndclass.cbWndExtra=0; 144 wndclass.hInstance=hInstance; 145 wndclass.hIcon=NULL; 146 wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); 147 wndclass.hCursor=LoadCursor(NULL,IDC_ARROW); 148 wndclass.hIconSm=NULL; 149 wndclass.lpszClassName=_T("NSClient_pp_TrayClass"); 150 wndclass.style=0; 151 // register task bar restore event after crash 152 //WM_TASKBARCREATED=RegisterWindowMessage(TEXT("TaskbarCreated")); 153 //MyChangeWindowMessageFilter(WM_TASKBARCREATED, MSGFLT_ADD); 132 154 133 155 UINT UDM_TASKBARCREATED = RegisterWindowMessage(_T("TaskbarCreated")); … … 139 161 } 140 162 163 if (!RegisterClassEx(&wndclass)) { 164 LOG_ERROR_TRAY(_T("Failed to register window class: ") + error::lookup::last_error()); 165 } 166 167 MSG msg; 168 hDlgWnd=CreateWindow(_T("NSClient_pp_TrayClass"),NULL,0,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL); 169 if(hDlgWnd==NULL) 170 { 171 LOG_ERROR_TRAY(_T("Failed to create window: ") + error::lookup::last_error()); 172 return; 173 } 174 while(GetMessage(&msg,NULL,0,0)) 175 { 176 if (msg.message == WM_MY_CLOSE) { 177 ::DestroyWindow(hDlgWnd); 178 } else if (msg.message == UDM_TASKBARCREATED) { 179 LOG_MESSAGE_TRAY(_T("Recreating systray icon...")); 180 TrayIcon::addIcon(msg.hwnd); 181 } else { 182 TranslateMessage(&msg); 183 DispatchMessage(&msg); 184 } 185 } 186 return; 187 188 /* 141 189 MSG Msg; 142 190 BOOL bRet; … … 158 206 } 159 207 } 208 */ 160 209 } 161 210 … … 529 578 namespace TrayIcon 530 579 { 580 UINT UDM_TASKBARCREATED = -1; 531 581 HMENU hPopupMenu_ = NULL; 532 582 } 533 INT_PTR CALLBACK TrayIcon::DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) 583 //LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 584 LRESULT CALLBACK TrayIcon::DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) 534 585 { 586 if (uMsg == UDM_TASKBARCREATED) { 587 addIcon(hwndDlg); 588 LOG_MESSAGE_TO_TRAY(_T("UDM_TASKBARCREATED")); 589 } 590 535 591 switch (uMsg) 536 592 { … … 542 598 return 0; 543 599 600 case WM_CREATE: 544 601 case WM_INITDIALOG: 602 LOG_MESSAGE_TO_TRAY(_T("WM_INITDIALOG")); 603 604 605 UDM_TASKBARCREATED = RegisterWindowMessage(_T("TaskbarCreated")); 606 if (UDM_TASKBARCREATED == 0) { 607 LOG_MESSAGE_TO_TRAY(_T("Failed to register 'TaskbarCreated': ") + error::lookup::last_error()); 608 } 609 if (!ChangeWindowMessageFilter(UDM_TASKBARCREATED, MSGFLT_ADD)) { 610 LOG_MESSAGE_TO_TRAY(_T("Failed to cchange window filter: ") + error::lookup::last_error()); 611 } 612 545 613 addIcon(hwndDlg); 546 614 break; … … 601 669 break; 602 670 } 603 return FALSE; 671 return DefWindowProc(hwndDlg,uMsg,wParam,lParam); 672 //return FALSE; 604 673 } 605 674 void TrayIcon::addIcon(HWND hWnd) { -
helpers/systray_helper/TrayWidget.h
rbc97cd8 ra34b229 75 75 namespace TrayIcon 76 76 { 77 INT_PTRCALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);77 LRESULT CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam); 78 78 INT_PTR CALLBACK InjectDialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam); 79 79 INT_PTR CALLBACK LogDialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
Note: See TracChangeset
for help on using the changeset viewer.








