Changeset 24f7192 in nscp for trunk/modules/SysTray/TrayIcon.cpp
- Timestamp:
- 07/11/05 21:55:28 (8 years ago)
- Children:
- 237da21
- Parents:
- e93e741
- File:
-
- 1 edited
-
trunk/modules/SysTray/TrayIcon.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/SysTray/TrayIcon.cpp
r4f2e807 r24f7192 5 5 #include <ShellAPI.h> 6 6 7 void IconWidget_::threadProc(LPVOID lpParameter) 8 { 9 createDialog(); 10 } 11 12 13 void IconWidget_::createDialog(void) { 14 hDlgWnd = ::CreateDialog(NSCModuleWrapper::getModule(),MAKEINTRESOURCE(IDD_NSTRAYDLG),NULL,TrayIcon::DialogProc); 15 16 MSG Msg; 17 while(::GetMessage(&Msg, hDlgWnd, 0, 0)) 18 { 19 if (Msg.message == WM_MY_CLOSE) 20 break; 21 if (!::IsWindow(hDlgWnd) || !::IsDialogMessage(hDlgWnd, &Msg)) { 22 ::TranslateMessage(&Msg); 23 ::DispatchMessage(&Msg); 24 } 25 } 26 TrayIcon::removeIcon(hDlgWnd); 27 28 ::DestroyWindow(hDlgWnd); 29 } 30 void IconWidget_::exitThread(void) { 31 ::PostMessage(hDlgWnd, WM_MY_CLOSE, NULL, NULL); 32 33 } 34 7 35 namespace TrayIcon 8 36 { 9 HWND ghDlgWnd = NULL;10 HANDLE ghMutex;11 37 std::string defaultCommand; 12 38 } … … 51 77 POINT pt; 52 78 GetCursorPos(&pt); 53 SetForegroundWindow( ghDlgWnd);54 int cmd = TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_RETURNCMD, pt.x, pt.y, 0, ghDlgWnd, &r);79 SetForegroundWindow(hwndDlg); 80 int cmd = TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, &r); 55 81 DestroyMenu(hMenu); 56 82 switch (cmd) { … … 67 93 case ID_POPUP_SHOWLOG: 68 94 { 69 long long err = reinterpret_cast<long long>(ShellExecute( ghDlgWnd, "open",95 long long err = reinterpret_cast<long long>(ShellExecute(hwndDlg, "open", 70 96 (NSCModuleHelper::getBasePath() + NSCModuleHelper::getSettingsString("log", "file", "")).c_str(), 71 97 NULL, NULL, SW_SHOWNORMAL)); … … 96 122 } 97 123 98 void TrayIcon::removeIcon( void) {124 void TrayIcon::removeIcon(HWND hWnd) { 99 125 NOTIFYICONDATA ndata; 100 ndata.hWnd=ghDlgWnd; 126 ndata.cbSize=sizeof(NOTIFYICONDATA); 127 ndata.hWnd=hWnd; 101 128 ndata.uID=2000; 102 129 Shell_NotifyIcon(NIM_DELETE,&ndata); 103 130 } 104 105 void TrayIcon::createDialog(void) {106 ghMutex = ::CreateMutex(NULL, TRUE, NULL);107 if (!ghMutex)108 throw std::string("Could not create mutex.");109 110 ghDlgWnd = ::CreateDialog(NSCModuleWrapper::getModule(),MAKEINTRESOURCE(IDD_NSTRAYDLG),NULL,DialogProc);111 112 MSG Msg;113 while(::GetMessage(&Msg, ghDlgWnd, 0, 0))114 {115 if (Msg.message == WM_MY_CLOSE)116 break;117 if (!::IsWindow(ghDlgWnd) || !::IsDialogMessage(ghDlgWnd, &Msg)) {118 ::TranslateMessage(&Msg);119 ::DispatchMessage(&Msg);120 }121 }122 removeIcon();123 124 ::DestroyWindow(ghDlgWnd);125 ::ReleaseMutex(ghMutex);126 }127 void TrayIcon::destroyDialog(void) {128 ::PostMessage(ghDlgWnd, WM_MY_CLOSE, NULL, NULL);129 }130 bool TrayIcon::waitForTermination(DWORD timeout /* = 5000L */) {131 DWORD dwWaitResult = WaitForSingleObject(ghMutex, timeout);132 switch (dwWaitResult) {133 // The thread got mutex ownership.134 case WAIT_OBJECT_0:135 ReleaseMutex(ghMutex);136 CloseHandle(ghMutex);137 return true;138 // Cannot get mutex ownership due to time-out.139 case WAIT_TIMEOUT:140 return false;141 142 // Got ownership of the abandoned mutex object.143 case WAIT_ABANDONED:144 return false;145 }146 return false;147 }
Note: See TracChangeset
for help on using the changeset viewer.








