Changeset a34b229 in nscp for helpers


Ignore:
Timestamp:
09/09/08 10:11:36 (5 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
7221dc8
Parents:
dc59b0e
Message:

2008-09-09 MickeM

  • Fixed issue with & and some commands via check_nt.
  • Fixed a crash on exit (which I added in Rc1).
  • Added 10 "bytes" the CPU buffer: (#174) + Added new option to [EventLog?] section buffer_size to change the size of the buffer used when scanning the evenlotg (defaults to 64k).
  • Fixed error handling in CHeckEventLog so errors are repoorted properly (#184)
Location:
helpers/systray_helper
Files:
1 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • helpers/systray_helper/TrayWidget.cpp

    rbc97cd8 ra34b229  
    3333 
    3434logging::file_logger g_log_instance(_T("nsclient++"),_T("systray.log")); 
     35HINSTANCE ghInstance = NULL; 
     36TrayWidget *gTrayInstance = NULL; 
    3537 
    3638#define LOG_ERROR_FILE(x) g_log_instance.log(_T("error"), __FILEW__, __LINE__, std::wstring(x).c_str()); 
     
    4143 
    4244#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()); 
    4346 
    4447#if WINVER < 0x0600 
     
    5255    HMODULE hMod = GetModuleHandle(TEXT("user32")); 
    5356    if (hMod == NULL) 
    54       return false; 
     57      return FALSE; 
    5558    fnChangeWindowMessageFilter = (LPFN_CHANGEWINDOWMESSAGEFILTER)GetProcAddress(hMod,"ChangeWindowMessageFilter"); 
    5659  } 
    5760  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...")); 
    6065  return fnChangeWindowMessageFilter(message,what); 
    6166} 
     
    7277  return _T(""); 
    7378} 
    74 HINSTANCE ghInstance = NULL; 
    75 TrayWidget *gTrayInstance = NULL; 
    7679TrayWidget::TrayWidget(std::wstring cmdLine) { 
    7780  strEx::splitList list = strEx::splitEx(cmdLine, _T(" ")); 
     
    124127 
    125128 
     129 
    126130void TrayWidget::createDialog(HINSTANCE hInstance) { 
     131  LOG_MESSAGE_TRAY(_T("Creating dialog...")); 
    127132  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);  
    132154 
    133155  UINT UDM_TASKBARCREATED = RegisterWindowMessage(_T("TaskbarCreated")); 
     
    139161  } 
    140162 
     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  /* 
    141189  MSG Msg; 
    142190  BOOL bRet; 
     
    158206    }  
    159207  } 
     208  */ 
    160209} 
    161210 
     
    529578namespace TrayIcon 
    530579{ 
     580  UINT UDM_TASKBARCREATED = -1; 
    531581  HMENU hPopupMenu_ = NULL; 
    532582} 
    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 ); 
     584LRESULT CALLBACK TrayIcon::DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) 
    534585{ 
     586  if (uMsg == UDM_TASKBARCREATED) { 
     587    addIcon(hwndDlg); 
     588    LOG_MESSAGE_TO_TRAY(_T("UDM_TASKBARCREATED")); 
     589  } 
     590 
    535591  switch (uMsg)  
    536592  { 
     
    542598    return 0; 
    543599 
     600  case WM_CREATE: 
    544601  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 
    545613    addIcon(hwndDlg); 
    546614    break; 
     
    601669    break; 
    602670  } 
    603   return FALSE; 
     671  return DefWindowProc(hwndDlg,uMsg,wParam,lParam); 
     672  //return FALSE; 
    604673} 
    605674void TrayIcon::addIcon(HWND hWnd) { 
  • helpers/systray_helper/TrayWidget.h

    rbc97cd8 ra34b229  
    7575namespace TrayIcon 
    7676{ 
    77   INT_PTR CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam); 
     77  LRESULT CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam); 
    7878  INT_PTR CALLBACK InjectDialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam); 
    7979  INT_PTR CALLBACK LogDialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam); 
Note: See TracChangeset for help on using the changeset viewer.