Exemple #1
0
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (!m_TrayIcon.Create(this, WM_ICON_NOTIFY, GUI_APP_CAPTION, theApp.LoadIcon(IDI_SMALL_PASS), IDR_MAINFRAME))
		return -1;

	theApp.SetTrayIcon();

	if(!m_TrayIcon.SetMenuDefaultItem(2,TRUE))
		return -1;
	
	DWORD dwFlags;
	if(InternetGetConnectedState(&dwFlags, 0))
		theApp.m_DownloadCommand.InitNetCommand();
	else
		SetTimer(1, 600000, NULL);

	if(!theApp.m_RegisterRequest.m_IsUploaded)
		SetTimer(2, 300000, NULL);

	// CG: The following line was added by the Splash Screen component.
	CSplashWnd::ShowSplashScreen(this);

	return 0;
}
Exemple #2
0
void CMainDlg::SetTrayIcon(int iWorkMode)
{
	if(iWorkMode == 255)
		iWorkMode = m_bWorkMode;

	if(iWorkMode == XF_PASS_ALL)
		m_TrayIcon.SetIcon(IDI_SMALL_PASS);
	else if(iWorkMode == XF_QUERY_ALL)
		m_TrayIcon.SetIcon(IDI_SMALL_QUERY);
	else if(iWorkMode == XF_DENY_ALL)
		m_TrayIcon.SetIcon(IDI_SMALL_DENY);
	else
		m_TrayIcon.SetIcon(IDI_SMALL_PASS);
}
Exemple #3
0
int CMainDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CPasseckDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_TrayIcon.Create(this, WM_ICON_NOTIFY, GUI_APP_CAPTION, theApp.LoadIcon(IDI_SMALL_PASS), IDR_MAINFRAME))
		return -1;

	if(!m_TrayIcon.SetMenuDefaultItem(0, TRUE))
		return -1;
	
	CSplashWnd::ShowSplashScreen(this);

	return 0;
}
Exemple #4
0
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;
   }

   // Create the tray icon
   TCHAR szHello[MAX_LOADSTRING];
   LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

	if (!TrayIcon.Create(hInstance,
						hWnd,                            // Parent window
						WM_ICON_NOTIFY,                  // Icon notify message to use
						szHello,                         // tooltip
						::LoadIcon(hInstance, (LPCTSTR)IDI_APPICON),
						IDR_POPUP_MENU))
		return FALSE;

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

   return TRUE;
}
Exemple #5
0
LRESULT CMainDlg::OnTrayNotification(WPARAM wParam, LPARAM lParam)
{
	if(wParam == IDR_MAINFRAME && 
		(lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN))
		SetTrayIcon();

	if(wParam == IDR_MAINFRAME 
		&& lParam == WM_RBUTTONUP
		&& theApp.m_dwSubWindowCount > 0)
		lParam = WM_LBUTTONDOWN;

	if(wParam == IDR_MAINFRAME && lParam == WM_LBUTTONDOWN)
	{
		if(m_MessageIndex != 0)
		{
			int tmpIndex = m_MessageIndex;
			m_MessageIndex = 0;
			AfxMessageBox(m_OnLine.GetInternet()->m_sMessage[tmpIndex], MB_ICONINFORMATION);
			m_OnLine.GetInternet()->m_sMessage[tmpIndex][0] = 0;
			SetTrayIcon();
			return 0;
		}

		lParam = WM_LBUTTONDBLCLK;
	}

    return m_TrayIcon.OnTrayNotification(wParam, lParam);
}
Exemple #6
0
void CMainDlg::OnAppExit() 
{
	m_TrayIcon.HideIcon();
	EndDialog(IDCANCEL);
	//theApp.ExitInstance();
	theApp.m_pMainDlg.DestroyWindow();
}
Exemple #7
0
DWORD WINAPI SplashIcon(LPVOID pVoid)
{
	m_IsSplash = TRUE;

	for(int i = 0; i < 3; i++)
	{
		m_TrayIcon.SetIcon(IDI_SMALL_ALERT);
		if(i == 2)
			continue;
		Sleep(180);
		m_TrayIcon.SetIcon(IDI_SMALL_NULL);
		Sleep(400);
	}
	
	m_IsSplash = FALSE;

	return 0;
}
Exemple #8
0
DWORD WINAPI CMainDlg::SplashIcon(LPVOID pVoid)
{
	CMainDlg* pMainDlg = (CMainDlg*)pVoid;
	pMainDlg->SetSplash(TRUE);

	for(int i = 0; i < 3; i++)
	{
		m_TrayIcon.SetIcon(IDI_SMALL_ALERT);
		if(i == 2)
			continue;
		Sleep(180);
		m_TrayIcon.SetIcon(IDI_SMALL_NULL);
		Sleep(400);
	}
	
	pMainDlg->SetSplash(FALSE);

	return 0;
}
Exemple #9
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;

	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	InitCtrls.dwICC = ICC_STANDARD_CLASSES;
	InitCommonControlsEx(&InitCtrls);

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

	hWnd = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_COMPOSITED, szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
	//hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
	hWndMain = hWnd;

	if (!hWnd)
	{
		return FALSE;
	}

	// Create the tray icon
	if (!TrayIcon.Create(hInstance,
		hWnd,                            // Parent window
		WM_ICON_NOTIFY,                  // Icon notify message to use
		_T("dhcpsv"),  // tooltip
		::LoadIcon(hInstance, (LPCTSTR)IDI_DHCPSVGUI),
		IDC_DHCPSVGUI)) 
		return FALSE;

	TrayIcon.SetIconList(IDI_ICON_GREEN, IDI_ICON_RED);

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

	return TRUE;
}
Exemple #10
0
DWORD WINAPI SplashMessage(LPVOID pVoid)
{
	for(int i = 0; i < MAX_NET_COMMAND; i++)
	{
		if(theApp.m_sMessage[i][0] != '\0')
		{
			m_MessageIndex = i;

			m_IsSplash = TRUE;
			while(m_MessageIndex)
			{
				m_TrayIcon.SetIcon(IDI_SMALL_MESSAGE);
				Sleep(180);
				m_TrayIcon.SetIcon(IDI_SMALL_NULL);
				Sleep(400);
			}
			theApp.SetTrayIcon();
			m_IsSplash = FALSE;
		}
	}
	
	ODS("Exit Thread SplashMessage...");
	return 0;
}
Exemple #11
0
DWORD WINAPI CMainDlg::SplashMessage(LPVOID pVoid)
{
	CMainDlg* pMainDlg = (CMainDlg*)pVoid;
	for(int i = 0; i < MAX_NET_COMMAND; i++)
	{
		if(pMainDlg->GetOnLine()->GetInternet()->m_sMessage[i][0] != 0)
		{
			pMainDlg->SetMessageIndex(i);

			pMainDlg->SetSplash(TRUE);
			while(pMainDlg->GetMessageIndex())
			{
				m_TrayIcon.SetIcon(IDI_SMALL_MESSAGE);
				Sleep(180);
				m_TrayIcon.SetIcon(IDI_SMALL_NULL);
				Sleep(400);
			}
			pMainDlg->SetSplash(FALSE);
		}
	}
	
	ODS("Exit Thread SplashMessage...");
	return 0;
}
Exemple #12
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;
	TCHAR szHello[MAX_LOADSTRING];
	LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

	switch (message)
	{
        case WM_ICON_NOTIFY:
            return TrayIcon.OnTrayNotification(wParam, lParam);

		case WM_COMMAND:
			wmId    = LOWORD(wParam);
			wmEvent = HIWORD(wParam);
			// Parse the menu selections:
			switch (wmId)
			{
				case IDM_ABOUT:
				   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
				   break;
				case IDM_EXIT:
				   DestroyWindow(hWnd);
				   break;
				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			// TODO: Add any drawing code here...
			RECT rt;
			GetClientRect(hWnd, &rt);
			DrawText(hdc, szHello, strlen(szHello), &rt, DT_VCENTER | DT_CENTER | DT_SINGLELINE |DT_WORDBREAK);
			EndPaint(hWnd, &ps);
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}
Exemple #13
0
LRESULT CMainFrame::OnTrayNotification(WPARAM wParam, LPARAM lParam)
{
	if(wParam == IDR_MAINFRAME && lParam == WM_LBUTTONDOWN)
	{
		if(m_MessageIndex != 0)
		{
			int tmpIndex = m_MessageIndex;
			m_MessageIndex = 0;
			AfxMessageBox(theApp.m_sMessage[tmpIndex], MB_ICONINFORMATION);
			return 0;
		}

		lParam = WM_LBUTTONDBLCLK;
	}

    return m_TrayIcon.OnTrayNotification(wParam, lParam);
}
// This is the global (static) callback function for all TrayIcon windows
LRESULT PASCAL CSystemTray::WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    // The option here is to maintain a list of all TrayIcon windows,
    // and iterate through them. If you do this, remove these 3 lines.
    CSystemTray* pTrayIcon = m_pThis;
    if (pTrayIcon->GetSafeHwnd() != hWnd)
        return ::DefWindowProc(hWnd, message, wParam, lParam);

    // If maintaining a list of TrayIcon windows, then the following...
    // pTrayIcon = GetFirstTrayIcon()
    // while (pTrayIcon != NULL)
    // {
    //    if (pTrayIcon->GetSafeHwnd() != hWnd) continue;

          // Taskbar has been recreated - all TrayIcons must process this.
          if (message == CSystemTray::m_nTaskbarCreatedMsg)
              return pTrayIcon->OnTaskbarCreated(wParam, lParam);

          // Animation timer
          if (message == WM_TIMER && wParam == pTrayIcon->GetTimerID())
              return pTrayIcon->OnTimer(wParam);

          // Settings changed
          if (message == WM_SETTINGCHANGE && wParam == pTrayIcon->GetTimerID())
              return pTrayIcon->OnSettingChange(wParam, (LPCTSTR) lParam);

          // Is the message from the icon for this TrayIcon?
          if (message == pTrayIcon->GetCallbackMessage())
              return pTrayIcon->OnTrayNotification(wParam, lParam);

    //    pTrayIcon = GetNextTrayIcon();
    // }

    // Message has not been processed, so default.
    return ::DefWindowProc(hWnd, message, wParam, lParam);
}
Exemple #15
0
void NetThread::Run()
{
    g_receive_buffer = new (std::nothrow)ReceiveBuffer();
    g_send_buffer = new (std::nothrow)SendBuffer();

    WSAEVENT event_array[1];
    g_connect_event = WSACreateEvent();
    if(WSA_INVALID_EVENT == g_connect_event)
    {
        Log::Error("Create WSAEVENT failed %d", GetLastError());
    }
CONNECTTOSERVER:
    g_TrayIcon.SetIcon(IDI_ICONRED);
    g_TrayIcon.SetTooltipText((LPCTSTR)"Toast agent disconnected!");
    g_connect_sock = ConnectToServer(serverhost.c_str(), serverport.c_str());
    if(!IsRequestStop()&&g_connect_sock != -1)
    {
        SetIsConnected(1);
        WSAEventSelect(g_connect_sock, g_connect_event, FD_READ|FD_WRITE|FD_CLOSE);
        event_array[0] = g_connect_event;
        AgentSystemInfo info;
        GetAgentInfo(&info);
        SendAgentInfo(info);
    }
    else
    {
        Log::Info("Request exist or error, socket fd is -1");
        return;
    }
    g_TrayIcon.SetIcon(IDI_ICONGREEN);
    g_TrayIcon.SetTooltipText((LPCTSTR)"Toast agent connected!");

    while(!IsRequestStop())
    {
        DWORD Index;

        Index = WSAWaitForMultipleEvents(1, event_array, FALSE, 1000, FALSE);
        if(Index == WSA_WAIT_FAILED)
        {
            Log::Error("WSAWaitForMultipleEvents error: %d", WSAGetLastError());
            continue;
            // error occure
        }
        if(Index == WSA_WAIT_TIMEOUT)
        {
            int res = SendProcessing(g_connect_sock, g_send_buffer);
            if(res == 1)
            {
                ClearWrite();
            }
            else if(res == -1) // some error occur, may be server is closed
            {
                ClearWrite();
                Log::Debug("Send data error");
                CloseConnectionToServer(g_connect_sock);
                goto CONNECTTOSERVER;
            }
            // ok we send data
        }
        else
        {
            Index = Index - WSA_WAIT_EVENT_0;
            WSANETWORKEVENTS network_event;
            if(0==WSAEnumNetworkEvents(g_connect_sock, g_connect_event, &network_event))
            {
                if(network_event.lNetworkEvents&FD_READ)
                {
                    if(network_event.iErrorCode[FD_READ_BIT] != 0)
                    {
                        // read error
                        // close connection and
                        Log::Error("WSAEnumNetworkEvents read error: %d", WSAGetLastError());
                        CloseConnectionToServer(g_connect_sock);
                        goto CONNECTTOSERVER;
                    }
                    else
                    {
                        // ok we receive data
                        int res = ReceiveProcessing(g_connect_sock, g_receive_buffer);
                        if(0 == res || -1 == res)
                        {
                            Log::Debug("Server close or error %d ", res);
                            CloseConnectionToServer(g_connect_sock);
                            goto CONNECTTOSERVER;
                        }
                    }
                }
                if(network_event.lNetworkEvents&FD_WRITE)
                {
                    if(network_event.iErrorCode[FD_WRITE_BIT] != 0)
                    {
                        // network error
                        Log::Error("WSAEnumNetworkEvents Write error: %d", WSAGetLastError());
                        CloseConnectionToServer(g_connect_sock);
                        goto CONNECTTOSERVER;
                    }
                    int res = SendProcessing(g_connect_sock, g_send_buffer);
                    if(res == 1)
                    {
                        ClearWrite();
                    }
                    else if(res == -1) // some error occur, may be server is closed
                    {
                        ClearWrite();
                        Log::Debug("Send data error");
                        CloseConnectionToServer(g_connect_sock);
                        goto CONNECTTOSERVER;
                    }
                    // ok we send data
                }
                if(network_event.lNetworkEvents&FD_CLOSE)
                {
                    Log::Error("WSAEnumNetworkEvents connection closed error: %d", WSAGetLastError());
                    CloseConnectionToServer(g_connect_sock);
                    goto CONNECTTOSERVER;
                }
            }
            else
            {
                // error occureWSAGetLastError
                CloseConnectionToServer(g_connect_sock);
                goto CONNECTTOSERVER;
            }
        }
    }

    CloseConnectionToServer(g_connect_sock);
}