Exemplo n.º 1
0
    // This method is called immediately before entering the message loop.
    // It contains initialization code for the application.
    // Returns:
    // S_OK => Success. Continue with RunMessageLoop() and PostMessageLoop().
    // S_FALSE => Skip RunMessageLoop(), call PostMessageLoop().
    // error code => Failure. Skip both RunMessageLoop() and PostMessageLoop().
    HRESULT PreMessageLoop(int nShowCmd) throw()
    {
        HRESULT hr = __super::PreMessageLoop(nShowCmd);
        if (FAILED(hr))
        {
            return hr;
        }
        // Note: In this sample, we don't respond differently to different hr success codes.

        // Allow only one instance of the application.
        // the "| 0x01" activates the correct owned window of the previous instance's main window
		HWND hWnd = NULL;
		for (int wait = 0; wait < m_nRestarting; wait++) {
			hWnd = FindWindow(CMainWindow::GetWndClassInfo().m_wc.lpszClassName, NULL);
			if (hWnd && m_nRestarting > 1) {
				Sleep(1000);
			} else {
				break;
			}
		}
		//EnumWindows(EnumRhodesWindowsProc, (LPARAM)&hWnd);

		if (hWnd)
		{
			SetForegroundWindow( HWND( DWORD(hWnd) | 0x01 ) );
			return S_FALSE;
		}

        // Create the main application window
        m_appWindow.Create(NULL, CWindow::rcDefault, TEXT("Rhodes"));
        if (NULL == m_appWindow.m_hWnd)
        {
            return S_FALSE;
        }

        m_pServerHost = new CServerHost();
        // Starting local server
        m_pServerHost->Start(m_appWindow.m_hWnd);
        // Navigate to the "loading..." page
		m_appWindow.Navigate2(_T("about:blank"));
        // Show the main application window
        m_appWindow.ShowWindow(nShowCmd);

#if defined(_WIN32_WCE)
		// Register for changes in the number of network connections
		hr = RegistryNotifyWindow(SN_CONNECTIONSNETWORKCOUNT_ROOT,
			SN_CONNECTIONSNETWORKCOUNT_PATH, 
			SN_CONNECTIONSNETWORKCOUNT_VALUE, 
			m_appWindow.m_hWnd, 
			WM_CONNECTIONSNETWORKCOUNT, 
			0, 
			NULL, 
			&g_hNotify);
#endif
        return S_OK;
    }
void CNotifications::InitRegistryNotifications(HWND hWnd)
{
	HRESULT hr;

	for (int i = 0; i < MAXDWORDNOTIFICATION; i++) {
		hr = RegistryNotifyWindow(
			SN_DW[i].hKey, SN_DW[i].pszSubKey, SN_DW[i].pszValueName,
			hWnd, WM_REGISTRY, i,
			NULL, &dwHrNotify[i]);
	}
	for (int i = 0; i < MAXSTRINGNOTIFICATION; i++) {
		hr = RegistryNotifyWindow(
			SN_SZ[i].hKey, SN_SZ[i].pszSubKey, SN_SZ[i].pszValueName,
			hWnd, WM_REGISTRY, MAXDWORDNOTIFICATION + i,
			NULL, &szHrNotify[i]);
	}
	for (int i = 0; i < MAXFILETIMENOTIFICATION; i++) {
		hr = RegistryNotifyWindow(
			SN_FT[i].hKey, SN_FT[i].pszSubKey, SN_FT[i].pszValueName,
			hWnd, WM_REGISTRY, MAXDWORDNOTIFICATION + MAXSTRINGNOTIFICATION + i,
			NULL, &ftHrNotify[i]);
	}
}