7 #include "../clib/esignal.h" 8 #include "../clib/threadhelp.h" 10 #include "../clib/logfacility.h" 12 #include "../plib/systemstate.h" 16 #include "../clib/Program/ProgramConfig.h" 17 #include "../clib/Header_Windows.h" 20 #include "../clib/NTService.h" 21 #include "../clib/ntservmsg.h" 24 #pragma warning( disable : 4189 ) // local variable is initialized but not referenced. TODO: check 35 int xmain(
int argc,
char* argv[] )
61 rc = GetCurrentDirectory(
sizeof buffer, buffer );
64 rc = SetCurrentDirectory( PROG_CONFIG::programDir().c_str() );
68 catch ( std::exception& ex )
97 #define WM_ICON_NOTIFY WM_USER + 1 102 #define DLG_MODELESS 1 105 INT_PTR CALLBACK
DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
107 BOOL CALLBACK
DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
110 if ( uMsg == WM_TASKBARCREATED )
111 uMsg = WM_INITDIALOG;
117 ndata.hWnd = hwndDlg;
119 Shell_NotifyIcon( NIM_ADD, &ndata );
121 SetWindowPos( hwndDlg,
nullptr, -10, -10, 0, 0, SWP_NOZORDER | SWP_NOMOVE );
127 if ( lParam == WM_RBUTTONDOWN )
130 HMENU m = LoadMenu( GetModuleHandle(
nullptr ), MAKEINTRESOURCE(
IDR_POPUP ) );
131 HMENU subm = GetSubMenu( m, 0 );
135 SetForegroundWindow( hwndDlg );
136 BOOL rc = TrackPopupMenu( subm, TPM_LEFTALIGN, p.x, p.y, 0, hwndDlg,
nullptr );
137 PostMessage( hwndDlg, WM_NULL, 0, 0 );
186 Shell_NotifyIcon( NIM_MODIFY, &ndata );
190 Shell_NotifyIcon( NIM_DELETE, &ndata );
192 DestroyWindow( hwndDlg );
194 EndDialog( hwndDlg, wParam );
202 Shell_NotifyIcon( NIM_DELETE, &ndata );
204 DestroyWindow( hwndDlg );
206 EndDialog( hwndDlg, wParam );
221 ShowWindow( hwnd, SW_HIDE );
226 while ( ( bRet = GetMessage( &msg,
nullptr, 0, 0 ) ) != 0 )
233 else if ( !IsWindow( hwnd ) || !IsDialogMessage( hwnd, &msg ) )
235 TranslateMessage( &msg );
236 DispatchMessage( &msg );
247 strncpy( ndata.szTip, text,
sizeof( ndata.szTip ) - 1 );
248 ndata.szTip[
sizeof( ndata.szTip ) - 1] =
'\0';
256 switch ( dwCtrlType )
258 case CTRL_CLOSE_EVENT:
259 Shell_NotifyIcon( NIM_DELETE, &ndata );
261 DestroyWindow( hwnd );
263 EndDialog( hwndDlg, wParam );
271 WM_TASKBARCREATED = RegisterWindowMessage(
"TaskbarCreated" );
273 ndata.cbSize =
sizeof( NOTIFYICONDATA );
276 ndata.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
278 ndata.hIcon = ::LoadIcon( GetModuleHandle(
nullptr ), MAKEINTRESOURCE(
IDI_POLTRAY ) );
279 strcpy( ndata.szTip,
"POL Initializing" );
297 PDWORD_PTR res =
nullptr;
298 LRESULT rc = SendMessageTimeout( hwnd, WM_COMMAND,
ID_SHUTDOWN, 0, SMTO_NORMAL, 5000, res );
301 LRESULT rc = SendMessageTimeout( hwnd, WM_COMMAND,
ID_SHUTDOWN, 0, SMTO_NORMAL, 5000, &res );
306 DWORD err = GetLastError();
307 INFO_PRINT <<
"Unable to shutdown systray: " << err <<
"\n";
BOOL ParseStandardArgs(int argc, char *argv[])
int RunWindowsService(int argc, char **argv)
virtual void OnStop() POL_OVERRIDE
int xmain(int argc, char *argv[])
void SystemTrayDialogThread(void *)
typedef DWORD(WINAPI *__SymGetOptions)(VOID)
int xmain_outer(bool testing)
virtual void Run() POL_OVERRIDE
#define ID_UPDATE_NOTIFYDATA
void InitializeSystemTrayHandling()
typedef BOOL(WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess
BOOL WINAPI control_handler_SystemTray(DWORD dwCtrlType)
unsigned WM_TASKBARCREATED
void LogEvent(WORD wType, DWORD dwID, const char *pszS1=NULL, const char *pszS2=NULL, const char *pszS3=NULL)
#define ID_POPUP_SHOWCONSOLE
void SetSysTrayPopupText(const char *text)
void ShutdownSystemTrayHandling()
std::atomic< bool > exit_signalled
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)