Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenconnectdialog.c
Go to the documentation of this file.
00001 /* 00002 rdesktop: A Remote Desktop Protocol client. 00003 Connection settings dialog 00004 Copyright (C) Ged Murphy 2007 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License along 00017 with this program; if not, write to the Free Software Foundation, Inc., 00018 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00019 */ 00020 00021 #include <precomp.h> 00022 00023 #define MAX_KEY_NAME 255 00024 00025 HINSTANCE hInst; 00026 00027 static VOID ReLoadGeneralPage(PINFO pInfo); 00028 static VOID ReLoadDisplayPage(PINFO pInfo); 00029 00030 static VOID 00031 DoOpenFile(PINFO pInfo) 00032 { 00033 OPENFILENAMEW ofn; 00034 WCHAR szFileName[MAX_PATH] = L""; 00035 static WCHAR szFilter[] = L"Remote Desktop Files (*rdp)\0*.rdp\0"; 00036 00037 ZeroMemory(&ofn, sizeof(ofn)); 00038 ofn.lStructSize = sizeof(OPENFILENAMEW); 00039 ofn.hwndOwner = pInfo->hGeneralPage; 00040 ofn.nMaxFile = MAX_PATH; 00041 ofn.nMaxFileTitle = MAX_PATH; 00042 ofn.lpstrDefExt = L"rdp"; 00043 ofn.lpstrFilter = szFilter; 00044 ofn.lpstrFile = szFileName; 00045 ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST; 00046 00047 if (GetOpenFileNameW(&ofn)) 00048 { 00049 LoadRdpSettingsFromFile(pInfo->pRdpSettings, szFileName); 00050 ReLoadGeneralPage(pInfo); 00051 ReLoadDisplayPage(pInfo); 00052 } 00053 } 00054 00055 00056 static VOID 00057 DoSaveAs(PINFO pInfo) 00058 { 00059 OPENFILENAMEW ofn; 00060 WCHAR szFileName[MAX_PATH] = L""; 00061 static WCHAR szFilter[] = L"Remote Desktop Files (*rdp)\0*.rdp\0"; 00062 00063 ZeroMemory(&ofn, sizeof(ofn)); 00064 ofn.lStructSize = sizeof(OPENFILENAMEW); 00065 ofn.hwndOwner = pInfo->hGeneralPage; 00066 ofn.nMaxFile = MAX_PATH; 00067 ofn.nMaxFileTitle = MAX_PATH; 00068 ofn.lpstrDefExt = L"rdp"; 00069 ofn.lpstrFilter = szFilter; 00070 ofn.lpstrFile = szFileName; 00071 ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT; 00072 00073 if (GetSaveFileNameW(&ofn)) 00074 { 00075 SaveAllSettings(pInfo); 00076 SaveRdpSettingsToFile(szFileName, pInfo->pRdpSettings); 00077 } 00078 } 00079 00080 00081 static VOID 00082 OnTabWndSelChange(PINFO pInfo) 00083 { 00084 switch (TabCtrl_GetCurSel(pInfo->hTab)) 00085 { 00086 case 0: //General 00087 ShowWindow(pInfo->hGeneralPage, SW_SHOW); 00088 ShowWindow(pInfo->hDisplayPage, SW_HIDE); 00089 BringWindowToTop(pInfo->hGeneralPage); 00090 break; 00091 case 1: //Display 00092 ShowWindow(pInfo->hGeneralPage, SW_HIDE); 00093 ShowWindow(pInfo->hDisplayPage, SW_SHOW); 00094 BringWindowToTop(pInfo->hDisplayPage); 00095 break; 00096 } 00097 } 00098 00099 00100 static VOID 00101 LoadUsernameHint(HWND hDlg, INT iCur) 00102 { 00103 WCHAR szValue[MAXVALUE+1000]; 00104 WCHAR szName[MAX_KEY_NAME]; 00105 WCHAR szKeyName[] = L"Software\\Microsoft\\Terminal Server Client\\Servers"; 00106 PWCHAR lpAddress; 00107 HKEY hKey; 00108 HKEY hSubKey; 00109 LONG lRet = ERROR_SUCCESS; 00110 INT iIndex = 0; 00111 DWORD dwSize = MAX_KEY_NAME; 00112 00113 SendDlgItemMessageW(hDlg, IDC_SERVERCOMBO, CB_GETLBTEXT, (WPARAM)iCur, (LPARAM)szValue); 00114 00115 /* remove possible port number */ 00116 lpAddress = wcstok(szValue, L":"); 00117 00118 if (lpAddress == NULL) 00119 return; 00120 00121 if (RegOpenKeyExW(HKEY_CURRENT_USER, 00122 szKeyName, 00123 0, 00124 KEY_READ, 00125 &hKey) == ERROR_SUCCESS) 00126 { 00127 while (lRet == ERROR_SUCCESS) 00128 { 00129 dwSize = MAX_KEY_NAME; 00130 00131 lRet = RegEnumKeyExW(hKey, iIndex, szName, &dwSize, NULL, NULL, NULL, NULL); 00132 00133 if(lRet == ERROR_SUCCESS && wcscmp(szName, lpAddress) == 0) 00134 { 00135 if(RegOpenKeyExW(hKey, szName, 0, KEY_READ, &hSubKey) != ERROR_SUCCESS) 00136 break; 00137 00138 dwSize = MAXVALUE; 00139 00140 if(RegQueryValueExW(hKey, L"UsernameHint", 0, NULL, (LPBYTE)szValue, &dwSize) == ERROR_SUCCESS) 00141 { 00142 SetDlgItemTextW(hDlg, IDC_NAMEEDIT, szValue); 00143 } 00144 00145 RegCloseKey(hSubKey); 00146 break; 00147 } 00148 iIndex++; 00149 } 00150 RegCloseKey(hKey); 00151 } 00152 } 00153 00154 00155 static VOID 00156 FillServerAddesssCombo(PINFO pInfo) 00157 { 00158 HKEY hKey; 00159 WCHAR KeyName[] = L"Software\\Microsoft\\Terminal Server Client\\Default"; 00160 WCHAR Name[MAX_KEY_NAME]; 00161 LONG ret = ERROR_SUCCESS; 00162 DWORD size; 00163 INT i = 0; 00164 BOOL found = FALSE; 00165 00166 if (RegOpenKeyExW(HKEY_CURRENT_USER, 00167 KeyName, 00168 0, 00169 KEY_READ, 00170 &hKey) == ERROR_SUCCESS) 00171 { 00172 while (ret == ERROR_SUCCESS) 00173 { 00174 size = MAX_KEY_NAME; 00175 ret = RegEnumValueW(hKey, 00176 i, 00177 Name, 00178 &size, 00179 NULL, 00180 NULL, 00181 NULL, 00182 NULL); 00183 if (ret == ERROR_SUCCESS) 00184 { 00185 size = MAX_KEY_NAME; 00186 if (RegQueryValueExW(hKey, 00187 Name, 00188 0, 00189 NULL, 00190 NULL, 00191 &size) == ERROR_SUCCESS) 00192 { 00193 LPWSTR lpAddress = HeapAlloc(GetProcessHeap(), 00194 0, 00195 size); 00196 if (lpAddress) 00197 { 00198 if (RegQueryValueExW(hKey, 00199 Name, 00200 0, 00201 NULL, 00202 (LPBYTE)lpAddress, 00203 &size) == ERROR_SUCCESS) 00204 { 00205 SendDlgItemMessageW(pInfo->hGeneralPage, 00206 IDC_SERVERCOMBO, 00207 CB_ADDSTRING, 00208 0, 00209 (LPARAM)lpAddress); 00210 found = TRUE; 00211 } 00212 00213 HeapFree(GetProcessHeap(), 00214 0, 00215 lpAddress); 00216 } 00217 } 00218 } 00219 00220 i++; 00221 } 00222 RegCloseKey(hKey); 00223 } 00224 00225 if (LoadStringW(hInst, 00226 IDS_BROWSESERVER, 00227 Name, 00228 sizeof(Name) / sizeof(WCHAR))) 00229 { 00230 SendDlgItemMessageW(pInfo->hGeneralPage, 00231 IDC_SERVERCOMBO, 00232 CB_ADDSTRING, 00233 0, 00234 (LPARAM)Name); 00235 } 00236 00237 if(found) 00238 { 00239 SendDlgItemMessageW(pInfo->hGeneralPage, 00240 IDC_SERVERCOMBO, 00241 CB_SETCURSEL, 00242 0, 00243 0); 00244 LoadUsernameHint(pInfo->hGeneralPage, 0); 00245 } 00246 00247 } 00248 00249 00250 static VOID 00251 ReLoadGeneralPage(PINFO pInfo) 00252 { 00253 LPWSTR lpText; 00254 00255 /* add file address */ 00256 lpText = GetStringFromSettings(pInfo->pRdpSettings, 00257 L"full address"); 00258 if (lpText) 00259 { 00260 SetDlgItemTextW(pInfo->hGeneralPage, 00261 IDC_SERVERCOMBO, 00262 lpText); 00263 } 00264 00265 /* set user name */ 00266 lpText = GetStringFromSettings(pInfo->pRdpSettings, 00267 L"username"); 00268 if (lpText) 00269 { 00270 SetDlgItemTextW(pInfo->hGeneralPage, 00271 IDC_NAMEEDIT, 00272 lpText); 00273 } 00274 } 00275 00276 00277 static VOID 00278 GeneralOnInit(HWND hwnd, 00279 PINFO pInfo) 00280 { 00281 SetWindowLongPtrW(hwnd, 00282 GWLP_USERDATA, 00283 (LONG_PTR)pInfo); 00284 00285 pInfo->hGeneralPage = hwnd; 00286 00287 SetWindowPos(pInfo->hGeneralPage, 00288 NULL, 00289 2, 00290 22, 00291 0, 00292 0, 00293 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER); 00294 00295 pInfo->hLogon = LoadImageW(hInst, 00296 MAKEINTRESOURCEW(IDI_LOGON), 00297 IMAGE_ICON, 00298 32, 00299 32, 00300 LR_DEFAULTCOLOR); 00301 if (pInfo->hLogon) 00302 { 00303 SendDlgItemMessageW(pInfo->hGeneralPage, 00304 IDC_LOGONICON, 00305 STM_SETICON, 00306 (WPARAM)pInfo->hLogon, 00307 0); 00308 } 00309 00310 pInfo->hConn = LoadImageW(hInst, 00311 MAKEINTRESOURCEW(IDI_CONN), 00312 IMAGE_ICON, 00313 32, 00314 32, 00315 LR_DEFAULTCOLOR); 00316 if (pInfo->hConn) 00317 { 00318 SendDlgItemMessageW(pInfo->hGeneralPage, 00319 IDC_CONNICON, 00320 STM_SETICON, 00321 (WPARAM)pInfo->hConn, 00322 0); 00323 } 00324 00325 FillServerAddesssCombo(pInfo); 00326 ReLoadGeneralPage(pInfo); 00327 } 00328 00329 00330 INT_PTR CALLBACK 00331 GeneralDlgProc(HWND hDlg, 00332 UINT message, 00333 WPARAM wParam, 00334 LPARAM lParam) 00335 { 00336 PINFO pInfo = (PINFO)GetWindowLongPtrW(hDlg, 00337 GWLP_USERDATA); 00338 00339 switch (message) 00340 { 00341 case WM_INITDIALOG: 00342 GeneralOnInit(hDlg, (PINFO)lParam); 00343 return TRUE; 00344 00345 case WM_COMMAND: 00346 { 00347 switch(LOWORD(wParam)) 00348 { 00349 case IDC_SERVERCOMBO: 00350 if (HIWORD(wParam) == CBN_SELCHANGE) 00351 { 00352 INT last, cur; 00353 00354 cur = SendDlgItemMessageW(hDlg, 00355 IDC_SERVERCOMBO, 00356 CB_GETCURSEL, 00357 0, 00358 0); 00359 00360 last = SendDlgItemMessageW(hDlg, 00361 IDC_SERVERCOMBO, 00362 CB_GETCOUNT, 00363 0, 00364 0); 00365 if ((cur + 1) == last) 00366 MessageBoxW(hDlg, L"SMB is not yet supported", L"RDP error", MB_ICONERROR); 00367 else 00368 { 00369 LoadUsernameHint(hDlg, cur); 00370 } 00371 } 00372 break; 00373 00374 case IDC_SAVE: 00375 SaveAllSettings(pInfo); 00376 SaveRdpSettingsToFile(NULL, pInfo->pRdpSettings); 00377 break; 00378 00379 case IDC_SAVEAS: 00380 DoSaveAs(pInfo); 00381 break; 00382 00383 case IDC_OPEN: 00384 DoOpenFile(pInfo); 00385 break; 00386 } 00387 00388 break; 00389 } 00390 00391 case WM_CLOSE: 00392 { 00393 if (pInfo->hLogon) 00394 DestroyIcon(pInfo->hLogon); 00395 00396 if (pInfo->hConn) 00397 DestroyIcon(pInfo->hConn); 00398 00399 break; 00400 } 00401 } 00402 00403 return 0; 00404 } 00405 00406 00407 static PSETTINGS_ENTRY 00408 GetPossibleSettings(IN LPCWSTR lpDeviceName, 00409 OUT DWORD* pSettingsCount, 00410 OUT PSETTINGS_ENTRY* CurrentSettings) 00411 { 00412 DEVMODEW devmode; 00413 DWORD NbSettings = 0; 00414 DWORD iMode = 0; 00415 DWORD dwFlags = 0; 00416 PSETTINGS_ENTRY Settings = NULL; 00417 HDC hDC; 00418 PSETTINGS_ENTRY Current; 00419 DWORD bpp, xres, yres, checkbpp; 00420 00421 /* Get current settings */ 00422 *CurrentSettings = NULL; 00423 hDC = CreateICW(NULL, lpDeviceName, NULL, NULL); 00424 bpp = GetDeviceCaps(hDC, PLANES); 00425 bpp *= GetDeviceCaps(hDC, BITSPIXEL); 00426 xres = GetDeviceCaps(hDC, HORZRES); 00427 yres = GetDeviceCaps(hDC, VERTRES); 00428 DeleteDC(hDC); 00429 00430 /* List all settings */ 00431 devmode.dmSize = (WORD)sizeof(DEVMODE); 00432 devmode.dmDriverExtra = 0; 00433 00434 if (!EnumDisplaySettingsExW(lpDeviceName, ENUM_CURRENT_SETTINGS, &devmode, dwFlags)) 00435 return NULL; 00436 00437 while (EnumDisplaySettingsExW(lpDeviceName, iMode, &devmode, dwFlags)) 00438 { 00439 if (devmode.dmBitsPerPel==8 || 00440 devmode.dmBitsPerPel==16 || 00441 devmode.dmBitsPerPel==24 || 00442 devmode.dmBitsPerPel==32) 00443 { 00444 checkbpp=1; 00445 } 00446 else 00447 checkbpp=0; 00448 00449 if (devmode.dmPelsWidth < 640 || 00450 devmode.dmPelsHeight < 480 || checkbpp == 0) 00451 { 00452 iMode++; 00453 continue; 00454 } 00455 00456 Current = HeapAlloc(GetProcessHeap(), 0, sizeof(SETTINGS_ENTRY)); 00457 if (Current != NULL) 00458 { 00459 /* Sort resolutions by increasing height, and BPP */ 00460 PSETTINGS_ENTRY Previous = NULL; 00461 PSETTINGS_ENTRY Next = Settings; 00462 Current->dmPelsWidth = devmode.dmPelsWidth; 00463 Current->dmPelsHeight = devmode.dmPelsHeight; 00464 Current->dmBitsPerPel = devmode.dmBitsPerPel; 00465 while (Next != NULL && 00466 (Next->dmPelsWidth < Current->dmPelsWidth || 00467 (Next->dmPelsWidth == Current->dmPelsWidth && Next->dmPelsHeight < Current->dmPelsHeight) || 00468 (Next->dmPelsHeight == Current->dmPelsHeight && 00469 Next->dmPelsWidth == Current->dmPelsWidth && 00470 Next->dmBitsPerPel < Current->dmBitsPerPel ))) 00471 { 00472 Previous = Next; 00473 Next = Next->Flink; 00474 } 00475 Current->Blink = Previous; 00476 Current->Flink = Next; 00477 if (Previous == NULL) 00478 Settings = Current; 00479 else 00480 Previous->Flink = Current; 00481 if (Next != NULL) 00482 Next->Blink = Current; 00483 if (devmode.dmPelsWidth == xres && devmode.dmPelsHeight == yres && devmode.dmBitsPerPel == bpp) 00484 { 00485 *CurrentSettings = Current; 00486 } 00487 NbSettings++; 00488 } 00489 iMode++; 00490 } 00491 00492 *pSettingsCount = NbSettings; 00493 return Settings; 00494 } 00495 00496 00497 static BOOL 00498 AddDisplayDevice(PINFO pInfo, PDISPLAY_DEVICEW DisplayDevice) 00499 { 00500 PDISPLAY_DEVICE_ENTRY newEntry = NULL; 00501 LPWSTR description = NULL; 00502 LPWSTR name = NULL; 00503 LPWSTR key = NULL; 00504 LPWSTR devid = NULL; 00505 DWORD descriptionSize, nameSize, keySize, devidSize; 00506 PSETTINGS_ENTRY Current; 00507 DWORD ResolutionsCount = 1; 00508 DWORD i; 00509 00510 newEntry = HeapAlloc(GetProcessHeap(), 00511 0, 00512 sizeof(DISPLAY_DEVICE_ENTRY)); 00513 if (!newEntry) goto ByeBye; 00514 ZeroMemory(newEntry, sizeof(DISPLAY_DEVICE_ENTRY)); 00515 00516 newEntry->Settings = GetPossibleSettings(DisplayDevice->DeviceName, 00517 &newEntry->SettingsCount, 00518 &newEntry->CurrentSettings); 00519 if (!newEntry->Settings) goto ByeBye; 00520 00521 newEntry->InitialSettings.dmPelsWidth = newEntry->CurrentSettings->dmPelsWidth; 00522 newEntry->InitialSettings.dmPelsHeight = newEntry->CurrentSettings->dmPelsHeight; 00523 newEntry->InitialSettings.dmBitsPerPel = newEntry->CurrentSettings->dmBitsPerPel; 00524 00525 /* Count different resolutions */ 00526 for (Current = newEntry->Settings; Current != NULL; Current = Current->Flink) 00527 { 00528 if (Current->Flink != NULL && 00529 ((Current->dmPelsWidth != Current->Flink->dmPelsWidth) && 00530 (Current->dmPelsHeight != Current->Flink->dmPelsHeight))) 00531 { 00532 ResolutionsCount++; 00533 } 00534 } 00535 00536 newEntry->Resolutions = HeapAlloc(GetProcessHeap(), 00537 0, 00538 ResolutionsCount * (sizeof(RESOLUTION_INFO) + 1)); 00539 if (!newEntry->Resolutions) goto ByeBye; 00540 00541 newEntry->ResolutionsCount = ResolutionsCount; 00542 00543 /* Fill resolutions infos */ 00544 for (Current = newEntry->Settings, i = 0; Current != NULL; Current = Current->Flink) 00545 { 00546 if (Current->Flink == NULL || 00547 (Current->Flink != NULL && 00548 ((Current->dmPelsWidth != Current->Flink->dmPelsWidth) && 00549 (Current->dmPelsHeight != Current->Flink->dmPelsHeight)))) 00550 { 00551 newEntry->Resolutions[i].dmPelsWidth = Current->dmPelsWidth; 00552 newEntry->Resolutions[i].dmPelsHeight = Current->dmPelsHeight; 00553 i++; 00554 } 00555 } 00556 00557 /* fullscreen */ 00558 newEntry->Resolutions[i].dmPelsWidth = GetSystemMetrics(SM_CXSCREEN); 00559 newEntry->Resolutions[i].dmPelsHeight = GetSystemMetrics(SM_CYSCREEN); 00560 00561 descriptionSize = (wcslen(DisplayDevice->DeviceString) + 1) * sizeof(WCHAR); 00562 description = HeapAlloc(GetProcessHeap(), 0, descriptionSize); 00563 if (!description) goto ByeBye; 00564 00565 nameSize = (wcslen(DisplayDevice->DeviceName) + 1) * sizeof(WCHAR); 00566 name = HeapAlloc(GetProcessHeap(), 0, nameSize); 00567 if (!name) goto ByeBye; 00568 00569 keySize = (wcslen(DisplayDevice->DeviceKey) + 1) * sizeof(WCHAR); 00570 key = HeapAlloc(GetProcessHeap(), 0, keySize); 00571 if (!key) goto ByeBye; 00572 00573 devidSize = (wcslen(DisplayDevice->DeviceID) + 1) * sizeof(WCHAR); 00574 devid = HeapAlloc(GetProcessHeap(), 0, devidSize); 00575 if (!devid) goto ByeBye; 00576 00577 memcpy(description, DisplayDevice->DeviceString, descriptionSize); 00578 memcpy(name, DisplayDevice->DeviceName, nameSize); 00579 memcpy(key, DisplayDevice->DeviceKey, keySize); 00580 memcpy(devid, DisplayDevice->DeviceID, devidSize); 00581 newEntry->DeviceDescription = description; 00582 newEntry->DeviceName = name; 00583 newEntry->DeviceKey = key; 00584 newEntry->DeviceID = devid; 00585 newEntry->DeviceStateFlags = DisplayDevice->StateFlags; 00586 newEntry->Flink = pInfo->DisplayDeviceList; 00587 pInfo->DisplayDeviceList = newEntry; 00588 return TRUE; 00589 00590 ByeBye: 00591 if (newEntry != NULL) 00592 { 00593 if (newEntry->Settings != NULL) 00594 { 00595 Current = newEntry->Settings; 00596 while (Current != NULL) 00597 { 00598 PSETTINGS_ENTRY Next = Current->Flink; 00599 HeapFree(GetProcessHeap(), 0, Current); 00600 Current = Next; 00601 } 00602 } 00603 if (newEntry->Resolutions != NULL) 00604 HeapFree(GetProcessHeap(), 0, newEntry->Resolutions); 00605 HeapFree(GetProcessHeap(), 0, newEntry); 00606 } 00607 if (description != NULL) 00608 HeapFree(GetProcessHeap(), 0, description); 00609 if (name != NULL) 00610 HeapFree(GetProcessHeap(), 0, name); 00611 if (key != NULL) 00612 HeapFree(GetProcessHeap(), 0, key); 00613 if (devid != NULL) 00614 HeapFree(GetProcessHeap(), 0, devid); 00615 return FALSE; 00616 } 00617 00618 00619 static VOID 00620 OnResolutionChanged(PINFO pInfo, INT position) 00621 { 00622 WCHAR Buffer[64]; 00623 INT MaxSlider; 00624 00625 MaxSlider = SendDlgItemMessageW(pInfo->hDisplayPage, 00626 IDC_GEOSLIDER, 00627 TBM_GETRANGEMAX, 00628 0, 00629 0); 00630 00631 if (position == MaxSlider) 00632 { 00633 LoadStringW(hInst, 00634 IDS_FULLSCREEN, 00635 Buffer, 00636 sizeof(Buffer) / sizeof(WCHAR)); 00637 } 00638 else 00639 { 00640 WCHAR Pixel[64]; 00641 00642 if (LoadStringW(hInst, 00643 IDS_PIXEL, 00644 Pixel, 00645 sizeof(Pixel) / sizeof(WCHAR))) 00646 { 00647 #ifdef _MSC_VER 00648 _swprintf(Buffer, 00649 Pixel, 00650 pInfo->DisplayDeviceList->Resolutions[position].dmPelsWidth, 00651 pInfo->DisplayDeviceList->Resolutions[position].dmPelsHeight, 00652 Pixel); 00653 #else 00654 swprintf(Buffer, 00655 Pixel, 00656 pInfo->DisplayDeviceList->Resolutions[position].dmPelsWidth, 00657 pInfo->DisplayDeviceList->Resolutions[position].dmPelsHeight, 00658 Pixel); 00659 #endif 00660 } 00661 } 00662 00663 SendDlgItemMessageW(pInfo->hDisplayPage, 00664 IDC_SETTINGS_RESOLUTION_TEXT, 00665 WM_SETTEXT, 00666 0, 00667 (LPARAM)Buffer); 00668 } 00669 00670 00671 static VOID 00672 FillResolutionsAndColors(PINFO pInfo) 00673 { 00674 PSETTINGS_ENTRY Current; 00675 DWORD index, i, num; 00676 DWORD MaxBpp = 0; 00677 UINT types[4]; 00678 00679 pInfo->CurrentDisplayDevice = pInfo->DisplayDeviceList; /* Update global variable */ 00680 00681 /* find max bpp */ 00682 SendDlgItemMessageW(pInfo->hDisplayPage, 00683 IDC_BPPCOMBO, 00684 CB_RESETCONTENT, 00685 0, 00686 0); 00687 for (Current = pInfo->DisplayDeviceList->Settings; Current != NULL; Current = Current->Flink) 00688 { 00689 if (Current->dmBitsPerPel > MaxBpp) 00690 MaxBpp = Current->dmBitsPerPel; 00691 } 00692 switch (MaxBpp) 00693 { 00694 case 32: 00695 case 24: num = 4; break; 00696 case 16: num = 3; break; 00697 case 8: num = 1; break; 00698 default: num = 0; break; 00699 } 00700 00701 types[0] = IDS_256COLORS; 00702 types[1] = IDS_HIGHCOLOR15; 00703 types[2] = IDS_HIGHCOLOR16; 00704 types[3] = IDS_HIGHCOLOR24; 00705 00706 /* Fill color depths combo box */ 00707 SendDlgItemMessageW(pInfo->hDisplayPage, 00708 IDC_BPPCOMBO, 00709 CB_RESETCONTENT, 00710 0, 00711 0); 00712 00713 for (i = 0, Current = pInfo->DisplayDeviceList->Settings; 00714 i <= num && Current != NULL; 00715 i++, Current = Current->Flink) 00716 { 00717 WCHAR Buffer[64]; 00718 if (LoadStringW(hInst, 00719 types[i], 00720 Buffer, 00721 sizeof(Buffer) / sizeof(WCHAR))) 00722 { 00723 index = (DWORD)SendDlgItemMessageW(pInfo->hDisplayPage, 00724 IDC_BPPCOMBO, 00725 CB_FINDSTRINGEXACT, 00726 (WPARAM)-1, 00727 (LPARAM)Buffer); 00728 if (index == (DWORD)CB_ERR) 00729 { 00730 index = (DWORD)SendDlgItemMessageW(pInfo->hDisplayPage, 00731 IDC_BPPCOMBO, 00732 CB_ADDSTRING, 00733 0, 00734 (LPARAM)Buffer); 00735 SendDlgItemMessageW(pInfo->hDisplayPage, 00736 IDC_BPPCOMBO, 00737 CB_SETITEMDATA, 00738 index, 00739 types[i]); 00740 } 00741 } 00742 } 00743 00744 /* Fill resolutions slider */ 00745 SendDlgItemMessageW(pInfo->hDisplayPage, 00746 IDC_GEOSLIDER, 00747 TBM_CLEARTICS, 00748 TRUE, 00749 0); 00750 SendDlgItemMessageW(pInfo->hDisplayPage, 00751 IDC_GEOSLIDER, 00752 TBM_SETRANGE, 00753 TRUE, 00754 MAKELONG(0, pInfo->DisplayDeviceList->ResolutionsCount)); //extra 1 for full screen 00755 00756 00757 } 00758 00759 00760 static VOID 00761 ReLoadDisplayPage(PINFO pInfo) 00762 { 00763 DWORD index; 00764 INT width, height, pos = 0; 00765 INT bpp, num, i, screenmode; 00766 BOOL bSet = FALSE; 00767 00768 /* get fullscreen info */ 00769 screenmode = GetIntegerFromSettings(pInfo->pRdpSettings, L"screen mode id"); 00770 00771 /* set trackbar position */ 00772 width = GetIntegerFromSettings(pInfo->pRdpSettings, L"desktopwidth"); 00773 height = GetIntegerFromSettings(pInfo->pRdpSettings, L"desktopheight"); 00774 00775 if (width != -1 && height != -1) 00776 { 00777 if(screenmode == 2) 00778 { 00779 pos = SendDlgItemMessageW(pInfo->hDisplayPage, 00780 IDC_GEOSLIDER, 00781 TBM_GETRANGEMAX, 00782 0, 00783 0); 00784 } 00785 else 00786 { 00787 for (index = 0; index < pInfo->CurrentDisplayDevice->ResolutionsCount; index++) 00788 { 00789 if (pInfo->CurrentDisplayDevice->Resolutions[index].dmPelsWidth == width && 00790 pInfo->CurrentDisplayDevice->Resolutions[index].dmPelsHeight == height) 00791 { 00792 pos = index; 00793 break; 00794 } 00795 } 00796 } 00797 } 00798 00799 /* set slider position */ 00800 SendDlgItemMessageW(pInfo->hDisplayPage, 00801 IDC_GEOSLIDER, 00802 TBM_SETPOS, 00803 TRUE, 00804 pos); 00805 00806 OnResolutionChanged(pInfo, pos); 00807 00808 00809 /* set color combo */ 00810 bpp = GetIntegerFromSettings(pInfo->pRdpSettings, L"session bpp"); 00811 00812 num = SendDlgItemMessageW(pInfo->hDisplayPage, 00813 IDC_BPPCOMBO, 00814 CB_GETCOUNT, 00815 0, 00816 0); 00817 for (i = 0; i < num; i++) 00818 { 00819 INT data = SendDlgItemMessageW(pInfo->hDisplayPage, 00820 IDC_BPPCOMBO, 00821 CB_GETITEMDATA, 00822 i, 00823 0); 00824 if (data == bpp) 00825 { 00826 SendDlgItemMessageW(pInfo->hDisplayPage, 00827 IDC_BPPCOMBO, 00828 CB_SETCURSEL, 00829 i, 00830 0); 00831 bSet = TRUE; 00832 break; 00833 } 00834 } 00835 00836 if (!bSet) 00837 { 00838 SendDlgItemMessageW(pInfo->hDisplayPage, 00839 IDC_BPPCOMBO, 00840 CB_SETCURSEL, 00841 num - 1, 00842 0); 00843 } 00844 } 00845 00846 00847 static VOID 00848 DisplayOnInit(HWND hwnd, 00849 PINFO pInfo) 00850 { 00851 DISPLAY_DEVICEW displayDevice; 00852 DWORD iDevNum = 0; 00853 BOOL GotDev = FALSE; 00854 00855 SetWindowLongPtrW(hwnd, 00856 GWLP_USERDATA, 00857 (LONG_PTR)pInfo); 00858 00859 pInfo->hDisplayPage = hwnd; 00860 00861 SetWindowPos(pInfo->hDisplayPage, 00862 NULL, 00863 2, 00864 22, 00865 0, 00866 0, 00867 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER); 00868 00869 pInfo->hRemote = LoadImageW(hInst, 00870 MAKEINTRESOURCEW(IDI_REMOTE), 00871 IMAGE_ICON, 00872 32, 00873 32, 00874 LR_DEFAULTCOLOR); 00875 if (pInfo->hRemote) 00876 { 00877 SendDlgItemMessageW(pInfo->hDisplayPage, 00878 IDC_REMICON, 00879 STM_SETICON, 00880 (WPARAM)pInfo->hRemote, 00881 0); 00882 } 00883 00884 pInfo->hColor = LoadImageW(hInst, 00885 MAKEINTRESOURCEW(IDI_COLORS), 00886 IMAGE_ICON, 00887 32, 00888 32, 00889 LR_DEFAULTCOLOR); 00890 if (pInfo->hColor) 00891 { 00892 SendDlgItemMessageW(pInfo->hDisplayPage, 00893 IDC_COLORSICON, 00894 STM_SETICON, 00895 (WPARAM)pInfo->hColor, 00896 0); 00897 } 00898 00899 pInfo->hSpectrum = LoadImageW(hInst, 00900 MAKEINTRESOURCEW(IDB_SPECT), 00901 IMAGE_BITMAP, 00902 0, 00903 0, 00904 LR_DEFAULTCOLOR); 00905 if (pInfo->hSpectrum) 00906 { 00907 GetObjectW(pInfo->hSpectrum, 00908 sizeof(BITMAP), 00909 &pInfo->bitmap); 00910 } 00911 00912 /* Get video cards list */ 00913 displayDevice.cb = (DWORD)sizeof(DISPLAY_DEVICE); 00914 while (EnumDisplayDevicesW(NULL, iDevNum, &displayDevice, 0x1)) 00915 { 00916 if ((displayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) != 0) 00917 { 00918 if (AddDisplayDevice(pInfo, &displayDevice)) 00919 GotDev = TRUE; 00920 } 00921 iDevNum++; 00922 } 00923 00924 if (GotDev) 00925 { 00926 FillResolutionsAndColors(pInfo); 00927 ReLoadDisplayPage(pInfo); 00928 } 00929 } 00930 00931 00932 INT_PTR CALLBACK 00933 DisplayDlgProc(HWND hDlg, 00934 UINT message, 00935 WPARAM wParam, 00936 LPARAM lParam) 00937 { 00938 PINFO pInfo = (PINFO)GetWindowLongPtrW(hDlg, 00939 GWLP_USERDATA); 00940 00941 switch (message) 00942 { 00943 case WM_INITDIALOG: 00944 DisplayOnInit(hDlg, (PINFO)lParam); 00945 return TRUE; 00946 00947 case WM_DRAWITEM: 00948 { 00949 LPDRAWITEMSTRUCT lpDrawItem; 00950 lpDrawItem = (LPDRAWITEMSTRUCT) lParam; 00951 if(lpDrawItem->CtlID == IDC_COLORIMAGE) 00952 { 00953 HDC hdcMem; 00954 HBITMAP hSpecOld; 00955 hdcMem = CreateCompatibleDC(lpDrawItem->hDC); 00956 if (hdcMem != NULL) 00957 { 00958 hSpecOld = SelectObject(hdcMem, pInfo->hSpectrum); 00959 StretchBlt(lpDrawItem->hDC, 00960 lpDrawItem->rcItem.left, 00961 lpDrawItem->rcItem.top, 00962 lpDrawItem->rcItem.right - lpDrawItem->rcItem.left, 00963 lpDrawItem->rcItem.bottom - lpDrawItem->rcItem.top, 00964 hdcMem, 00965 0, 00966 0, 00967 pInfo->bitmap.bmWidth, 00968 pInfo->bitmap.bmHeight, 00969 SRCCOPY); 00970 SelectObject(hdcMem, hSpecOld); 00971 DeleteDC(hdcMem); 00972 } 00973 } 00974 break; 00975 } 00976 00977 case WM_HSCROLL: 00978 { 00979 switch (LOWORD(wParam)) 00980 { 00981 case TB_LINEUP: 00982 case TB_LINEDOWN: 00983 case TB_PAGEUP: 00984 case TB_PAGEDOWN: 00985 case TB_TOP: 00986 case TB_BOTTOM: 00987 case TB_ENDTRACK: 00988 { 00989 INT newPosition = (DWORD)SendDlgItemMessageW(hDlg, IDC_GEOSLIDER, TBM_GETPOS, 0, 0); 00990 OnResolutionChanged(pInfo, newPosition); 00991 break; 00992 } 00993 00994 case TB_THUMBTRACK: 00995 OnResolutionChanged(pInfo, HIWORD(wParam)); 00996 break; 00997 } 00998 break; 00999 } 01000 01001 case WM_CLOSE: 01002 { 01003 if (pInfo->hRemote) 01004 DestroyIcon(pInfo->hRemote); 01005 01006 if (pInfo->hColor) 01007 DestroyIcon(pInfo->hColor); 01008 01009 if (pInfo->hSpectrum) 01010 DeleteObject(pInfo->hSpectrum); 01011 01012 break; 01013 } 01014 01015 break; 01016 } 01017 return 0; 01018 } 01019 01020 01021 static BOOL 01022 OnMainCreate(HWND hwnd, 01023 PRDPSETTINGS pRdpSettings) 01024 { 01025 PINFO pInfo; 01026 TCITEMW item; 01027 BOOL bRet = FALSE; 01028 01029 pInfo = HeapAlloc(GetProcessHeap(), 01030 HEAP_ZERO_MEMORY, 01031 sizeof(INFO)); 01032 if (pInfo) 01033 { 01034 SetWindowLongPtrW(hwnd, 01035 GWLP_USERDATA, 01036 (LONG_PTR)pInfo); 01037 01038 pInfo->hSelf = hwnd; 01039 01040 /* add main settings pointer */ 01041 pInfo->pRdpSettings = pRdpSettings; 01042 01043 /* set the dialog icons */ 01044 pInfo->hMstscSm = LoadImageW(hInst, 01045 MAKEINTRESOURCEW(IDI_MSTSC), 01046 IMAGE_ICON, 01047 16, 01048 16, 01049 LR_DEFAULTCOLOR); 01050 if (pInfo->hMstscSm) 01051 { 01052 SendMessageW(hwnd, 01053 WM_SETICON, 01054 ICON_SMALL, 01055 (WPARAM)pInfo->hMstscSm); 01056 } 01057 pInfo->hMstscLg = LoadImageW(hInst, 01058 MAKEINTRESOURCEW(IDI_MSTSC), 01059 IMAGE_ICON, 01060 32, 01061 32, 01062 LR_DEFAULTCOLOR); 01063 if (pInfo->hMstscLg) 01064 { 01065 SendMessageW(hwnd, 01066 WM_SETICON, 01067 ICON_BIG, 01068 (WPARAM)pInfo->hMstscLg); 01069 } 01070 01071 pInfo->hHeader = (HBITMAP)LoadImageW(hInst, 01072 MAKEINTRESOURCEW(IDB_HEADER), 01073 IMAGE_BITMAP, 01074 0, 01075 0, 01076 LR_DEFAULTCOLOR); 01077 if (pInfo->hHeader) 01078 { 01079 GetObjectW(pInfo->hHeader, 01080 sizeof(BITMAP), 01081 &pInfo->headerbitmap); 01082 } 01083 01084 /* setup the tabs */ 01085 pInfo->hTab = GetDlgItem(hwnd, IDC_TAB); 01086 if (pInfo->hTab) 01087 { 01088 if (CreateDialogParamW(hInst, 01089 MAKEINTRESOURCEW(IDD_GENERAL), 01090 pInfo->hTab, 01091 GeneralDlgProc, 01092 (LPARAM)pInfo)) 01093 { 01094 WCHAR str[256]; 01095 ZeroMemory(&item, sizeof(TCITEM)); 01096 item.mask = TCIF_TEXT; 01097 if (LoadStringW(hInst, IDS_TAB_GENERAL, str, 256)) 01098 item.pszText = str; 01099 item.cchTextMax = 256; 01100 (void)TabCtrl_InsertItem(pInfo->hTab, 0, &item); 01101 } 01102 01103 if (CreateDialogParamW(hInst, 01104 MAKEINTRESOURCEW(IDD_DISPLAY), 01105 pInfo->hTab, 01106 DisplayDlgProc, 01107 (LPARAM)pInfo)) 01108 { 01109 WCHAR str[256]; 01110 ZeroMemory(&item, sizeof(TCITEM)); 01111 item.mask = TCIF_TEXT; 01112 if (LoadStringW(hInst, IDS_TAB_DISPLAY, str, 256)) 01113 item.pszText = str; 01114 item.cchTextMax = 256; 01115 (void)TabCtrl_InsertItem(pInfo->hTab, 1, &item); 01116 } 01117 01118 OnTabWndSelChange(pInfo); 01119 } 01120 } 01121 01122 return bRet; 01123 } 01124 01125 static void Cleanup(PINFO pInfo) 01126 { 01127 if (pInfo) 01128 { 01129 if (pInfo->hMstscSm) 01130 DestroyIcon(pInfo->hMstscSm); 01131 if (pInfo->hMstscLg) 01132 DestroyIcon(pInfo->hMstscLg); 01133 if (pInfo->hHeader) 01134 DeleteObject(pInfo->hHeader); 01135 if (pInfo->hSpectrum) 01136 DeleteObject(pInfo->hSpectrum); 01137 if (pInfo->hRemote) 01138 DestroyIcon(pInfo->hRemote); 01139 if (pInfo->hLogon) 01140 DestroyIcon(pInfo->hLogon); 01141 if (pInfo->hConn) 01142 DestroyIcon(pInfo->hConn); 01143 if (pInfo->hColor) 01144 DestroyIcon(pInfo->hColor); 01145 HeapFree(GetProcessHeap(), 01146 0, 01147 pInfo); 01148 } 01149 } 01150 01151 static INT_PTR CALLBACK 01152 DlgProc(HWND hDlg, 01153 UINT Message, 01154 WPARAM wParam, 01155 LPARAM lParam) 01156 { 01157 PINFO pInfo; 01158 01159 /* Get the window context */ 01160 pInfo = (PINFO)GetWindowLongPtrW(hDlg, 01161 GWLP_USERDATA); 01162 if (pInfo == NULL && Message != WM_INITDIALOG) 01163 { 01164 goto HandleDefaultMessage; 01165 } 01166 01167 switch(Message) 01168 { 01169 case WM_INITDIALOG: 01170 OnMainCreate(hDlg, (PRDPSETTINGS)lParam); 01171 break; 01172 01173 case WM_COMMAND: 01174 { 01175 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 01176 { 01177 if (LOWORD(wParam) == IDOK ) 01178 { 01179 SaveAllSettings(pInfo); 01180 SaveRdpSettingsToFile(NULL, pInfo->pRdpSettings); 01181 } 01182 Cleanup(pInfo); 01183 EndDialog(hDlg, LOWORD(wParam)); 01184 } 01185 01186 break; 01187 } 01188 01189 case WM_NOTIFY: 01190 { 01191 //INT idctrl; 01192 LPNMHDR pnmh; 01193 //idctrl = (int)wParam; 01194 pnmh = (LPNMHDR)lParam; 01195 if (//(pnmh->hwndFrom == pInfo->hSelf) && 01196 (pnmh->idFrom == IDC_TAB) && 01197 (pnmh->code == TCN_SELCHANGE)) 01198 { 01199 OnTabWndSelChange(pInfo); 01200 } 01201 01202 break; 01203 } 01204 01205 case WM_PAINT: 01206 { 01207 PAINTSTRUCT ps; 01208 HDC hdc; 01209 01210 hdc = BeginPaint(hDlg, &ps); 01211 if (hdc != NULL) 01212 { 01213 HDC hdcMem = CreateCompatibleDC(hdc); 01214 if (hdcMem) 01215 { 01216 WCHAR szBuffer[32]; 01217 RECT bmpRc, txtRc; 01218 LOGFONTW lf; 01219 HFONT hFont, hFontOld; 01220 HBITMAP hBmpOld; 01221 01222 GetClientRect(pInfo->hSelf, &bmpRc); 01223 01224 hBmpOld = SelectObject(hdcMem, pInfo->hHeader); 01225 StretchBlt(hdc, 01226 0, 01227 0, 01228 bmpRc.right, 01229 pInfo->headerbitmap.bmHeight, 01230 hdcMem, 01231 0, 01232 0, 01233 pInfo->headerbitmap.bmWidth, 01234 pInfo->headerbitmap.bmHeight, 01235 SRCCOPY); 01236 01237 SelectObject(hdcMem, hBmpOld); 01238 txtRc.left = bmpRc.right / 4; 01239 txtRc.top = 10; 01240 txtRc.right = bmpRc.right * 3 / 4; 01241 txtRc.bottom = pInfo->headerbitmap.bmHeight / 2; 01242 01243 ZeroMemory(&lf, sizeof(LOGFONTW)); 01244 01245 if (LoadStringW(hInst, 01246 IDS_HEADERTEXT1, 01247 szBuffer, 01248 sizeof(szBuffer) / sizeof(WCHAR))) 01249 { 01250 lf.lfHeight = 24; 01251 lf.lfCharSet = OEM_CHARSET; 01252 lf.lfQuality = DEFAULT_QUALITY; 01253 lf.lfWeight = FW_MEDIUM; 01254 wcscpy(lf.lfFaceName, L"Tahoma"); 01255 01256 hFont = CreateFontIndirectW(&lf); 01257 if (hFont) 01258 { 01259 hFontOld = SelectObject(hdc, hFont); 01260 01261 DPtoLP(hdc, (PPOINT)&txtRc, 2); 01262 SetTextColor(hdc, RGB(255,255,255)); 01263 SetBkMode(hdc, TRANSPARENT); 01264 DrawTextW(hdc, 01265 szBuffer, 01266 -1, 01267 &txtRc, 01268 DT_BOTTOM | DT_SINGLELINE | DT_NOCLIP); 01269 SelectObject(hdc, hFontOld); 01270 DeleteObject(hFont); 01271 } 01272 } 01273 01274 txtRc.left = bmpRc.right / 4; 01275 txtRc.top = txtRc.bottom - 5; 01276 txtRc.right = bmpRc.right * 3 / 4; 01277 txtRc.bottom = pInfo->headerbitmap.bmHeight * 9 / 10; 01278 01279 if (LoadStringW(hInst, 01280 IDS_HEADERTEXT2, 01281 szBuffer, 01282 sizeof(szBuffer) / sizeof(WCHAR))) 01283 { 01284 lf.lfHeight = 30; 01285 lf.lfCharSet = OEM_CHARSET; 01286 lf.lfQuality = DEFAULT_QUALITY; 01287 lf.lfWeight = FW_EXTRABOLD; 01288 wcscpy(lf.lfFaceName, L"Tahoma"); 01289 01290 hFont = CreateFontIndirectW(&lf); 01291 if (hFont) 01292 { 01293 hFontOld = SelectObject(hdc, hFont); 01294 01295 DPtoLP(hdc, (PPOINT)&txtRc, 2); 01296 SetTextColor(hdc, RGB(255,255,255)); 01297 SetBkMode(hdc, TRANSPARENT); 01298 DrawTextW(hdc, 01299 szBuffer, 01300 -1, 01301 &txtRc, 01302 DT_TOP | DT_SINGLELINE); 01303 SelectObject(hdc, hFontOld); 01304 DeleteObject(hFont); 01305 } 01306 } 01307 01308 DeleteDC(hdcMem); 01309 } 01310 01311 EndPaint(hDlg, &ps); 01312 } 01313 01314 break; 01315 } 01316 01317 case WM_CLOSE: 01318 { 01319 Cleanup(pInfo); 01320 EndDialog(hDlg, 0); 01321 } 01322 break; 01323 01324 HandleDefaultMessage: 01325 default: 01326 return FALSE; 01327 } 01328 01329 return FALSE; 01330 } 01331 01332 01333 BOOL 01334 OpenRDPConnectDialog(HINSTANCE hInstance, 01335 PRDPSETTINGS pRdpSettings) 01336 { 01337 INITCOMMONCONTROLSEX iccx; 01338 01339 hInst = hInstance; 01340 01341 iccx.dwSize = sizeof(INITCOMMONCONTROLSEX); 01342 iccx.dwICC = ICC_TAB_CLASSES; 01343 InitCommonControlsEx(&iccx); 01344 01345 return (DialogBoxParamW(hInst, 01346 MAKEINTRESOURCEW(IDD_CONNECTDIALOG), 01347 NULL, 01348 DlgProc, 01349 (LPARAM)pRdpSettings) == IDOK); 01350 } Generated on Mon May 28 2012 04:17:07 for ReactOS by
1.7.6.1
|