- add functionality to save .rdp files

- auto add file ip address to dialog
- fix various bugs

svn path=/trunk/; revision=30232
This commit is contained in:
Ged Murphy
2007-11-06 23:23:25 +00:00
parent 851285b465
commit e9648e85b4
3 changed files with 139 additions and 35 deletions
+58 -34
View File
@@ -84,7 +84,8 @@ typedef struct _INFO
HINSTANCE hInst;
extern char g_servername[];
void OnTabWndSelChange(PINFO pInfo)
static VOID
OnTabWndSelChange(PINFO pInfo)
{
switch (TabCtrl_GetCurSel(pInfo->hTab))
{
@@ -101,6 +102,7 @@ void OnTabWndSelChange(PINFO pInfo)
}
}
static VOID
FillServerAddesssCombo(PINFO pInfo)
{
@@ -185,6 +187,8 @@ FillServerAddesssCombo(PINFO pInfo)
static VOID
GeneralOnInit(PINFO pInfo)
{
LPWSTR lpText;
SetWindowPos(pInfo->hGeneralPage,
NULL,
15,
@@ -225,8 +229,15 @@ GeneralOnInit(PINFO pInfo)
FillServerAddesssCombo(pInfo);
/* add address */
//GetStringFromSettings(pInfo->pRdpSettings, L"full address");
/* add file address */
lpText = GetStringFromSettings(pInfo->pRdpSettings,
L"full address");
if (lpText)
{
SetDlgItemTextW(pInfo->hGeneralPage,
IDC_SERVERCOMBO,
lpText);
}
}
@@ -252,7 +263,7 @@ GeneralDlgProc(HWND hDlg,
switch(LOWORD(wParam))
{
case IDC_SAVE:
SaveRdpSettingsToFile(NULL, pInfo->pRdpSettings);
break;
}
@@ -276,7 +287,9 @@ GeneralDlgProc(HWND hDlg,
static PSETTINGS_ENTRY
GetPossibleSettings(IN LPCTSTR DeviceName, OUT DWORD* pSettingsCount, OUT PSETTINGS_ENTRY* CurrentSettings)
GetPossibleSettings(IN LPCTSTR DeviceName,
OUT DWORD* pSettingsCount,
OUT PSETTINGS_ENTRY* CurrentSettings)
{
DEVMODE devmode;
DWORD NbSettings = 0;
@@ -286,7 +299,6 @@ GetPossibleSettings(IN LPCTSTR DeviceName, OUT DWORD* pSettingsCount, OUT PSETTI
HDC hDC;
PSETTINGS_ENTRY Current;
DWORD bpp, xres, yres, checkbpp;
DWORD curDispFreq;
/* Get current settings */
*CurrentSettings = NULL;
@@ -304,15 +316,12 @@ GetPossibleSettings(IN LPCTSTR DeviceName, OUT DWORD* pSettingsCount, OUT PSETTI
if (!EnumDisplaySettingsEx(DeviceName, ENUM_CURRENT_SETTINGS, &devmode, dwFlags))
return NULL;
curDispFreq = devmode.dmDisplayFrequency;
while (EnumDisplaySettingsEx(DeviceName, iMode, &devmode, dwFlags))
{
if ((devmode.dmBitsPerPel==8 ||
devmode.dmBitsPerPel==16 ||
devmode.dmBitsPerPel==24 ||
devmode.dmBitsPerPel==32) &&
devmode.dmDisplayFrequency==curDispFreq)
if (devmode.dmBitsPerPel==8 ||
devmode.dmBitsPerPel==16 ||
devmode.dmBitsPerPel==24 ||
devmode.dmBitsPerPel==32)
{
checkbpp=1;
}
@@ -335,12 +344,12 @@ GetPossibleSettings(IN LPCTSTR DeviceName, OUT DWORD* pSettingsCount, OUT PSETTI
Current->dmPelsWidth = devmode.dmPelsWidth;
Current->dmPelsHeight = devmode.dmPelsHeight;
Current->dmBitsPerPel = devmode.dmBitsPerPel;
while (Next != NULL && (
Next->dmPelsWidth < Current->dmPelsWidth ||
(Next->dmPelsWidth == Current->dmPelsWidth && Next->dmPelsHeight < Current->dmPelsHeight) ||
(Next->dmPelsHeight == Current->dmPelsHeight &&
Next->dmPelsWidth == Current->dmPelsWidth &&
Next->dmBitsPerPel < Current->dmBitsPerPel )))
while (Next != NULL &&
(Next->dmPelsWidth < Current->dmPelsWidth ||
(Next->dmPelsWidth == Current->dmPelsWidth && Next->dmPelsHeight < Current->dmPelsHeight) ||
(Next->dmPelsHeight == Current->dmPelsHeight &&
Next->dmPelsWidth == Current->dmPelsWidth &&
Next->dmBitsPerPel < Current->dmBitsPerPel )))
{
Previous = Next;
Next = Next->Flink;
@@ -367,6 +376,7 @@ GetPossibleSettings(IN LPCTSTR DeviceName, OUT DWORD* pSettingsCount, OUT PSETTI
}
static BOOL
AddDisplayDevice(PINFO pInfo, PDISPLAY_DEVICE DisplayDevice)
{
PDISPLAY_DEVICE_ENTRY newEntry = NULL;
@@ -482,12 +492,20 @@ ByeBye:
return FALSE;
}
static VOID
OnResolutionChanged(PINFO pInfo, DWORD position)
{
TCHAR Buffer[64];
INT MaxSlider;
if (position == 4)
MaxSlider = SendDlgItemMessageW(pInfo->hDisplayPage,
IDC_GEOSLIDER,
TBM_GETRANGEMAX,
0,
0);
if (position == MaxSlider)
{
LoadString(hInst,
IDS_FULLSCREEN,
@@ -512,10 +530,10 @@ OnResolutionChanged(PINFO pInfo, DWORD position)
}
SendDlgItemMessage(pInfo->hDisplayPage,
IDC_SETTINGS_RESOLUTION_TEXT,
WM_SETTEXT,
0,
(LPARAM)Buffer);
IDC_SETTINGS_RESOLUTION_TEXT,
WM_SETTEXT,
0,
(LPARAM)Buffer);
}
@@ -529,6 +547,7 @@ FillResolutionsAndColors(PINFO pInfo)
DWORD index, i, num;
DWORD MaxBpp = 0;
UINT HighBpp;
DWORD width, height;
pInfo->CurrentDisplayDevice = pInfo->DisplayDeviceList; /* Update global variable */
@@ -619,18 +638,23 @@ FillResolutionsAndColors(PINFO pInfo)
(LPARAM)Buffer);
}
/* FIXME: read from file */
for (index = 0; index < pInfo->CurrentDisplayDevice->ResolutionsCount; index++)
width = GetIntegerFromSettings(pInfo->pRdpSettings, L"desktopwidth");
height = GetIntegerFromSettings(pInfo->pRdpSettings, L"desktopheight");
if (width && height)
{
if (pInfo->CurrentDisplayDevice->Resolutions[index].dmPelsWidth == pInfo->CurrentDisplayDevice->CurrentSettings->dmPelsWidth &&
pInfo->CurrentDisplayDevice->Resolutions[index].dmPelsHeight == pInfo->CurrentDisplayDevice->CurrentSettings->dmPelsHeight)
for (index = 0; index < pInfo->CurrentDisplayDevice->ResolutionsCount; index++)
{
SendDlgItemMessage(pInfo->hDisplayPage,
IDC_GEOSLIDER,
TBM_SETPOS,
TRUE,
index);
break;
if (pInfo->CurrentDisplayDevice->Resolutions[index].dmPelsWidth == width &&
pInfo->CurrentDisplayDevice->Resolutions[index].dmPelsHeight == height)
{
SendDlgItemMessage(pInfo->hDisplayPage,
IDC_GEOSLIDER,
TBM_SETPOS,
TRUE,
index);
break;
}
}
}
}
+80 -1
View File
@@ -74,9 +74,40 @@ GetStringFromSettings(PRDPSETTINGS pRdpSettings,
static BOOL
WriteRdpFile(HANDLE hFile,
PSETTINGS pSettings)
PRDPSETTINGS pRdpSettings)
{
WCHAR line[MAXKEY + MAXVALUE + 4];
DWORD BytesToWrite, BytesWritten;
BOOL bRet;
INT i;
for (i = 0; i < pRdpSettings->NumSettings; i++)
{
if (pRdpSettings->pSettings[i].Type == L'i')
{
_snwprintf(line, MAXKEY + MAXVALUE + 4, L"%s:i:%d\r\n",
pRdpSettings->pSettings[i].Key,
pRdpSettings->pSettings[i].Value.i);
}
else
{
_snwprintf(line, MAXKEY + MAXVALUE + 4, L"%s:s:%s\r\n",
pRdpSettings->pSettings[i].Key,
pRdpSettings->pSettings[i].Value.s);
}
BytesToWrite = wcslen(line) * sizeof(WCHAR);
bRet = WriteFile(hFile,
line,
BytesToWrite,
&BytesWritten,
NULL);
if (!bRet || BytesWritten == 0)
return FALSE;
}
return TRUE;
}
@@ -242,6 +273,54 @@ CloseRdpFile(HANDLE hFile)
}
BOOL
SaveRdpSettingsToFile(LPWSTR lpFile,
PRDPSETTINGS pRdpSettings)
{
WCHAR pszPath[MAX_PATH];
HANDLE hFile;
BOOL bRet = FALSE;
/* use default file */
if (lpFile == NULL)
{
HRESULT hr;
LPITEMIDLIST lpidl= NULL;
hr = SHGetFolderLocation(NULL,
CSIDL_PERSONAL,
NULL,
0,
&lpidl);
if (hr == S_OK)
{
if (SHGetPathFromIDListW(lpidl, pszPath))
{
wcscat(pszPath, L"\\Default.rdp");
lpFile = pszPath;
CoTaskMemFree(lpidl);
}
}
}
if (lpFile)
{
hFile = OpenRdpFile(lpFile, TRUE);
if (hFile)
{
if (WriteRdpFile(hFile, pRdpSettings))
{
bRet = TRUE;
}
CloseRdpFile(hFile);
}
}
return bRet;
}
PRDPSETTINGS
LoadRdpSettingsFromFile(LPWSTR lpFile)
{
+1
View File
@@ -19,5 +19,6 @@ typedef struct _RDPSETTINGS
PRDPSETTINGS LoadRdpSettingsFromFile(LPWSTR lpFile);
BOOL SaveRdpSettingsToFile(LPWSTR lpFile, PRDPSETTINGS pRdpSettings);
INT GetIntegerFromSettings(PRDPSETTINGS pSettings, LPWSTR lpValue);
LPWSTR GetStringFromSettings(PRDPSETTINGS pSettings, LPWSTR lpValue);