Ejemplo n.º 1
0
void TrayIcon::RestoreWindowFromTray(bool abIconOnly /*= false*/, bool abDontCallShowWindow /*= false*/)
{
	if (!abIconOnly)
	{
		gpConEmu->SetWindowMode(gpConEmu->GetWindowMode());

		if (!abDontCallShowWindow && !IsWindowVisible(ghWnd))
		{
			gpConEmu->ShowWindow(SW_SHOW);
		}

		apiSetForegroundWindow(ghWnd);
	}

	if (IsWindowVisible(ghWnd))
	{
		//EnableMenuItem(GetSystemMenu(ghWnd, false), ID_TOTRAY, MF_BYCOMMAND | MF_ENABLED);
		HMENU hMenu = gpConEmu->mp_Menu->GetSysMenu(/*ghWnd, false*/);
		SetMenuItemText(hMenu, ID_TOTRAY, TRAY_ITEM_HIDE_NAME);
	}

	//for (int i = 0; i < countof(mn_SysItemId); i++)
	//{
	//	EnableMenuItem(hMenu, mn_SysItemId[i], MF_BYCOMMAND | mn_SysItemState[i]);
	//}

	if (!gpSet->isAlwaysShowTrayIcon)
		RemoveTrayIcon();
	else
		UpdateTitle();
}
Ejemplo n.º 2
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);
	}
}
Ejemplo n.º 3
0
Daemon::~Daemon()
{
	KillTimer(m_hwnd, m_timer);
	RemoveTrayIcon();
	DestroyMenu(m_hmenu);
	if (m_deamon_sock != INVALID_SOCKET) shutdown(m_deamon_sock, SD_BOTH);
	if (m_deamon_sock != INVALID_SOCKET) closesocket(m_deamon_sock);
}
Ejemplo n.º 4
0
Daemon::~Daemon()
{
	KillTimer(m_hwnd, m_timer);
	RemoveTrayIcon();
	DestroyMenu(m_hmenu);
	if (m_sock!=NULL) shutdown(m_sock, SD_BOTH);
	if (m_sock!=NULL) closesocket(m_sock);
}
Ejemplo n.º 5
0
void DoCleanup()
{
	pKillVentHook();
	SaveSettings();
	RemoveTrayIcon();
	DestroyMenu(hMenu);
	FreeLibrary(hinstDLL);
	CloseHandle(hThreadVent);
}
Ejemplo n.º 6
0
	void CTaskTrayManager::Finalize()
	{
		if (m_fShowTrayIcon)
			RemoveTrayIcon();

		m_hwnd=nullptr;
		m_Message=0;
		m_hIcon=nullptr;
	}
Ejemplo n.º 7
0
LRESULT
CMainWindow::OnDestroy()
{
    RemoveTrayIcon();

    /* Clear the user data pointer */
    SetWindowLongPtr(m_hMainWnd, GWLP_USERDATA, 0);

    /* Break the message loop */
    PostQuitMessage(0);

    return 0;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
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);
	}
}
Ejemplo n.º 10
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);
	//}
}
Ejemplo n.º 11
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);
	}
Ejemplo n.º 12
0
BOOL CMainFrame::DestroyWindow()
{
	// TODO: 在此添加专用代码和/或调用基类
	RemoveTrayIcon();
	return CFrameWnd::DestroyWindow();
}