Exemplo n.º 1
0
///////////////////////////////////////////////////////////////////////////////
// Handles events at the window (both hot key and from the tray icon)
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)
	{
	case WM_CREATE:
		g_uTaskbarRestart = RegisterWindowMessage(L"TaskbarCreated");
		AddTrayIcon(hWnd, 0, APPWM_TRAYICON, IDI_MAINFRAME, TITLE);
		return 0;

	case APPWM_TRAYICON:
		return OnTrayIcon(hWnd, wParam, lParam);

	case WM_COMMAND:
		return OnCommand(hWnd, LOWORD(wParam), (HWND)lParam);

	case WM_CLOSE:
		DestroyWindow(hWnd);
		return 0;

	case WM_DESTROY:
		RemoveTrayIcon(hWnd, 0);
		PostQuitMessage(0);
		return 0;

	default:
		if(uMsg == g_uTaskbarRestart)
		{
			AddTrayIcon(hWnd, 0, APPWM_TRAYICON, IDI_MAINFRAME, TITLE);
			return 0;
		}

		return DefWindowProc(hWnd, uMsg, wParam, lParam);
	}
}
Exemplo n.º 2
0
void Daemon::CheckTrayIcon() {
	vnclog.Print(8, _T("Checking tray icon\n"));
	if (!SendTrayMsg(NIM_MODIFY)) {
		vnclog.Print(4, _T("Tray icon not there - reinstalling\n"));
		AddTrayIcon();
	};
}
Exemplo n.º 3
0
void Daemon::CheckTrayIcon() {
	Log::info(_T("Checking tray icon\n"));
	if (!SendTrayMsg(NIM_MODIFY)) {
		Log::message(_T("Tray icon not there - reinstalling\n"));
		AddTrayIcon();
	};
}
Exemplo n.º 4
0
void TrayIcon::OnTaskbarCreated()
{
	if (mb_WindowInTray)
	{
		mb_WindowInTray = false;
		AddTrayIcon();
	}
}
Exemplo n.º 5
0
void CResendDlg::CloseDialog(int nVal)
{
    DestroyWindow();
    AddTrayIcon(FALSE);

    Utility::RecycleFile(m_sLogFile, true);

    ::PostQuitMessage(nVal);
}
Exemplo n.º 6
0
	bool CTaskTrayManager::HandleMessage(UINT Message,WPARAM wParam,LPARAM lParam)
	{
		if (m_TaskbarCreatedMessage!=0
				&& Message==m_TaskbarCreatedMessage) {
			if (m_fShowTrayIcon)
				AddTrayIcon();

			return true;
		}

		return false;
	}
Exemplo n.º 7
0
bool Tray::Create( HWND hwnd, UINT uid, UINT ucallback_msg, HICON htray_icon, wchar_t* sztip )
{
  notify_icon_data_.cbSize = GetNOTIFYICONDATASizeForOS();
  notify_icon_data_.hWnd = hwnd;
  notify_icon_data_.uID = uid;
  notify_icon_data_.uCallbackMessage = ucallback_msg;
  notify_icon_data_.hIcon = htray_icon;
  wcscpy_s(notify_icon_data_.szTip, sizeof(notify_icon_data_.szTip)/sizeof(wchar_t), sztip);

  AddTrayIcon();

  return true;
}
Exemplo n.º 8
0
void ReloadTsTrayIcons() {
	if (g_dwFlags & TSF_SHOWTRAYICON) {
		if (!ReloadTrayIcon(g_hwndMain, IDI_TASKSWITCHXP))
			ShowTrayIcon(TRUE);
	}
	for (int i = (int)g_cWti - 1; i >= 0; i--) {
		if (!ReloadTrayIcon(g_hwndMain, g_pWti[i].uID)) {
			if (IsWindow(g_pWti[i].hwnd)) {
				WCHAR szCaption[MAX_CAPTION];
				InternalGetWindowText(g_pWti[i].hwnd, szCaption, MAX_CAPTION);
				AddTrayIcon(g_hwndMain, g_pWti[i].uID, g_pWti[i].hIconSm, szCaption);
			}
		}
	}
}
Exemplo n.º 9
0
LRESULT
CMainWindow::OnCreate(HWND hwnd)
{
    m_hMainWnd = hwnd;

    if (!AddTrayIcon())
        return -1;

    if (SetTimer(hwnd, IDT_TIMER, 3000, NULL) == 0)
    {
        RemoveTrayIcon();
        return -1;
    }

    return 0;
}
Exemplo n.º 10
0
// ------------------------------------------------------------------------------------------------
// Message handler
//
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	case WM_CREATE:
		AddTrayIcon(hWnd, ID_TRAYICON, APPWM_TRAYICON, IDI_MEMORY, _T("Looking for SUPERPLAY..."));
		//MonitorProcess(proc_name, limit_mb, hWnd, ID_TRAYICON);
		return(0);

	case APPWM_NOP:			// see OnTrayIconRBtnUp()
		return(0);

	case APPWM_TRAYICON:	// mouse events involving our tray icon
		SetForegroundWindow(hWnd);

		switch (lParam)
		{
		case WM_RBUTTONUP:	// see OnTrayIconRBtnUp()
			OnTrayIconRBtnUp(hWnd);
			return(0);

		}
		return(0);

	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case ID_ABOUT:
			g_bModalState = TRUE;
			MessageBox(hWnd, HELP_ABOUT, THIS_TITLE, MB_ICONINFORMATION | MB_OK);
			g_bModalState = FALSE;
			break;
		case ID_EXIT:
			PostMessage(hWnd, WM_CLOSE, 0, 0);
			break;
		}
		return(0);

	case WM_CLOSE:
		OnClose(hWnd);
		// fall through
	default:
		return(DefWindowProc(hWnd, uMsg, wParam, lParam));
	}
}
Exemplo n.º 11
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR    lpCmdLine,
                     int       nCmdShow)
{

    // Register the main window class
    WindowClass wndClass( KWindowClass, WndProc );

    // Create all of the windows
    CreateWindows();

    // Create the "sink" window that handles the timer to update all other windows
    HWND hWnd = CreateWindowA( KWindowClass, KWindowTitle, 
         WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, // style
        CW_USEDEFAULT,  //x
        0,              // y
        1, // w
        1,  // h
        NULL, // Parent
        NULL, // hMenu
        hInstance, NULL);
    DWORD gle = GetLastError();

    // Update the new window
    UpdateWindow(hWnd);

    // Add the tray icon
    AddTrayIcon(hWnd);

    // Main message loop
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);  
    }

    for ( unsigned int i=0; i<g_windows.size(); i++ )
    {
        delete g_windows[i];
    }

    return (int) msg.wParam;
}
Exemplo n.º 12
0
BOOL ShowTrayIcon(BOOL fShow) {

	BOOL fRet = DeleteTrayIcon(g_hwndMain, IDI_TASKSWITCHXP);
	g_dwFlags &= ~TSF_SHOWTRAYICON;

	if (g_hIconTray) {
		DestroyIcon(g_hIconTray);
		g_hIconTray = NULL;
	}

	if (fShow) {

		HICON hIconSm = NULL;
		if (g_dwFlags & TSF_USECUSTOMICON) {
			HKEY hkey = NULL;
			if (!RegOpenKeyEx(HKEY_CURRENT_USER, g_szRegKeyTs, 0, KEY_READ, &hkey)) {
				WCHAR szBuff[MAX_DATALEN] = L"";
				DWORD cbData = MAX_DATALEN * sizeof(WCHAR);
				if (!RegQueryValueEx(hkey, RS_CUSTOMICON, 0, NULL, (PBYTE)szBuff, &cbData)) {
					int nIconIndex;
					if (_GetIconPathIndex(szBuff, &nIconIndex)) {
						if (!ExtractIconEx(szBuff, nIconIndex, NULL, &hIconSm, 1))
							hIconSm = NULL;
					}
				}
				RegCloseKey(hkey);
			}
		}

		if (!hIconSm) {
			g_hIconTray = (HICON)LoadImage(g_hinstExe, MAKEINTRESOURCE(IDI_TASKSWITCHXP), 
				IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
		} else {
			g_hIconTray = CopyIcon(hIconSm);
			DestroyIcon(hIconSm);
		}

		if (!g_hIconTray)
			g_hIconTray = LoadIcon(NULL, IDI_WARNING);

		fRet = AddTrayIcon(g_hwndMain, IDI_TASKSWITCHXP, g_hIconTray, g_szWindowName);
		g_dwFlags |= TSF_SHOWTRAYICON;
	}
	return(fRet);
}
Exemplo n.º 13
0
void TrayIcon::ShowTrayIcon(LPCTSTR asInfoTip /*= NULL*/, TrayIconMsgSource aMsgSource /*= tsa_Source_None*/)
{
	m_MsgSource = aMsgSource;
	if (asInfoTip && *asInfoTip)
	{
		// Сообщение, которое сейчас всплывет
		IconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_INFO | NIF_TIP;
		lstrcpyn(IconData.szInfoTitle, gpConEmu->GetDefaultTitle(), countof(IconData.szInfoTitle));
		lstrcpyn(IconData.szInfo, asInfoTip, countof(IconData.szInfo));
	}
	else
	{
		IconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
		IconData.szInfo[0] = 0;
		IconData.szInfoTitle[0] = 0;
	}
	AddTrayIcon(); // добавит или обновит tooltip
}
Exemplo n.º 14
0
void TrayIcon::SettingsChanged()
{
	bool bShowTSA = gpSet->isAlwaysShowTrayIcon();

	if (bShowTSA)
	{
		AddTrayIcon(); // добавит или обновит tooltip
	}
	else
	{
		if (IsWindowVisible(ghWnd))
			RemoveTrayIcon();
	}

	if (gpSetCls->GetPage(gpSetCls->thi_Taskbar))
	{
		CheckDlgButton(gpSetCls->GetPage(gpSetCls->thi_Taskbar), cbAlwaysShowTrayIcon, bShowTSA);
	}
}
Exemplo n.º 15
0
void CResendDlg::DoBalloonTimer()
{
    if(m_nTick==0)
    {
        // Show tray icon and balloon.
        AddTrayIcon(TRUE);

        KillTimer(0);

        // Wait for one minute. If user doesn't want to click us, exit.
        SetTimer(0, 60000);
    }
    else if(m_nTick==1)
    {
        KillTimer(0);
        CloseDialog(0);
    }

    m_nTick ++;
}
Exemplo n.º 16
0
void TrayIcon::SettingsChanged()
{
	if (gpSet->isAlwaysShowTrayIcon)
	{
		AddTrayIcon(); // добавит или обновит tooltip
	}
	else
	{
		if (IsWindowVisible(ghWnd))
			RemoveTrayIcon();
	}

	//if (ghWnd)
	//{
	//	DWORD_PTR nStyleEx = GetWindowLongPtr(ghWnd, GWL_EXSTYLE);
	//	DWORD_PTR nNewStyleEx = nStyleEx;
	//	if (gpSet->isAlwaysShowTrayIcon == 2)
	//		nNewStyleEx |= WS_EX_TOOLWINDOW;
	//	else if (nNewStyleEx & WS_EX_TOOLWINDOW)
	//		nNewStyleEx &= ~WS_EX_TOOLWINDOW;
	//	if (nNewStyleEx != nStyleEx)
	//		SetWindowLongPtr(ghWnd, GWL_EXSTYLE, nNewStyleEx);
	//}
}
Exemplo n.º 17
0
	static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
		static UINT s_uTaskbarRestart;

		switch (uMsg)
		{
			case WM_CREATE:
			{
				s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
				AddTrayIcon (hWnd);
				break;
			}
			case WM_CLOSE:
			{
				RemoveTrayIcon (hWnd);
				KillTimer (hWnd, FRAME_UPDATE_TIMER);
				KillTimer (hWnd, IDT_GRACEFUL_SHUTDOWN_TIMER);
				KillTimer (hWnd, IDT_GRACEFUL_TUNNELCHECK_TIMER);
				PostQuitMessage (0);
				break;
			}
			case WM_COMMAND:
			{
				switch (LOWORD(wParam))
				{
					case ID_ABOUT:
					{
						std::stringstream text;
						text << "Version: " << I2PD_VERSION << " " << CODENAME;
						MessageBox( hWnd, TEXT(text.str ().c_str ()), TEXT("i2pd"), MB_ICONINFORMATION | MB_OK );
						return 0;
					}
					case ID_EXIT:
					{
						PostMessage (hWnd, WM_CLOSE, 0, 0);
						return 0;
					}
					case ID_ACCEPT_TRANSIT:
					{
						i2p::context.SetAcceptsTunnels (true);
						std::stringstream text;
						text << "I2Pd now accept transit tunnels";
						MessageBox( hWnd, TEXT(text.str ().c_str ()), TEXT("i2pd"), MB_ICONINFORMATION | MB_OK );
						return 0;
					}
					case ID_DECLINE_TRANSIT:
					{
						i2p::context.SetAcceptsTunnels (false);
						std::stringstream text;
						text << "I2Pd now decline new transit tunnels";
						MessageBox( hWnd, TEXT(text.str ().c_str ()), TEXT("i2pd"), MB_ICONINFORMATION | MB_OK );
						return 0;
					}
					case ID_GRACEFUL_SHUTDOWN:
					{
						i2p::context.SetAcceptsTunnels (false);
						SetTimer (hWnd, IDT_GRACEFUL_SHUTDOWN_TIMER, 10*60*1000, nullptr); // 10 minutes
						SetTimer (hWnd, IDT_GRACEFUL_TUNNELCHECK_TIMER, 1000, nullptr); // check tunnels every second
						GracefulShutdownEndtime = GetTickCount() + 10*60*1000;
						i2p::util::DaemonWin32::Instance ().isGraceful = true;
						return 0;
					}
					case ID_STOP_GRACEFUL_SHUTDOWN:
					{
						i2p::context.SetAcceptsTunnels (true);
						KillTimer (hWnd, IDT_GRACEFUL_SHUTDOWN_TIMER);
						KillTimer (hWnd, IDT_GRACEFUL_TUNNELCHECK_TIMER);
						GracefulShutdownEndtime = 0;
						i2p::util::DaemonWin32::Instance ().isGraceful = false;
						return 0;
					}
					case ID_RELOAD:
					{
						i2p::client::context.ReloadConfig();
						std::stringstream text;
						text << "I2Pd reloading configs...";
						MessageBox( hWnd, TEXT(text.str ().c_str ()), TEXT("i2pd"), MB_ICONINFORMATION | MB_OK );
						return 0;
					}
					case ID_CONSOLE:
					{
						char buf[30];
						std::string httpAddr; i2p::config::GetOption("http.address", httpAddr);
						uint16_t httpPort; i2p::config::GetOption("http.port", httpPort);
						snprintf(buf, 30, "http://%s:%d", httpAddr.c_str(), httpPort);
						ShellExecute(NULL, "open", buf, NULL, NULL, SW_SHOWNORMAL);
						return 0;
					}
					case ID_APP:
					{
						ShowWindow(hWnd, SW_SHOW);
						SetTimer(hWnd, FRAME_UPDATE_TIMER, 3000, NULL);
						return 0;
					}
				}
				break;
			}
			case WM_SYSCOMMAND:
			{
				switch (wParam)
				{
					case SC_MINIMIZE:
					{
						ShowWindow(hWnd, SW_HIDE);
						KillTimer (hWnd, FRAME_UPDATE_TIMER);
						return 0;
					}
					case SC_CLOSE:
					{
						std::string close; i2p::config::GetOption("close", close);
						if (0 == close.compare("ask"))
						switch(::MessageBox(hWnd, "Would you like to minimize instead of exiting?"
						" You can add 'close' configuration option. Valid values are: ask, minimize, exit.",
						"Minimize instead of exiting?", MB_ICONQUESTION | MB_YESNOCANCEL | MB_DEFBUTTON1))
						{
							case IDYES: close = "minimize"; break;
							case IDNO: close = "exit"; break;
							default: return 0;
						}
						if (0 == close.compare("minimize"))
						{
							ShowWindow(hWnd, SW_HIDE);
							KillTimer (hWnd, FRAME_UPDATE_TIMER);
							return 0;
						}
						if (0 != close.compare("exit"))
						{
							::MessageBox(hWnd, close.c_str(), "Unknown close action in config", MB_OK | MB_ICONWARNING);
							return 0;
						}
					}
				}
			}
			case WM_TRAYICON:
			{
				switch (lParam)
				{
					case WM_LBUTTONUP:
					case WM_RBUTTONUP:
					{
						SetForegroundWindow (hWnd);
						ShowPopupMenu(hWnd, NULL, -1);
						PostMessage (hWnd, WM_APP + 1, 0, 0);
						break;
					}
				}
				break;
			}
			case WM_TIMER:
			{
				switch(wParam)
				{
					case IDT_GRACEFUL_SHUTDOWN_TIMER:
					{
						GracefulShutdownEndtime = 0;
						PostMessage (hWnd, WM_CLOSE, 0, 0); // exit
						return 0;
					}
					case FRAME_UPDATE_TIMER:
					{
						InvalidateRect(hWnd, NULL, TRUE);
						return 0;
					}
					case IDT_GRACEFUL_TUNNELCHECK_TIMER:
					{
						if (i2p::tunnel::tunnels.CountTransitTunnels() == 0)
							PostMessage (hWnd, WM_CLOSE, 0, 0);
						else
							SetTimer (hWnd, IDT_GRACEFUL_TUNNELCHECK_TIMER, 1000, nullptr);
						return 0;
					}
				}
				break;
			}
			case WM_PAINT:
			{
				HDC hDC;
				PAINTSTRUCT ps;
				RECT rp;
				HFONT hFont;
				std::stringstream s; PrintMainWindowText (s);
				hDC = BeginPaint (hWnd, &ps);
				GetClientRect(hWnd, &rp);
				SetTextColor(hDC, 0x00D43B69);
				hFont = CreateFont(18,0,0,0,0,0,0,0,DEFAULT_CHARSET,0,0,0,0,TEXT("Times New Roman"));
				SelectObject(hDC,hFont);
				DrawText(hDC, TEXT(s.str().c_str()), s.str().length(), &rp, DT_CENTER|DT_VCENTER);
				DeleteObject(hFont);
				EndPaint(hWnd, &ps);
				break;
			}
			default:
			{
				if (uMsg == s_uTaskbarRestart)
					AddTrayIcon (hWnd);
				break;
			}
		}
		return DefWindowProc( hWnd, uMsg, wParam, lParam);
	}
Exemplo n.º 18
0
vncMenu::vncMenu(vncServer *server)
{
	ports_set=false;
    CoInitialize(0);
	

	// Save the server pointer
	m_server = server;

	// Set the initial user name to something sensible...
	vncService::CurrentUser((char *)&m_username, sizeof(m_username));

	// Create a dummy window to handle tray icon messages
	WNDCLASSEX wndclass;

	wndclass.cbSize			= sizeof(wndclass);
	wndclass.style			= 0;
	wndclass.lpfnWndProc	= vncMenu::WndProc;
	wndclass.cbClsExtra		= 0;
	wndclass.cbWndExtra		= 0;
	wndclass.hInstance		= hAppInstance;
	wndclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground	= (HBRUSH) GetStockObject(WHITE_BRUSH);
	wndclass.lpszMenuName	= (const char *) NULL;
	wndclass.lpszClassName	= MENU_CLASS_NAME;
	wndclass.hIconSm		= LoadIcon(NULL, IDI_APPLICATION);

	RegisterClassEx(&wndclass);

	m_hwnd = CreateWindow(MENU_CLASS_NAME,
				MENU_CLASS_NAME,
				WS_OVERLAPPEDWINDOW,
				CW_USEDEFAULT,
				CW_USEDEFAULT,
				200, 200,
				NULL,
				NULL,
				hAppInstance,
				NULL);
	if (m_hwnd == NULL)
	{
		PostQuitMessage(0);
		return;
	}

	// record which client created this window
	SetWindowLong(m_hwnd, GWL_USERDATA, (LONG) this);

	// Ask the server object to notify us of stuff
	server->AddNotify(m_hwnd);

	// Initialise the properties dialog object
	if (!m_properties.Init(m_server))
	{
		PostQuitMessage(0);
		return;
	}
	if (!m_propertiesPoll.Init(m_server))
	{
		PostQuitMessage(0);
		return;
	}

	// Only enable the timer if the tray icon will be displayed.
	if ( ! server->GetDisableTrayIcon())
	{
		// Timer to trigger icon updating
		SetTimer(m_hwnd, 1, 5000, NULL);
	}

	// Load the icons for the tray
//	m_winvnc_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_WINVNC));
//	m_flash_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_FLASH));
	{
		OSVERSIONINFO	osvi;
	osvi.dwOSVersionInfoSize = sizeof(osvi);
	GetVersionEx(&osvi);
if (osvi.dwPlatformId==VER_PLATFORM_WIN32_NT)
		{
		  if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion>=1)
		  {
			m_winvnc_icon=(HICON)LoadImage(NULL, "icon1.ico", IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE|LR_DEFAULTCOLOR);
			m_flash_icon=(HICON)LoadImage(NULL, "icon2.ico", IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE|LR_DEFAULTCOLOR);

			if (!m_winvnc_icon) m_winvnc_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_WINVNC), IMAGE_ICON,
                        GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
			if (!m_flash_icon) m_flash_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_FLASH), IMAGE_ICON,
                        GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
		  }
		  else
		 {
			  m_winvnc_icon=(HICON)LoadImage(NULL, "icon1.ico", IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE|LR_VGACOLOR);
				m_flash_icon=(HICON)LoadImage(NULL, "icon2.ico", IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE|LR_VGACOLOR);
			  if (!m_winvnc_icon)m_winvnc_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_WINVNC), IMAGE_ICON,
                        GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_VGACOLOR);
			 if (!m_flash_icon)m_flash_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_FLASH), IMAGE_ICON,
                        GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_VGACOLOR);
		  }
		 }
	else
		 {
				m_winvnc_icon=(HICON)LoadImage(NULL, "icon1.ico", IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE|LR_VGACOLOR);
				m_flash_icon=(HICON)LoadImage(NULL, "icon2.ico", IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE|LR_VGACOLOR);
				if (!m_winvnc_icon)m_winvnc_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_WINVNC), IMAGE_ICON,
                        GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_VGACOLOR);
				if (!m_flash_icon)m_flash_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_FLASH), IMAGE_ICON,
                        GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_VGACOLOR);
		  }
	}

	// Load the popup menu
	m_hmenu = LoadMenu(hAppInstance, MAKEINTRESOURCE(IDR_TRAYMENU));

	// Install the tray icon!
	AddTrayIcon();
}
Exemplo n.º 19
0
void upsMenu::Redraw()
{
   AddTrayIcon();
}
Exemplo n.º 20
0
// Implementation
upsMenu::upsMenu(HINSTANCE appinst, MonitorConfig &mcfg, BalloonMgr *balmgr,
                 InstanceManager *instmgr)
   : _statmgr(NULL),
     _about(appinst),
     _status(appinst, this),
     _events(appinst, this),
     _configdlg(appinst, instmgr),
     _wait(NULL),
     _thread(NULL),
     _hmenu(NULL),
     _hsubmenu(NULL),
     _upsname("<unknown>"),
     _balmgr(balmgr),
     _appinst(appinst),
     _hwnd(NULL),
     _config(mcfg),
     _runthread(true),
     _generation(0),
     _reconfig(true),
     _instmgr(instmgr)
{
   // Determine message id for "TaskbarCreate" message
   _tbcreated_msg = RegisterWindowMessage("TaskbarCreated");

   // Create a dummy window to handle tray icon messages
   WNDCLASSEX wndclass;
   wndclass.cbSize = sizeof(wndclass);
   wndclass.style = 0;
   wndclass.lpfnWndProc = upsMenu::WndProc;
   wndclass.cbClsExtra = 0;
   wndclass.cbWndExtra = 0;
   wndclass.hInstance = appinst;
   wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
   wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
   wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
   wndclass.lpszMenuName = (const char *)NULL;
   wndclass.lpszClassName = APCTRAY_WINDOW_CLASS;
   wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
   RegisterClassEx(&wndclass);

   // Make unique window title as 'host:port'.
   char title[1024];
   asnprintf(title, sizeof(title), "%s:%d", mcfg.host.str(), mcfg.port);

   // Create System Tray menu window
   _hwnd = CreateWindow(APCTRAY_WINDOW_CLASS, title, WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, NULL, NULL,
                         appinst, NULL);
   if (_hwnd == NULL) {
      PostQuitMessage(0);
      return;
   }

   // record which client created this window
   SetWindowLong(_hwnd, GWL_USERDATA, (LONG)this);

   // Load the icons for the tray
   _online_icon = LoadIcon(appinst, MAKEINTRESOURCE(IDI_ONLINE));
   _onbatt_icon = LoadIcon(appinst, MAKEINTRESOURCE(IDI_ONBATT));
   _charging_icon = LoadIcon(appinst, MAKEINTRESOURCE(IDI_CHARGING));
   _commlost_icon = LoadIcon(appinst, MAKEINTRESOURCE(IDI_COMMLOST));

   // Load the popup menu
   _hmenu = LoadMenu(appinst, MAKEINTRESOURCE(IDR_TRAYMENU));
   if (_hmenu == NULL) {
      PostQuitMessage(0);
      return;
   }
   _hsubmenu = GetSubMenu(_hmenu, 0);

   // Install the tray icon. Although it's tempting to let this happen
   // on the poll thread, we do it here so its synchronous and all icons
   // are consistently created in the same order.
   AddTrayIcon();

   // Create a semaphore to use for interruptible waiting
   _wait = CreateSemaphore(NULL, 0, 1, NULL);
   if (_wait == NULL) {
      PostQuitMessage(0);
      return;
   }

   // Thread to poll UPS status and update tray icon
   _thread = CreateThread(NULL, 0, &upsMenu::StatusPollThread, this, 0, NULL);
   if (_thread == NULL)
      PostQuitMessage(0);
}
Exemplo n.º 21
0
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标
	///工具栏创建
	
	m_imageList.Create(16,16,ILC_COLOR32|ILC_MASK,0,0);
	m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_LEFT));//0
	m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_MIDDLE));//1
	m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_RIGHT));//2
	m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_TOP));//6
	m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_BOTTOM));//7
	m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_WIDTH));//3
	m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_HEIGHT));//4
	m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_SAMESIZE));//5
	m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_HORI));//8
	m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_VERI));//9

	UINT btnIDs[12]; 
	btnIDs[0]=IDI_ICON_LEFT;
	btnIDs[1]=IDI_ICON_MIDDLE;
	btnIDs[2]=IDI_ICON_RIGHT;
	btnIDs[3]=IDI_ICON_TOP;
	btnIDs[4]=IDI_ICON_BOTTOM;
	btnIDs[5]=ID_SEPARATOR;
	btnIDs[6]=IDI_ICON_WIDTH;
	btnIDs[7]=IDI_ICON_HEIGHT;
	btnIDs[8]=IDI_ICON_SAMESIZE;
	btnIDs[9]=ID_SEPARATOR;
	btnIDs[10]=IDI_ICON_HORI;
	btnIDs[11]=IDI_ICON_VERI;

	m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_NOALIGN
		| CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
	m_wndToolBar.SetButtons(btnIDs,12);
	m_wndToolBar.SetButtonText(0,toolLeftText);
	m_wndToolBar.SetButtonText(1,toolMiddleText);
	m_wndToolBar.SetButtonText(2,toolRightText);
	m_wndToolBar.SetButtonText(3,toolTopText);
	m_wndToolBar.SetButtonText(4,toolBottomText);
	m_wndToolBar.SetButtonText(6,toolWidthText);
	m_wndToolBar.SetButtonText(7,toolHeightText);
	m_wndToolBar.SetButtonText(8,toolSameSizeText);
	m_wndToolBar.SetButtonText(10,toolHorText);
	m_wndToolBar.SetButtonText(11,toolVerText);
	
	m_wndToolBar.GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
	/*
	TBMETRICS tbmer;
	tbmer.cbSize=sizeof(TBMETRICS);
	tbmer.dwMask=TBMF_BUTTONSPACING;
	tbmer.cxButtonSpacing=5;//设置间隔
	m_wndToolBar.GetToolBarCtrl().SetMetrics(&tbmer);
	*/
	m_wndToolBar.GetToolBarCtrl().SetImageList(&m_imageList);
	CRect temp;
	m_wndToolBar.GetItemRect(0,&temp);
	m_wndToolBar.SetSizes(CSize(temp.Width(),temp.Height()),CSize(16,16));   
	//Make the toolbar dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_TOP);
	EnableDocking(CBRS_ALIGN_TOP);
	DockControlBar(&m_wndToolBar);

	////////////////////////////去掉默认菜单栏
	SetMenu(NULL);
	DestroyMenu(m_hMenuDefault);
	///////////////////////////
	LONG style=::GetWindowLong(this->m_hWnd,GWL_STYLE);//取消标题栏
	style &= ~WS_CAPTION;
	SetWindowLong(m_hWnd,GWL_STYLE,style);

	
	
//	GetWindowPlacement(&m_oldWindowPlaceMent);
	

//	FullScreen();
	///////////////////////////////////////
	theApp.ReadLogicVariablesFromFile();

	SetTimer(AUTOSHUTDOWN,1000,NULL);
	///////////////////////
	DeleteLogFile();
	//////////////////////
	AddTrayIcon();
	///////////////
	return 0;
}
Exemplo n.º 22
0
MRESULT EXPENTRY windowproc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
HPS hps;
RECTL rcl;
DRAGITEM dit;
PDRAGINFO pdin;
HOBJECT hobj;
static a=0;

switch(msg)
{
/* control tray icon specific messages */
case DM_DROP:
pdin = (PDRAGINFO)mp1;
DrgAccessDraginfo(pdin);
DrgQueryDragitem(pdin,sizeof(DRAGITEM),&dit,0);
DrgQueryStrName(dit.hstrContainerName,256,cbuf);
DrgQueryStrName(dit.hstrSourceName,256,buf);
strcat(cbuf,buf);
hobj=WinQueryObject("<WP_DRIVES>");
if(hobj)DosBeep(1000,100);
//WinOpenObject(hobj,0,TRUE);
WinMessageBox(HWND_DESKTOP,hwnd,"Drag Succeed!",cbuf,0,MB_OK | MB_INFORMATION);
DrgFreeDraginfo(pdin);
break;
case DM_DRAGOVER:
return MPFROM2SHORT(DOR_DROP,DO_LINK);
case WM_TIMER:
a++;
a%=5;
WinSendMsg(hwndFrame,WM_SETICON,(MPARAM)hIcon[a],NULL);
ChangeTrayIcon(hwnd,NULLHANDLE);
break;
case WM_BUTTON1CLICK|0x2000:
case WM_BUTTON2CLICK|0x2000:
/* activate frame window */
WinSetWindowPos(hwndFrame,HWND_TOP,0,0,0,0,SWP_ACTIVATE | SWP_SHOW | SWP_ZORDER | SWP_RESTORE);
break;
case WM_CREATE:
/* initialize window */

/* initialize tray api */
InitializeTrayApi(hwnd);
break;

case WM_DDE_INITIATEACK:
/* aswer dde server */
AnswerTrayApiDdeAck(mp1);
AddTrayIcon(hwnd,WinSendMsg(hwndFrame,WM_QUERYICON,NULL,NULL));
WinStartTimer(hab,hwnd,1,500);

return (MRESULT)0L;

case WM_PAINT:
hps = WinBeginPaint(hwnd,NULL,NULL);
WinQueryWindowRect(hwnd, &rcl);
WinFillRect(hps, &rcl, CLR_CYAN);
GpiSetColor(hps, CLR_DARKBLUE);
GpiSetBackColor(hps, CLR_CYAN);
rcl.xLeft=(rcl.xLeft+rcl.xRight)/2-40;
rcl.yBottom=(rcl.yBottom+rcl.yTop)/2-7;
GpiCharStringAt(hps, (PPOINTL)&rcl, 13, "Hello, world!");
WinEndPaint(hps);
break;

case WM_DESTROY:
/* delete application icon from system tray */
return (MRESULT)DeleteTrayIcon(hwnd);
}

return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
Exemplo n.º 23
0
Daemon::Daemon(int port)
{

	// Create a dummy window
	WNDCLASSEX wndclass;

	wndclass.cbSize			= sizeof(wndclass);
	wndclass.style			= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
	wndclass.lpfnWndProc	= Daemon::WndProc;
	wndclass.cbClsExtra		= 0;
	wndclass.cbWndExtra		= 0;
	wndclass.hInstance		= pApp->m_instance;
	wndclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground	= (HBRUSH) GetStockObject(WHITE_BRUSH);
	wndclass.lpszMenuName	= (const char *) NULL;
	wndclass.lpszClassName	= DAEMON_CLASS_NAME;
	wndclass.hIconSm		= LoadIcon(NULL, IDI_APPLICATION);

	RegisterClassEx(&wndclass);

	m_hwnd = CreateWindow(DAEMON_CLASS_NAME,
				DAEMON_CLASS_NAME,
				WS_OVERLAPPEDWINDOW,
				CW_USEDEFAULT,
				CW_USEDEFAULT,
				200, 200,
				NULL,
				NULL,
				pApp->m_instance,
				NULL);
	
	// record which client created this window
    helper::SafeSetWindowUserData(m_hwnd, (LONG_PTR)this);

	// Load a popup menu
	m_hmenu = LoadMenu(pApp->m_instance, MAKEINTRESOURCE(IDR_TRAYMENU));

	// sf@2003 - Store Port number for systray display
	m_nPort = port;

	// Create a listening socket
    struct sockaddr_in addr;
	memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = INADDR_ANY;
    m_deamon_sock = socket(AF_INET, SOCK_STREAM, 0);
	if (!m_deamon_sock) throw WarningException(sz_I1);
    
	
    
	try {
		int res = 0;	
		res = bind(m_deamon_sock, (struct sockaddr *)&addr, sizeof(addr));
		if (res == SOCKET_ERROR)
			throw WarningException(sz_I2);
		
		res = listen(m_deamon_sock, 5);
		if (res == SOCKET_ERROR)
			throw WarningException(sz_I3);
	} catch (...) {
		closesocket(m_deamon_sock);
		m_deamon_sock = INVALID_SOCKET;
		throw;
	}
	
	// Send a message to specified window on an incoming connection
	WSAAsyncSelect (m_deamon_sock,  m_hwnd,  WM_SOCKEVENT, FD_ACCEPT);

	// Create the tray icon
	AddTrayIcon();
	
	// A timer checks that the tray icon is intact
	m_timer = SetTimer( m_hwnd, IDT_TRAYTIMER,  15000, NULL);
}
Exemplo n.º 24
0
BOOL FlipToTray(HWND hwnd) {

	if (g_cWti >= MAX_WNDTRAY)
		return(FALSE);
	if (!IsWindow(hwnd))
		return(FALSE);

	HWND hwndShell = GetShellWindow(), hwndTmp, hwndOwner;
	hwndTmp = hwndOwner = hwnd;
	do {
		hwndOwner = hwndTmp;
		hwndTmp = GetWindow(hwndTmp, GW_OWNER);
	} while (hwndTmp && hwndTmp != hwndShell);

	DWORD dw = GetWindowLongPtr(hwndOwner, GWL_STYLE);
	if (!(dw & WS_MINIMIZEBOX) || dw & WS_CHILD)
		return(FALSE);

	//SetForegroundWindow(g_hwndMain);
	//MySwitchToThisWindow(GetShellWindow());

	for (UINT i = 0; i < g_cWti; i++) {
		if (g_pWti[i].hwnd == hwndOwner) {
			if (IsWindowVisible(hwndOwner))
				_UnflipFromTray(i, 0);
			else return(FALSE);
		}
	}

	UINT uID = IDC_FIRSTTRAYICON;
	if (g_cWti > 0) {
		while (uID < IDC_FIRSTTRAYICON + MAX_WNDTRAY) {
			BOOL fIs1 = TRUE;
			for (UINT i = 0; i < g_cWti; i++) {
				if (g_pWti[i].uID == uID)
					fIs1 = FALSE;
			}
			if (fIs1) break;
			uID++;
		}
	}

	HICON hIcon, hIconSm;
	GetWindowIcons(hwndOwner, &hIcon, &hIconSm);

	WCHAR szCaption[MAX_CAPTION];
	InternalGetWindowText(hwndOwner, szCaption, MAX_CAPTION);
	if (szCaption[0] == L'\0' && hwnd != hwndOwner) {
		InternalGetWindowText(hwnd, szCaption, MAX_CAPTION);
	}

	if (MyIsHungAppWindow(hwndOwner))
		return(FALSE);

	RECT rcTray = { 0 };

	g_pWti[g_cWti].fAnimate = FALSE;

	if (!(dw & WS_MINIMIZE)) {

		GetWindowRect(hwnd, &g_pWti[g_cWti].rcWnd);
	
		ANIMATIONINFO ai;
		ai.cbSize = sizeof(ANIMATIONINFO);
		ai.iMinAnimate = FALSE;
		SystemParametersInfo(SPI_GETANIMATION, sizeof(ANIMATIONINFO), &ai, FALSE);

		if (ai.iMinAnimate) {
			HWND hwndTray = FindTrayToolbarWindow();
			if (hwndTray) {
				GetWindowRect(hwndTray, &rcTray);
				rcTray.bottom = rcTray.top;
				rcTray.right = rcTray.left;

				KillTimer(g_hwndMain, TIMER_SETANIMATION);
				g_pWti[g_cWti].fAnimate = TRUE;			
				ai.iMinAnimate = 0;
				SystemParametersInfo(SPI_SETANIMATION, sizeof(ANIMATIONINFO), &ai, FALSE);
				SetTimer(g_hwndMain, TIMER_SETANIMATION, 500, NULL);

				DrawAnimatedRects(g_hwndMain, IDANI_CAPTION, 
					&g_pWti[g_cWti].rcWnd, &rcTray);
			}
		}

		//ShowWindow(hwndOwner, SW_MINIMIZE);
		if (!SendMessageTimeout(hwndOwner, WM_SYSCOMMAND, SC_MINIMIZE, 0, 
			SMTO_ABORTIFHUNG, 500, &dw)) return(FALSE);
	}

	//ShowWindow(hwndOwner, SW_HIDE);
	SetWindowPos(hwndOwner, NULL, 0, 0, 0, 0, 
		SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_HIDEWINDOW);

	//if (g_pWti[g_cWti].fAnimate) {
	//}

	g_pWti[g_cWti].hwnd = hwndOwner;
	g_pWti[g_cWti].uID = uID;
	g_pWti[g_cWti].hIconSm = hIconSm;
	g_cWti++;
	AddTrayIcon(g_hwndMain, uID, hIconSm, szCaption);
	return(TRUE);
}
Exemplo n.º 25
0
Daemon::Daemon(int port)
{

	// Create a dummy window
	WNDCLASSEX wndclass;

	wndclass.cbSize			= sizeof(wndclass);
	wndclass.style			= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
	wndclass.lpfnWndProc	= Daemon::WndProc;
	wndclass.cbClsExtra		= 0;
	wndclass.cbWndExtra		= 0;
	wndclass.hInstance		= pApp->m_instance;
	wndclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground	= (HBRUSH) GetStockObject(WHITE_BRUSH);
	wndclass.lpszMenuName	= (const char *) NULL;
	wndclass.lpszClassName	= DAEMON_CLASS_NAME;
	wndclass.hIconSm		= LoadIcon(NULL, IDI_APPLICATION);

	RegisterClassEx(&wndclass);

	m_hwnd = CreateWindow(DAEMON_CLASS_NAME,
				DAEMON_CLASS_NAME,
				WS_OVERLAPPEDWINDOW,
				CW_USEDEFAULT,
				CW_USEDEFAULT,
				200, 200,
				NULL,
				NULL,
				pApp->m_instance,
				NULL);
	
	// record which client created this window
	SetWindowLong(m_hwnd, GWL_USERDATA, (LONG) this);

	// Load a popup menu
	m_hmenu = LoadMenu(pApp->m_instance, MAKEINTRESOURCE(IDR_TRAYMENU));

	// Create a listening socket
    struct sockaddr_in addr;

    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = INADDR_ANY;

    m_sock = socket(AF_INET, SOCK_STREAM, 0);
	if (!m_sock)
		throw WarningException("Error creating Daemon socket");

	int one = 1, res = 0;
	//res = setsockopt(m_sock, SOL_SOCKET, SO_REUSEADDR, (const char *) &one, sizeof(one));
	//if (res == SOCKET_ERROR)  {
	//	closesocket(m_sock);
	//	m_sock = 0;
	//	throw WarningException("Error setting Daemon socket options");
	//}

	res = bind(m_sock, (struct sockaddr *)&addr, sizeof(addr));
	if (res == SOCKET_ERROR) {
		closesocket(m_sock);
		m_sock = 0;
		throw WarningException("Error binding Daemon socket");
	}

	res = listen(m_sock, 5);
	if (res == SOCKET_ERROR) {
		closesocket(m_sock);
		m_sock = 0;
		throw WarningException("Error when Daemon listens");
	}

	// Send a message to specified window on an incoming connection
	WSAAsyncSelect (m_sock,  m_hwnd,  WM_SOCKEVENT, FD_ACCEPT);

	// Create the tray icon
	AddTrayIcon();

	// A timer checks that the tray icon is intact
	m_timer = SetTimer( m_hwnd, IDT_TRAYTIMER,  15000, NULL);
}
Exemplo n.º 26
0
vncMenu::vncMenu(vncServer *server)
{
	vnclog.Print(LL_INTERR, VNCLOG("vncmenu(server)\n"));
	hWTSDll = NULL;
	ports_set=false;
    CoInitialize(0);
	IsIconSet=false;
	IconFaultCounter=0;

	HMODULE hUser32 = LoadLibrary("user32.dll");
	CHANGEWINDOWMESSAGEFILTER pfnFilter = NULL;
	pfnFilter =(CHANGEWINDOWMESSAGEFILTER)GetProcAddress(hUser32,"ChangeWindowMessageFilter");
	if (pfnFilter) pfnFilter(MENU_ADD_CLIENT_MSG, MSGFLT_ADD);
	if (pfnFilter) pfnFilter(MENU_AUTO_RECONNECT_MSG, MSGFLT_ADD);
	if (pfnFilter) pfnFilter(MENU_REPEATER_ID_MSG, MSGFLT_ADD);
	// adzm 2009-07-05 - Tray icon balloon tips
	if (pfnFilter) pfnFilter(MENU_TRAYICON_BALLOON_MSG, MSGFLT_ADD);

    FreeLibrary (hUser32);
	
	// adzm 2009-07-05 - Tray icon balloon tips
	m_BalloonInfo = NULL;
	m_BalloonTitle = NULL;

	// Save the server pointer
	m_server = server;

	// Set the initial user name to something sensible...
	vncService::CurrentUser((char *)&m_username, sizeof(m_username));

	//if (strcmp(m_username, "") == 0)
	//	strcpy((char *)&m_username, "SYSTEM");
	//vnclog.Print(LL_INTERR, VNCLOG("########### vncMenu::vncMenu - UserName = %s\n"), m_username);

	// Create a dummy window to handle tray icon messages
	WNDCLASSEX wndclass;

	wndclass.cbSize			= sizeof(wndclass);
	wndclass.style			= 0;
	wndclass.lpfnWndProc	= vncMenu::WndProc;
	wndclass.cbClsExtra		= 0;
	wndclass.cbWndExtra		= 0;
	wndclass.hInstance		= hAppInstance;
	wndclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground	= (HBRUSH) GetStockObject(WHITE_BRUSH);
	wndclass.lpszMenuName	= (const char *) NULL;
	wndclass.lpszClassName	= MENU_CLASS_NAME;
	wndclass.hIconSm		= LoadIcon(NULL, IDI_APPLICATION);

	RegisterClassEx(&wndclass);

	m_hwnd = CreateWindow(MENU_CLASS_NAME,
				MENU_CLASS_NAME,
				WS_OVERLAPPEDWINDOW,
				CW_USEDEFAULT,
				CW_USEDEFAULT,
				200, 200,
				NULL,
				NULL,
				hAppInstance,
				NULL);
	if (m_hwnd == NULL)
	{
		PostQuitMessage(0);
		return;
	}

	if (!hWTSDll) hWTSDll = LoadLibrary( ("wtsapi32.dll") );
	if (hWTSDll)
	{
		WTSREGISTERSESSIONNOTIFICATION FunctionWTSRegisterSessionNotification;    
		FunctionWTSRegisterSessionNotification = (WTSREGISTERSESSIONNOTIFICATION)GetProcAddress((HINSTANCE)hWTSDll, "WTSRegisterSessionNotification" );
		if (FunctionWTSRegisterSessionNotification)
			FunctionWTSRegisterSessionNotification( m_hwnd, NOTIFY_FOR_THIS_SESSION );
	}

	// record which client created this window
    helper::SafeSetWindowUserData(m_hwnd, (LONG) this);

	// Ask the server object to notify us of stuff
	server->AddNotify(m_hwnd);

	// Initialise the properties dialog object
	if (!m_properties.Init(m_server))
	{
		PostQuitMessage(0);
		return;
	}
	if (!m_propertiesPoll.Init(m_server))
	{
		PostQuitMessage(0);
		return;
	}
	
	/* Does not work when vncMenu is created from imp_thread
	hEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, "Global\\SessionEvent");
	ResetEvent(hEvent);
	*/

	SetTimer(m_hwnd, 1, 5000, NULL);


	// sf@2002
	if (!m_ListDlg.Init(m_server))
	{
		PostQuitMessage(0);
		return;
	}

	// Load the icons for the tray
//	m_winvnc_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_WINVNC));
//	m_flash_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_FLASH));
	{
	osvi.dwOSVersionInfoSize = sizeof(osvi);
	GetVersionEx(&osvi);
/*if (osvi.dwPlatformId==VER_PLATFORM_WIN32_NT)
		{
		  if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion>=1)
		  {
			m_winvnc_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_WINVNC), IMAGE_ICON,
                        GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
			m_flash_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_FLASH), IMAGE_ICON,
                        GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
		  }
		  else
		 {
			  m_winvnc_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_WINVNC), IMAGE_ICON,
                        GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_VGACOLOR);
			m_flash_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_FLASH), IMAGE_ICON,
                        GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_VGACOLOR);
		  }
		 }
	else
		 {
			  m_winvnc_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_WINVNC), IMAGE_ICON,
                        GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_VGACOLOR);
			m_flash_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_FLASH), IMAGE_ICON,
                        GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_VGACOLOR);
		  }
	}*/

	if (osvi.dwPlatformId==VER_PLATFORM_WIN32_NT)
		{
		  if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion>=1)
		  {
			m_winvnc_icon=(HICON)LoadImage(NULL, "icon1.ico", IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE|LR_DEFAULTCOLOR);
			m_flash_icon=(HICON)LoadImage(NULL, "icon2.ico", IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE|LR_DEFAULTCOLOR);
			// [v1.0.2-jp1 fix]
			//if (!m_winvnc_icon) m_winvnc_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_WINVNC), IMAGE_ICON,
			if (!m_winvnc_icon) m_winvnc_icon=(HICON)LoadImage(hInstResDLL, MAKEINTRESOURCE(IDI_WINVNC), IMAGE_ICON,
                        GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
			// [v1.0.2-jp1 fix]
			//if (!m_flash_icon) m_flash_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_FLASH), IMAGE_ICON,
 			if (!m_flash_icon) m_flash_icon=(HICON)LoadImage(hInstResDLL, MAKEINTRESOURCE(IDI_FLASH), IMAGE_ICON,
                       GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
			
		  }
		  else
		 {
			  m_winvnc_icon=(HICON)LoadImage(NULL, "icon1.ico", IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE|LR_VGACOLOR);
				m_flash_icon=(HICON)LoadImage(NULL, "icon2.ico", IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE|LR_VGACOLOR);
				
			  // [v1.0.2-jp1 fix]
			  //if (!m_winvnc_icon)m_winvnc_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_WINVNC), IMAGE_ICON,
 			  if (!m_winvnc_icon)m_winvnc_icon=(HICON)LoadImage(hInstResDLL, MAKEINTRESOURCE(IDI_WINVNC), IMAGE_ICON,
                       GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_VGACOLOR);
			 // [v1.0.2-jp1 fix]
			 //if (!m_flash_icon)m_flash_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_FLASH), IMAGE_ICON,
 			 if (!m_flash_icon)m_flash_icon=(HICON)LoadImage(hInstResDLL, MAKEINTRESOURCE(IDI_FLASH), IMAGE_ICON,
                       GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_VGACOLOR);
			 
		  }
		 }
	else
		 {
				m_winvnc_icon=(HICON)LoadImage(NULL, "icon1.ico", IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE|LR_VGACOLOR);
				m_flash_icon=(HICON)LoadImage(NULL, "icon2.ico", IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE|LR_VGACOLOR);
				
				// [v1.0.2-jp1 fix]
				//if (!m_winvnc_icon)m_winvnc_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_WINVNC), IMAGE_ICON,
				if (!m_winvnc_icon)m_winvnc_icon=(HICON)LoadImage(hInstResDLL, MAKEINTRESOURCE(IDI_WINVNC), IMAGE_ICON,
                       GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_VGACOLOR);
				// [v1.0.2-jp1 fix]
				//if (!m_flash_icon)m_flash_icon=(HICON)LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_FLASH), IMAGE_ICON,
				if (!m_flash_icon)m_flash_icon=(HICON)LoadImage(hInstResDLL, MAKEINTRESOURCE(IDI_FLASH), IMAGE_ICON,
                        GetSystemMetrics(SM_CXSMICON),
                        GetSystemMetrics(SM_CYSMICON), LR_VGACOLOR);
				
		  }
	}

	// Load the popup menu
	// [v1.0.2-jp1 fix]
	//m_hmenu = LoadMenu(hAppInstance, MAKEINTRESOURCE(IDR_TRAYMENU));
	m_hmenu = LoadMenu(hInstResDLL, MAKEINTRESOURCE(IDR_TRAYMENU));

	// Install the tray icon!
	AddTrayIcon();
	CoUninitialize();
}