Ignore:
Timestamp:
07/11/05 21:55:28 (8 years ago)
Author:
Michael Medin <michael@…>
Children:
237da21
Parents:
e93e741
Message:

changes all over manily in the checking code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/SysTray/TrayIcon.cpp

    r4f2e807 r24f7192  
    55#include <ShellAPI.h> 
    66 
     7void IconWidget_::threadProc(LPVOID lpParameter) 
     8{ 
     9  createDialog(); 
     10} 
     11 
     12 
     13void 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} 
     30void IconWidget_::exitThread(void) { 
     31  ::PostMessage(hDlgWnd, WM_MY_CLOSE, NULL, NULL); 
     32 
     33} 
     34 
    735namespace TrayIcon 
    836{ 
    9   HWND ghDlgWnd = NULL; 
    10   HANDLE ghMutex; 
    1137  std::string defaultCommand; 
    1238} 
     
    5177      POINT pt; 
    5278      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); 
    5581      DestroyMenu(hMenu); 
    5682      switch (cmd) { 
     
    6793      case ID_POPUP_SHOWLOG: 
    6894        { 
    69           long long err = reinterpret_cast<long long>(ShellExecute(ghDlgWnd, "open",  
     95          long long err = reinterpret_cast<long long>(ShellExecute(hwndDlg, "open",  
    7096            (NSCModuleHelper::getBasePath() + NSCModuleHelper::getSettingsString("log", "file", "")).c_str(),  
    7197            NULL, NULL, SW_SHOWNORMAL)); 
     
    96122} 
    97123 
    98 void TrayIcon::removeIcon(void) { 
     124void TrayIcon::removeIcon(HWND hWnd) { 
    99125  NOTIFYICONDATA ndata; 
    100   ndata.hWnd=ghDlgWnd; 
     126  ndata.cbSize=sizeof(NOTIFYICONDATA); 
     127  ndata.hWnd=hWnd; 
    101128  ndata.uID=2000; 
    102129  Shell_NotifyIcon(NIM_DELETE,&ndata); 
    103130} 
    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.