Beispiel #1
0
//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   //Register to get device messages
   regDeviceNotification(hWnd);

   //Register to get session messages
   WTSRegisterSessionNotification(hWnd, NOTIFY_FOR_THIS_SESSION);

   return TRUE;
}
DWORD WINAPI CreateMsgWindow( LPVOID lpParam )
{
    MSG messages;
    char szClassName[] = "msgWindowClass";
    RegisterDLLWindowClass(szClassName);
    msgWindowHandle = CreateWindowEx (
            0,
            szClassName,
            NULL,
            WS_EX_PALETTEWINDOW,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            0,
            0,
            HWND_DESKTOP,
            NULL,
            msgWindowHInstance,
            NULL
            );

    WTSRegisterSessionNotification(msgWindowHandle, NOTIFY_FOR_THIS_SESSION );

    while (GetMessage (&messages, NULL, 0, 0))
    {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }
    return 1;
}
Beispiel #3
0
HWND
otIdleServiceWin::GetHWND()
{
  HINSTANCE hInst;
  WNDCLASS wc;
  
  if (myHWND)
    return myHWND;
  
  hInst = GetModuleHandle(NULL);
  
  memset(&wc, 0, sizeof(wc));
  wc.style = CS_NOCLOSE | CS_GLOBALCLASS;
  wc.lpfnWndProc = WinProc;
  wc.hInstance = hInst;
  wc.lpszClassName = TEXT("otIdleHandlerClass");
  myWinClass = RegisterClass(&wc);

  if (!myWinClass)
    return NULL;

  myHWND = CreateWindow((LPCSTR)myWinClass, TEXT(""),
                        WS_MINIMIZE, 0, 0, 0, 0,
                        GetDesktopWindow(), NULL, hInst, NULL);
  
  if (!myHWND)
    UnregisterClass((LPCSTR)myWinClass, hInst);

  WTSRegisterSessionNotification(myHWND, NOTIFY_FOR_THIS_SESSION);
  
  return myHWND;
}
EndSessionDetector::EndSessionDetector()
	: m_isDestroyed(false)
{
#ifdef Q_OS_WIN
	if (WTSRegisterSessionNotification(getLightpackApp()->getMainWindowHandle(), NOTIFY_FOR_THIS_SESSION) == FALSE)
		throw std::exception("Failed to register session notification.");
#endif
}
Beispiel #5
0
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_HOTKEY:
		switch ( HIWORD( lParam ) )
		{
		case VK_RIGHT:
			PostEvent( EVENT_TYPE_HOTKEY_NEXT );
			break;

		case VK_SPACE:
			PostEvent( EVENT_TYPE_HOTKEY_PAUSE );
			break;
		}
		break;
	
   case WM_WTSSESSION_CHANGE:
      switch ( wParam )
      {
      case WTS_SESSION_LOCK:	  
			PostEvent( EVENT_TYPE_CONSOLE_LOCK );
			break;
		 
      case WTS_SESSION_UNLOCK:
			PostEvent( EVENT_TYPE_CONSOLE_UNLOCK );
			break;
      }
      break;

   case WM_WINDOWPOSCHANGING:
      {
         WINDOWPOS * pPos = (WINDOWPOS*) lParam;
         pPos->flags |= SWP_HIDEWINDOW;
         pPos->flags &= ~SWP_SHOWWINDOW;
      }
      break;
   
	case WM_INITDIALOG:
		g_hwnd = hDlg;
		WTSRegisterSessionNotification( hDlg, NOTIFY_FOR_ALL_SESSIONS );
		RegisterHotKey( g_hwnd, 1, MOD_ALT | MOD_CONTROL, VK_SPACE );
		RegisterHotKey( g_hwnd, 2, MOD_ALT | MOD_CONTROL, VK_RIGHT );
		return (INT_PTR)TRUE;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
		{
			EndDialog(hDlg, LOWORD(wParam));
			return (INT_PTR)TRUE;
		}
		break;
	}
	return (INT_PTR)FALSE;
}
void CWebinosUI::Initialise()
{
	m_confirmingExit = false;
	m_restartingPzh = m_restartingPzp = 0;

	// Register to receive session-change notifications.
	WTSRegisterSessionNotification(m_hWnd, NOTIFY_FOR_THIS_SESSION);

	// Set user info for this session (this will initialise m_user_params).
	SetSession();

	// Initialise the node services we are interested in.
	m_pzh_params.serviceName = WEBINOS_PZH;
	m_pzp_params.serviceName = WEBINOS_PZP;

	CServiceManager mgr;

	// Get PZH parameters.
	mgr.GetServiceParameters(m_user_params,m_pzh_params);

	// Get PZP parameters.
	mgr.GetServiceParameters(m_user_params,m_pzp_params);

	// Initialise dialog controls with configuration folders.
	SetDlgItemText(IDC_PATH_TO_NODE_EDIT,m_pzp_params.nodePath.c_str());
	SetDlgItemText(IDC_PATH_TO_WEBINOS_EDIT,m_pzp_params.workingDirectoryPath.c_str());

	// Parse node arguments to extract PZP specific params.
  std::vector<std::string> toks = webinos::split(m_pzp_params.nodeArgs.c_str(),' ');
  for (std::vector<std::string>::iterator it = toks.begin(); it != toks.end(); it++)
  {
    std::string tok = *it;
    if (tok.length() == 0)
      continue;

		std::string argVal;
		if (ParseArg(tok,_T("--auth-code=\""),argVal))
			SetDlgItemText(IDC_AUTH_CODE_EDIT,argVal.c_str());
		else if (ParseArg(tok,_T("--pzh-name=\""),argVal))
			SetDlgItemText(IDC_PZH_NAME_EDIT,argVal.c_str());
  }

	// Re-set PZH service parameters.
	m_pzh_params.instance = 0;
	mgr.SetServiceParameters(m_user_params,m_pzh_params);

	// Re-set PZP service parameters.
	m_pzp_params.instance = 0;
	mgr.SetServiceParameters(m_user_params,m_pzp_params);

	// Start timer to poll for status
	SetTimer(ID_POLL_TIMER,SERVICE_POLL_INTERVAL,NULL);
}
Beispiel #7
0
//================================================================================================
//--------------------------------+++--> Register the Clock For Login Session Change Notifications:
void RegisterSession(HWND hwnd)   //---------{ Explicitly Linked for Windows 2000 }---------+++-->
{
	HINSTANCE handle;
	if(m_bMonOffOnLock)
		return;
	handle = LoadLibrary("wtsapi32");
	if(handle){
		typedef BOOL (WINAPI *WTSRegisterSessionNotification_t)(HWND,DWORD);
		WTSRegisterSessionNotification_t WTSRegisterSessionNotification=(WTSRegisterSessionNotification_t)GetProcAddress(handle,"WTSRegisterSessionNotification");
		if(WTSRegisterSessionNotification) {
			WTSRegisterSessionNotification(hwnd,NOTIFY_FOR_THIS_SESSION);
			m_bMonOffOnLock = TRUE;
		}
		FreeLibrary(handle);
	}
}
Beispiel #8
0
int CMainWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	WTSRegisterSessionNotification(GetSafeHwnd(), NOTIFY_FOR_ALL_SESSIONS);

	m_lpDataXMReceiver = new NS_DataX::CDataXMReceiverT<CMainWnd>
		(this, OnDataArrival);

	BOOL bRet = m_lpDataXMReceiver->Create(_T("DdnPcp-CA591950-AA6A-495a-9ABE-C02374F479FE"));

	ASSERT(bRet);

	return 0;
}
/*
 * See https://msdn.microsoft.com/en-us/library/windows/desktop/aa373196(v=vs.85).aspx
 * See https://msdn.microsoft.com/en-us/library/aa383841(v=vs.85).aspx
 * See https://blogs.msdn.microsoft.com/oldnewthing/20060104-50/?p=32783
 */
ScreenLockListenerWin::ScreenLockListenerWin(QWidget* parent)
    : ScreenLockListenerPrivate(parent)
    , QAbstractNativeEventFilter()
{
    Q_ASSERT(parent != nullptr);
    // On windows, we need to register for platform specific messages and
    // install a message handler for them
    QCoreApplication::instance()->installNativeEventFilter(this);

    // This call requests a notification from windows when a laptop is closed
    HPOWERNOTIFY hPnotify = RegisterPowerSettingNotification(
        reinterpret_cast<HWND>(parent->winId()), &GUID_LIDSWITCH_STATE_CHANGE, DEVICE_NOTIFY_WINDOW_HANDLE);
    m_powerNotificationHandle = reinterpret_cast<void*>(hPnotify);

    // This call requests a notification for session changes
    if (!WTSRegisterSessionNotification(reinterpret_cast<HWND>(parent->winId()), NOTIFY_FOR_THIS_SESSION)) {
    }
}
/////////////////////////////////////////////////////////////////////////////
// Registers the LNR window and requests TS session change notifications.
/////////////////////////////////////////////////////////////////////////////
static gboolean plugin_load(PurplePlugin *plugin)
{
    WNDCLASSEX wcx;
    HWND hwnd;
    wcx.cbSize = sizeof(WNDCLASSEX);
    wcx.lpszClassName = "pidgin_lockonaway";
    wcx.lpfnWndProc = (WNDPROC)LnrWindowProc;
    wcx.style = wcx.cbClsExtra = wcx.cbWndExtra = 0;
    wcx.hbrBackground = NULL;
    wcx.hInstance = NULL;
    wcx.hIcon = NULL;
    wcx.hCursor = NULL;
    wcx.hIconSm = NULL;

    // Register the class with Windows
    if(!RegisterClassEx(&wcx))
    {
        purple_notify_message(plugin, PURPLE_NOTIFY_MSG_INFO, "Lock 'n' Roll",
            "RegisterClassEx failed, sorry.", NULL, NULL, NULL);
        return FALSE;
    }

    hwnd = CreateWindowEx(0, "pidgin_lockonaway", "", 0, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, NULL, NULL);
    if(hwnd == NULL)
    {
        purple_notify_message(plugin, PURPLE_NOTIFY_MSG_INFO, "Lock 'n' Roll",
            "CreateWindowEx failed, sorry.", NULL, NULL, NULL);
        return FALSE;
    }

    if(!WTSRegisterSessionNotification(hwnd, NOTIFY_FOR_THIS_SESSION))
    {
        purple_notify_message(plugin, PURPLE_NOTIFY_MSG_INFO, "Lock 'n' Roll",
            "WTSRegisterSessionNotification failed, sorry.", NULL, NULL, NULL);
        return FALSE;
    }

    lnr_reactivate_status = NULL;
    lnr_handle = plugin;
    lnr_hwnd = hwnd;

    return TRUE;
}
Beispiel #11
0
/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  static UINT s_uTaskbarRestart;
  int i;

  switch (message) {
    case WM_CREATE:       

      /* Save Window Handle */
      o.hWnd = hwnd;

      s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));

      WTSRegisterSessionNotification(hwnd, NOTIFY_FOR_THIS_SESSION);

      /* Load application icon */
      HICON hIcon = LoadLocalizedIcon(ID_ICO_APP);
      if (hIcon) {
        SendMessage(hwnd, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon));
        SendMessage(hwnd, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon));
      }

      CreatePopupMenus();	/* Create popup menus */  
      ShowTrayIcon();
      if (o.allow_service[0]=='1' || o.service_only[0]=='1')
        CheckServiceStatus();	// Check if service is running or not
      if (!AutoStartConnections()) {
        SendMessage(hwnd, WM_CLOSE, 0, 0);
        break;
      }
      break;
    	
    case WM_NOTIFYICONTRAY:
      OnNotifyTray(lParam); 	// Manages message from tray
      break;

    case WM_COMMAND:
      if ( (LOWORD(wParam) >= IDM_CONNECTMENU) && (LOWORD(wParam) < IDM_CONNECTMENU + MAX_CONFIGS) ) {
        StartOpenVPN(&o.conn[LOWORD(wParam) - IDM_CONNECTMENU]);
      }
      if ( (LOWORD(wParam) >= IDM_DISCONNECTMENU) && (LOWORD(wParam) < IDM_DISCONNECTMENU + MAX_CONFIGS) ) {
        StopOpenVPN(&o.conn[LOWORD(wParam) - IDM_DISCONNECTMENU]);
      }
      if ( (LOWORD(wParam) >= IDM_STATUSMENU) && (LOWORD(wParam) < IDM_STATUSMENU + MAX_CONFIGS) ) {
        ShowWindow(o.conn[LOWORD(wParam) - IDM_STATUSMENU].hwndStatus, SW_SHOW);
      }
      if ( (LOWORD(wParam) >= IDM_VIEWLOGMENU) && (LOWORD(wParam) < IDM_VIEWLOGMENU + MAX_CONFIGS) ) {
        ViewLog(LOWORD(wParam) - IDM_VIEWLOGMENU);
      }
      if ( (LOWORD(wParam) >= IDM_EDITMENU) && (LOWORD(wParam) < IDM_EDITMENU + MAX_CONFIGS) ) {
        EditConfig(LOWORD(wParam) - IDM_EDITMENU);
      }
#ifndef DISABLE_CHANGE_PASSWORD
      if ( (LOWORD(wParam) >= IDM_PASSPHRASEMENU) && (LOWORD(wParam) < IDM_PASSPHRASEMENU + MAX_CONFIGS) ) {
        ShowChangePassphraseDialog(&o.conn[LOWORD(wParam) - IDM_PASSPHRASEMENU]);
      }
#endif
      if (LOWORD(wParam) == IDM_SETTINGS) {
        ShowSettingsDialog();
      }
      if (LOWORD(wParam) == IDM_CLOSE) {
        CloseApplication(hwnd);
      }
      if (LOWORD(wParam) == IDM_SERVICE_START) {
        MyStartService();
      }
      if (LOWORD(wParam) == IDM_SERVICE_STOP) {
        MyStopService();
      }     
      if (LOWORD(wParam) == IDM_SERVICE_RESTART) MyReStartService();
      break;
	    
    case WM_CLOSE:
      CloseApplication(hwnd);
      break;

    case WM_DESTROY:
      WTSUnRegisterSessionNotification(hwnd);
      StopAllOpenVPN();	
      OnDestroyTray();          /* Remove Tray Icon and destroy menus */
      PostQuitMessage (0);	/* Send a WM_QUIT to the message queue */
      break;

    case WM_QUERYENDSESSION:
      return(TRUE);

    case WM_ENDSESSION:
      StopAllOpenVPN();
      OnDestroyTray();
      break;

    case WM_WTSSESSION_CHANGE:
      switch (wParam) {
        case WTS_SESSION_LOCK:
          o.session_locked = TRUE;
          break;
        case WTS_SESSION_UNLOCK:
          o.session_locked = FALSE;
          if (CountConnState(suspended) != 0)
            ResumeConnections();
          break;
      }
      break;

    case WM_POWERBROADCAST:
      switch (wParam) {
        case PBT_APMSUSPEND:
          if (o.disconnect_on_suspend[0] == '1')
            {
              /* Suspend running connections */
              for (i=0; i<o.num_configs; i++)
                {
                  if (o.conn[i].state == connected)
                SuspendOpenVPN(i);
                }

              /* Wait for all connections to suspend */
              for (i=0; i<10; i++, Sleep(500))
                if (CountConnState(suspending) == 0) break;
            }
          return FALSE;

        case PBT_APMRESUMESUSPEND:
        case PBT_APMRESUMECRITICAL:
          if (CountConnState(suspended) != 0 && !o.session_locked)
            ResumeConnections();
          return FALSE;
      }

    default:			/* for messages that we don't deal with */
      if (message == s_uTaskbarRestart)
        {
          /* Explorer has restarted, re-register the tray icon. */
          ShowTrayIcon();
          CheckAndSetTrayIcon();
          break;
        }      
      return DefWindowProc (hwnd, message, wParam, lParam);
  }

  return 0;
}
void VDAgent::input_desktop_message_loop()
{
    TCHAR desktop_name[MAX_PATH];
    HDESK hdesk;

    hdesk = OpenInputDesktop(0, FALSE, GENERIC_ALL);
    if (!hdesk) {
        vd_printf("OpenInputDesktop() failed: %lu", GetLastError());
        _running = false;
        return;
    }
    if (!SetThreadDesktop(hdesk)) {
        vd_printf("SetThreadDesktop failed %lu", GetLastError());
        _running = false;
        return;
    }
    if (GetUserObjectInformation(hdesk, UOI_NAME, desktop_name, sizeof(desktop_name), NULL)) {
        vd_printf("Desktop: %S", desktop_name);
    } else {
        vd_printf("GetUserObjectInformation failed %lu", GetLastError());
    }

    // loading the display settings for the current session's logged on user only
    // after 1) we receive logon event, and 2) the desktop switched from Winlogon
    if (_tcscmp(desktop_name, TEXT("Winlogon")) == 0) {
        _logon_desktop = true;
    } else {
        // first load after connection
        if (!_display_setting_initialized) {
            vd_printf("First display setting");
            _display_setting.load();
            _display_setting_initialized = true;
        } else if (_logon_occured && _logon_desktop) {
            vd_printf("LOGON display setting");
            _display_setting.load();
        }
        _logon_occured = false;
        _logon_desktop = false;
    }

    _hwnd = CreateWindow(VD_AGENT_WINCLASS_NAME, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
    if (!_hwnd) {
        vd_printf("CreateWindow() failed: %lu", GetLastError());
        _running = false;
        return;
    }
    if (!WTSRegisterSessionNotification(_hwnd, NOTIFY_FOR_ALL_SESSIONS)) {
        vd_printf("WTSRegisterSessionNotification() failed: %lu", GetLastError());
    }
    if (_system_version == SYS_VER_WIN_7_CLASS) {
        _add_clipboard_listener(_hwnd);
    } else {
        _hwnd_next_viewer = SetClipboardViewer(_hwnd);
    }
    while (_running && !_desktop_switch) {
        event_dispatcher(INFINITE, QS_ALLINPUT);
    }
    _desktop_switch = false;
    if (_pending_input) {
        KillTimer(_hwnd, VD_TIMER_ID);
        _pending_input = false;
    }
    if (_system_version == SYS_VER_WIN_7_CLASS) {
        _remove_clipboard_listener(_hwnd);
    } else {
        ChangeClipboardChain(_hwnd, _hwnd_next_viewer);
    }
    WTSUnRegisterSessionNotification(_hwnd);
    DestroyWindow(_hwnd);
    CloseDesktop(hdesk);
}
Beispiel #13
0
int MirandaLoaded(WPARAM,LPARAM)
{
	g_wMask = db_get_w(NULL,MOD_NAME,"optsmask",DEFAULTSETTING);

	RegisterCoreHotKeys();

	g_hWinHook = SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_SHOW, NULL, WinEventProc, GetCurrentProcessId(), 0, 0);

	HookEvent(ME_TTB_MODULELOADED, TopToolbarInit);
	HookEvent(ME_OPT_INITIALISE, OptsDlgInit);
	HookEvent(ME_MSG_WINDOWEVENT, MsgWinOpening);
	HookEvent(ME_PROTO_ACCLISTCHANGED, EnumProtos);
	HookEvent(ME_MSG_TOOLBARLOADED, TabsrmmButtonsInit);
	HookEvent(ME_MSG_BUTTONPRESSED, TabsrmmButtonPressed);

	GetWindowThreadProcessId(pcli->hwndContactList, &g_dwMirandaPID);

	WNDCLASS winclass = {0};
	winclass.lpfnWndProc = ListenWndProc;
	winclass.hInstance = g_hInstance;
	winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	winclass.lpszClassName = BOSSKEY_LISTEN_INFO;

	if (RegisterClass(&winclass))
	{
		g_hListenWindow = CreateWindow(BOSSKEY_LISTEN_INFO,BOSSKEY_LISTEN_INFO,WS_POPUP,0,0,5,5,pcli->hwndContactList,NULL,g_hInstance,NULL);
		WTSRegisterSessionNotification(g_hListenWindow, 0);
	}

	if (IsWinVerVistaPlus())
	{
		hDwmApi = LoadLibrary(_T("dwmapi.dll"));
		if (hDwmApi)
			dwmIsCompositionEnabled = (PFNDwmIsCompositionEnabled)GetProcAddress(hDwmApi,"DwmIsCompositionEnabled");
	}
	if (g_wMaskAdv & OPT_MENUITEM)
		BossKeyMenuItemInit();

	// Register token for variables plugin
	if (ServiceExists(MS_VARS_REGISTERTOKEN))
	{
		TOKENREGISTER tr = {0};
		tr.cbSize = sizeof(TOKENREGISTER);
		tr.memType = TR_MEM_OWNER;
		tr.flags = TRF_FIELD | TRF_TCHAR | TRF_PARSEFUNC;

		tr.tszTokenString = _T("bosskeyname");
		tr.parseFunctionT = VariablesBossKey;
		tr.szHelpText = LPGEN("BossKey")"\t"LPGEN("get the BossKey name");
		CallService(MS_VARS_REGISTERTOKEN, 0, (LPARAM) &tr);
	}

	EnumProtos(0, 0);
	InitIdleTimer();

	if (g_bOldSetting && !(g_wMaskAdv & OPT_RESTORE)) // Restore settings if Miranda was crushed or killed in hidden mode and "Restore hiding on startup after failure" option is disabled
		RestoreOldSettings();

	if ((g_wMaskAdv & OPT_HIDEONSTART) || (g_wMaskAdv & OPT_RESTORE && g_bOldSetting))
		BossKeyHideMiranda(0, 0);

	return 0;
}