/*****************************Public*Routine******************************\
 * SaveWindowPos
 *
 * Store the window position information in the registry
 *
\**************************************************************************/
BOOL
SaveWindowPos(
    HWND hwnd
    )
{
    WINDOWPLACEMENT wpl;

    HKEY hKey = GetAppKey(TRUE);
    if(!hKey)
    {
        return FALSE;
    }

    // Save the current size and position of the window to the registry
    //
    ZeroMemory(&wpl, sizeof(wpl));
    wpl.length = sizeof(wpl);
    GetWindowPlacement(hwnd, &wpl);

    RegSetValueEx(hKey, cszWindow, 0, REG_BINARY,
                 (LPBYTE)&wpl.rcNormalPosition,
                 sizeof(wpl.rcNormalPosition));

    RegCloseKey(hKey);
    return TRUE;
}
/******************************Public*Routine******************************\
* ProfileStringIn
*
\**************************************************************************/
UINT
ProfileStringIn(
    LPTSTR  szKey,
    LPTSTR  szDefault,
    LPTSTR  szProfileString,
    DWORD   cb
    )
{
    CheckPointer(szKey,0);
    CheckPointer(szDefault,0);
    CheckPointer(szProfileString,0);

    HKEY  hKey;
    DWORD dwType;

    if((hKey = GetAppKey(FALSE)) == 0)
    {
        StringCbCopy(szProfileString, cb, szDefault);
        return lstrlen(szProfileString);
    }

    if((RegQueryValueEx(hKey, szKey, NULL, &dwType, 
                       (LPBYTE)szProfileString, &cb) != ERROR_SUCCESS)
        || dwType != REG_SZ)
    {
        StringCbCopy(szProfileString, cb, szDefault);
        cb = lstrlen(szProfileString);
    }

    RegCloseKey(hKey);
    return cb;
}
Esempio n. 3
0
void CCommands::SetApplicationObject (IApplication * pApplication)
{
	// This function assumes pApplication has already been AddRef'd
	// for us, which CDSAddIn did in it's QueryInterface call
	// just before it called us.
	m_pApplication = pApplication;
	if (! m_pApplication)
		return;

	// Create Application event handlers
	XApplicationEventsObj::CreateInstance (&m_pApplicationEventsObj);
	if (! m_pApplicationEventsObj)
	{
		ReportInternalError ("XApplicationEventsObj::CreateInstance");
		return;
	}
	m_pApplicationEventsObj->AddRef ();
	m_pApplicationEventsObj->Connect (m_pApplication);
	m_pApplicationEventsObj->m_pCommands = this;

#ifdef NEVER
	// Create Debugger event handler
	CComPtr < IDispatch > pDebugger;
	if (SUCCEEDED (m_pApplication->get_Debugger (&pDebugger))
	    && pDebugger != NULL)
	{
		XDebuggerEventsObj::CreateInstance (&m_pDebuggerEventsObj);
		m_pDebuggerEventsObj->AddRef ();
		m_pDebuggerEventsObj->Connect (pDebugger);
		m_pDebuggerEventsObj->m_pCommands = this;
	}
#endif

	// Get settings from registry HKEY_CURRENT_USER\Software\Vim\VisVim
	HKEY hAppKey = GetAppKey ("Vim");
	if (hAppKey)
	{
		HKEY hSectionKey = GetSectionKey (hAppKey, "VisVim");
		if (hSectionKey)
		{
			g_bEnableVim = GetRegistryInt (hSectionKey, "EnableVim",
						       g_bEnableVim);
			g_bDevStudioEditor = GetRegistryInt(hSectionKey,"DevStudioEditor",
							    g_bDevStudioEditor);
			g_ChangeDir = GetRegistryInt (hSectionKey, "ChangeDir",
						      g_ChangeDir);
			RegCloseKey (hSectionKey);
		}
		RegCloseKey (hAppKey);
	}
}
BOOL
LoadWindowPos(
    LPRECT lprc
    )
{
    CheckPointer(lprc,FALSE);
    
    static RECT rcDefault = {0,0,CX_DEFAULT,CY_DEFAULT};
    RECT  rcScreen, rc;
    HKEY  hKey = GetAppKey(FALSE);

    // Read window placement from the registry.
    //
    *lprc = rcDefault;

    if(hKey)
    {
        DWORD cb = sizeof(rc);
        DWORD dwType;

        if(ERROR_SUCCESS == RegQueryValueEx(hKey, cszWindow, NULL, &dwType, (LPBYTE)&rc, &cb)
            && dwType == REG_BINARY && cb == sizeof(RECT))
        {
            *lprc = rc;
        }

        RegCloseKey(hKey);
    }

    // If we fail to get the working area (screen-tray), then assume
    // the screen is 640x480
    //
    if(! SystemParametersInfo(SPI_GETWORKAREA, 0, &rcScreen, FALSE))
    {
        rcScreen.top    = rcScreen.left = 0;
        rcScreen.right  = 640;
        rcScreen.bottom = 480;
    }

    // If the proposed window position is outside the screen,
    // use the default placement
    //
    if(! IntersectRect(&rc, &rcScreen, lprc))
    {
        *lprc = rcDefault;
    }

    return ! IsRectEmpty(lprc);
}
/******************************Public*Routine******************************\
* ProfileStringOut
*
\**************************************************************************/
void
ProfileStringOut(
    LPTSTR  szKey,
    LPTSTR  szProfileString
    )
{
    assert(szKey);
    assert(szProfileString);

    HKEY  hKey;

    hKey = GetAppKey(TRUE);
    if (hKey)
    {
        RegSetValueEx(hKey, szKey, 0, REG_SZ, (LPBYTE)szProfileString,
                      sizeof(TCHAR) * (lstrlen(szProfileString)+1));

        RegCloseKey(hKey);
    }
}