Beispiel #1
0
static BOOL QueryBool(HKEY hKey, LPCTSTR pszValueName, BOOL *pbResult)
{
    DWORD dwResult;
    if (!QueryDword(hKey, pszValueName, &dwResult))
        return FALSE;
    *pbResult = dwResult ? TRUE : FALSE;
    return TRUE;
}
Beispiel #2
0
void LoadSettings(void)
{
	HKEY hKey = NULL;
	HFONT hFont;
	DWORD dwPointSize = 0;
	INT base_length, dx, dy;

	base_length = (GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN))?
		GetSystemMetrics(SM_CYSCREEN) : GetSystemMetrics(SM_CXSCREEN);

	dx = (INT)(base_length * .95);
	dy = dx * 3 / 4;
	SetRect( &Globals.main_rect, 0, 0, dx, dy );

	if (RegOpenKey(HKEY_CURRENT_USER, s_szRegistryKey, &hKey) == ERROR_SUCCESS)
	{
		QueryByte(hKey,     _T("lfCharSet"),        &Globals.lfFont.lfCharSet);
		QueryByte(hKey,     _T("lfClipPrecision"),  &Globals.lfFont.lfClipPrecision);
		QueryDword(hKey,    _T("lfEscapement"),     (DWORD*)&Globals.lfFont.lfEscapement);
		QueryString(hKey,   _T("lfFaceName"),       Globals.lfFont.lfFaceName, sizeof(Globals.lfFont.lfFaceName) / sizeof(Globals.lfFont.lfFaceName[0]));
		QueryByte(hKey,     _T("lfItalic"),         &Globals.lfFont.lfItalic);
		QueryDword(hKey,    _T("lfOrientation"),    (DWORD*)&Globals.lfFont.lfOrientation);
		QueryByte(hKey,     _T("lfOutPrecision"),   &Globals.lfFont.lfOutPrecision);
		QueryByte(hKey,     _T("lfPitchAndFamily"), &Globals.lfFont.lfPitchAndFamily);
		QueryByte(hKey,     _T("lfQuality"),        &Globals.lfFont.lfQuality);
		QueryByte(hKey,     _T("lfStrikeOut"),      &Globals.lfFont.lfStrikeOut);
		QueryByte(hKey,     _T("lfUnderline"),      &Globals.lfFont.lfUnderline);
		QueryDword(hKey,    _T("lfWeight"),         (DWORD*)&Globals.lfFont.lfWeight);
		QueryDword(hKey,    _T("iPointSize"),       &dwPointSize);
		QueryBool(hKey,     _T("fWrap"),            &Globals.bWrapLongLines);
		QueryBool(hKey,     _T("fStatusBar"),       &Globals.bShowStatusBar);

		QueryDword(hKey,    _T("iWindowPosX"),      (DWORD*)&Globals.main_rect.left);
		QueryDword(hKey,    _T("iWindowPosY"),      (DWORD*)&Globals.main_rect.top);
		QueryDword(hKey,    _T("iWindowPosDX"),     (DWORD*)&dx);
		QueryDword(hKey,    _T("iWindowPosDY"),     (DWORD*)&dy);

        Globals.main_rect.right = Globals.main_rect.left + dx;
        Globals.main_rect.bottom = Globals.main_rect.top + dy;

		Globals.bShowStatusBar = !Globals.bShowStatusBar; /* invert value becuase DIALOG_ViewStatusBar will be called to show it*/

		if (dwPointSize != 0)
			Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize);

		RegCloseKey(hKey);
	}

	hFont = CreateFontIndirect(&Globals.lfFont);
	if (hFont)
	{
		if (Globals.hFont)
			DeleteObject(Globals.hFont);
		Globals.hFont = hFont;
	}
}
Beispiel #3
0
/***********************************************************************
 *
 *           NOTEPAD_LoadSettingsFromRegistry
 *
 *  Load settings from registry HKCU\Software\Microsoft\Notepad.
 */
void NOTEPAD_LoadSettingsFromRegistry(void)
{
    HKEY hKey = NULL;
    HFONT hFont;
    DWORD dwPointSize = 0;
    INT base_length, dx, dy;

    base_length = (GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN)) ?
                  GetSystemMetrics(SM_CYSCREEN) : GetSystemMetrics(SM_CXSCREEN);

    dx = (INT)(base_length * .95);
    dy = dx * 3 / 4;
    SetRect(&Globals.main_rect, 0, 0, dx, dy);

    if (RegOpenKey(HKEY_CURRENT_USER, s_szRegistryKey, &hKey) == ERROR_SUCCESS)
    {
        QueryByte(hKey, _T("lfCharSet"), &Globals.lfFont.lfCharSet);
        QueryByte(hKey, _T("lfClipPrecision"), &Globals.lfFont.lfClipPrecision);
        QueryDword(hKey, _T("lfEscapement"), (DWORD*)&Globals.lfFont.lfEscapement);
        QueryString(hKey, _T("lfFaceName"), Globals.lfFont.lfFaceName, ARRAY_SIZE(Globals.lfFont.lfFaceName));
        QueryByte(hKey, _T("lfItalic"), &Globals.lfFont.lfItalic);
        QueryDword(hKey, _T("lfOrientation"), (DWORD*)&Globals.lfFont.lfOrientation);
        QueryByte(hKey, _T("lfOutPrecision"), &Globals.lfFont.lfOutPrecision);
        QueryByte(hKey, _T("lfPitchAndFamily"), &Globals.lfFont.lfPitchAndFamily);
        QueryByte(hKey, _T("lfQuality"), &Globals.lfFont.lfQuality);
        QueryByte(hKey, _T("lfStrikeOut"), &Globals.lfFont.lfStrikeOut);
        QueryByte(hKey, _T("lfUnderline"), &Globals.lfFont.lfUnderline);
        QueryDword(hKey, _T("lfWeight"), (DWORD*)&Globals.lfFont.lfWeight);
        QueryDword(hKey, _T("iPointSize"), &dwPointSize);
        QueryBool(hKey, _T("fWrap"), &Globals.bWrapLongLines);
        QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar);
        QueryString(hKey, _T("szHeader"), Globals.szHeader, ARRAY_SIZE(Globals.szHeader));
        QueryString(hKey, _T("szTrailer"), Globals.szFooter, ARRAY_SIZE(Globals.szFooter));
        QueryDword(hKey, _T("iMarginLeft"), (DWORD*)&Globals.lMarginLeft);
        QueryDword(hKey, _T("iMarginTop"), (DWORD*)&Globals.lMarginTop);
        QueryDword(hKey, _T("iMarginRight"), (DWORD*)&Globals.lMarginRight);
        QueryDword(hKey, _T("iMarginBottom"), (DWORD*)&Globals.lMarginBottom);

        QueryDword(hKey, _T("iWindowPosX"), (DWORD*)&Globals.main_rect.left);
        QueryDword(hKey, _T("iWindowPosY"), (DWORD*)&Globals.main_rect.top);
        QueryDword(hKey, _T("iWindowPosDX"), (DWORD*)&dx);
        QueryDword(hKey, _T("iWindowPosDY"), (DWORD*)&dy);

        Globals.main_rect.right = Globals.main_rect.left + dx;
        Globals.main_rect.bottom = Globals.main_rect.top + dy;

        /* invert value because DIALOG_ViewStatusBar will be called to show it */
        Globals.bShowStatusBar = !Globals.bShowStatusBar;

        if (dwPointSize != 0)
            Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize);
        else
            Globals.lfFont.lfHeight = HeightFromPointSize(100);

        RegCloseKey(hKey);
    }
    else
    {
        /* If no settings are found in the registry, then use default values */
        Globals.lfFont.lfCharSet = 163;
        Globals.lfFont.lfClipPrecision = 2;
        Globals.lfFont.lfEscapement = 0;
        _tcscpy(Globals.lfFont.lfFaceName, _T("Arial"));
        Globals.lfFont.lfItalic = 0;
        Globals.lfFont.lfOrientation = 0;
        Globals.lfFont.lfOutPrecision = 3;
        Globals.lfFont.lfPitchAndFamily = 34;
        Globals.lfFont.lfQuality = 1;
        Globals.lfFont.lfStrikeOut = 0;
        Globals.lfFont.lfUnderline = 0;
        Globals.lfFont.lfWeight = 400;
        Globals.lfFont.lfHeight = HeightFromPointSize(100);
    }

    hFont = CreateFontIndirect(&Globals.lfFont);
    SendMessage(Globals.hEdit, WM_SETFONT, (WPARAM)hFont, (LPARAM)TRUE);
    if (hFont)
    {
        if (Globals.hFont)
            DeleteObject(Globals.hFont);
        Globals.hFont = hFont;
    }
}
Beispiel #4
0
BOOL CSettingsPage::OnInitDialog()
{
	int t;
	BYTE buf[_MAX_PATH*sizeof(TCHAR)];
	DWORD bufLen;
	DWORD dwType;
	CWaitCursor wait;

	CTooltipPropertyPage::OnInitDialog();

	SetDlgItemInt(IDC_PSERVERPORT,(t=QueryDword(_T("PServerPort")))>=0?t:2401,FALSE);
	bufLen=sizeof(buf);
	if(RegQueryValueEx(g_hServerKey,_T("LockServer"),NULL,&dwType,buf,&bufLen))
	{
		SetDlgItemText(IDC_LOCKSERVER,_T("localhost"));
		SetDlgItemInt(IDC_LOCKSERVERPORT,(t=QueryDword(_T("LockServerPort")))>=0?t:2402,FALSE);
	}
	else
	{
		RegDeleteValue(g_hServerKey,_T("LockServerPort"));
		TCHAR *p=_tcschr((TCHAR*)buf,':');
		if(p)
			*p='\0';
		m_edLockServer.SetWindowText((LPCTSTR)buf);
		SetDlgItemInt(IDC_LOCKSERVERPORT,p?_tstoi(p+1):2402,FALSE);
	}

	if(!RegQueryValueEx(g_hServerKey,_T("AnonymousUsername"),NULL,&dwType,buf,&bufLen))
		m_edAnonUser.SetWindowText((TCHAR*)buf);

	SendDlgItemMessage(IDC_PSERVERPORT,EM_LIMITTEXT,4);
	SendDlgItemMessage(IDC_LOCKSERVERPORT,EM_LIMITTEXT,4);

	m_sbServerPort.SetRange32(1,65535);
	m_sbLockPort.SetRange32(1,65535);

	bufLen=sizeof(buf);
	if(RegQueryValueEx(g_hServerKey,_T("TempDir"),NULL,&dwType,buf,&bufLen) &&
	   SHRegGetUSValue(_T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"),_T("TEMP"),NULL,(LPVOID)buf,&bufLen,TRUE,NULL,0) &&
	   !GetEnvironmentVariable(_T("TEMP"),(LPTSTR)buf,sizeof(buf)) &&
	   !GetEnvironmentVariable(_T("TMP"),(LPTSTR)buf,sizeof(buf)))
		{
			// Not set
			*buf='\0';
		}

	m_edTempDir.SetWindowText((LPCTSTR)buf);

	m_cbEncryption.ResetContent();
	m_cbEncryption.SetItemData(m_cbEncryption.AddString(_T("Optional")),0);
	m_cbEncryption.SetItemData(m_cbEncryption.AddString(_T("Request Authentication")),1);
	m_cbEncryption.SetItemData(m_cbEncryption.AddString(_T("Request Encryption")),2);
	m_cbEncryption.SetItemData(m_cbEncryption.AddString(_T("Require Authentication")),3);
	m_cbEncryption.SetItemData(m_cbEncryption.AddString(_T("Require Encryption")),4);
	m_cbCompression.ResetContent();
	m_cbCompression.SetItemData(m_cbCompression.AddString(_T("Optional")),0);
	m_cbCompression.SetItemData(m_cbCompression.AddString(_T("Request Compression")),1);
	m_cbCompression.SetItemData(m_cbCompression.AddString(_T("Require Compression")),2);

	m_cbEncryption.SetCurSel((t=QueryDword(_T("EncryptionLevel")))>=0?t:0);
	m_cbCompression.SetCurSel((t=QueryDword(_T("CompressionLevel")))>=0?t:0);

	/* Migrate the old setting */
	if((t=QueryDword(_T("DontUseDomain")))>=0)
	{
		if(t)
		{
			/* If dont use domain is set, force domain to computer name */
			/* The server will automatically pick up the domain otherwise */
			bufLen=sizeof(buf);
			GetComputerName((LPTSTR)buf,&bufLen);
			RegSetValueEx(g_hServerKey,_T("DefaultDomain"),0,REG_SZ,(BYTE*)buf,_tcslen((LPCTSTR)buf));
		}
		RegDeleteValue(g_hServerKey,_T("DontUseDomain"));
		if(g_bPrivileged)
			GetParent()->PostMessage(PSM_CHANGED, (WPARAM)m_hWnd); /* SetModified happens too early */
	}

	m_cbDefaultDomain.ResetContent();
	DWORD dwLen = sizeof(mw_computer)/sizeof(mw_computer[0]);

	m_cbDefaultDomain.AddString(_T("(default)"));

	GetComputerName(mw_computer,&dwLen);
	m_cbDefaultDomain.AddString(mw_computer);
	if(isDomainMember(mw_domain))
	{
		LPWSTR pw_pdc;
		m_cbDefaultDomain.AddString(mw_domain);
		if(!NetGetAnyDCName(NULL,mw_domain,(LPBYTE*)&pw_pdc) || !NetGetDCName(NULL,mw_domain,(LPBYTE*)&pw_pdc))
		{
			wcscpy(mw_pdc,pw_pdc);
			NetApiBufferFree(pw_pdc);
		}
	}

	CString szDefaultDomain = QueryString(_T("DefaultDomain"));
	int n = m_cbDefaultDomain.FindStringExact(-1,szDefaultDomain);
	m_cbDefaultDomain.SetCurSel(n>0?n:0);

	m_cbRunAsUser.ResetContent();
	m_cbRunAsUser.AddString(_T("(client user)"));
	CString usr = QueryString(_T("RunAsUser"));
	if(!usr.GetLength())
		m_cbRunAsUser.SetCurSel(0);
	else
		m_cbRunAsUser.SetCurSel(m_cbRunAsUser.AddString(usr));

	if(!g_bPrivileged)
	{
		m_edTempDir.EnableWindow(FALSE);
		m_edLockServer.EnableWindow(FALSE);
		m_cbEncryption.EnableWindow(FALSE);
		m_cbCompression.EnableWindow(FALSE);
		m_sbServerPort.EnableWindow(FALSE);
		m_sbLockPort.EnableWindow(FALSE);
		m_cbDefaultDomain.EnableWindow(FALSE);
		m_cbRunAsUser.EnableWindow(FALSE);
		m_edAnonUser.EnableWindow(FALSE);
		::EnableWindow(*GetDlgItem(IDC_CHANGETEMP),FALSE);
		::EnableWindow(*GetDlgItem(IDC_LOCKSERVERPORT),FALSE);
		::EnableWindow(*GetDlgItem(IDC_PSERVERPORT),FALSE);
	}

	return TRUE;
}