Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2196 lines
62 KiB

  1. //
  2. // maindlg.cpp: main dialog box
  3. // gathers connection info and hosts tabs
  4. //
  5. // Copyright Microsoft Corportation 2000
  6. // (nadima)
  7. //
  8. #include "stdafx.h"
  9. #define TRC_GROUP TRC_GROUP_UI
  10. #define TRC_FILE "maindlg.cpp"
  11. #include <atrcapi.h>
  12. #include "maindlg.h"
  13. #include "discodlg.h"
  14. #include "validatedlg.h"
  15. #include "aboutdlg.h"
  16. #include "sh.h"
  17. #include "commctrl.h"
  18. #include "browsedlg.h"
  19. #include "propgeneral.h"
  20. #include "proplocalres.h"
  21. #include "propdisplay.h"
  22. #include "proprun.h"
  23. #include "propperf.h"
  24. //
  25. // Background color to fill padding area after branding img
  26. //
  27. #define IMAGE_BG_COL RGB(0x29,0x47,0xDA)
  28. // Low color
  29. #define IMAGE_BG_COL_16 RGB(0,0,0xFF)
  30. //
  31. // Controls which need to be moved when dialog
  32. // is resized
  33. //
  34. UINT moveableControls[] = {IDOK,
  35. IDCANCEL,
  36. ID_BUTTON_LOGON_HELP,
  37. ID_BUTTON_OPTIONS};
  38. UINT numMoveableControls = sizeof(moveableControls)/sizeof(UINT);
  39. //
  40. // Controls that are only visible/enabled on less
  41. //
  42. UINT lessUI[] = { UI_IDC_COMPUTER_NAME_STATIC,
  43. IDC_COMBO_SERVERS
  44. };
  45. UINT numLessUI = sizeof(lessUI)/sizeof(UINT);
  46. //
  47. // Controls that are only visibile/enabled on more
  48. //
  49. UINT moreUI[] = {IDC_TABS};
  50. UINT numMoreUI = sizeof(moreUI)/sizeof(UINT);
  51. //
  52. // Controls that need to be disabled/enabled
  53. // during connection
  54. //
  55. UINT connectingDisableControls[] = {IDOK,
  56. ID_BUTTON_LOGON_HELP,
  57. ID_BUTTON_OPTIONS,
  58. IDC_TABS,
  59. IDC_COMBO_SERVERS,
  60. IDC_COMBO_MAIN_OPTIMIZE,
  61. UI_IDC_COMPUTER_NAME_STATIC,
  62. UI_IDC_MAIN_OPTIMIZE_STATIC};
  63. const UINT numConnectingDisableControls = sizeof(connectingDisableControls) /
  64. sizeof(UINT);
  65. BOOL g_fPropPageStringMapInitialized = FALSE;
  66. PERFOPTIMIZESTRINGMAP g_PerfOptimizeStringTable[] =
  67. {
  68. {UI_IDS_OPTIMIZE_28K, TEXT("")},
  69. {UI_IDS_OPTIMIZE_56K, TEXT("")},
  70. {UI_IDS_OPTIMIZE_BROADBAND, TEXT("")},
  71. {UI_IDS_OPTIMIZE_LAN, TEXT("")},
  72. {UI_IDS_OPTIMIZE_MAIN_CUSTOM, TEXT("")},
  73. {UI_IDS_OPTIMIZE_CUSTOM, TEXT("")}
  74. };
  75. #define NUM_PERFSTRINGS sizeof(g_PerfOptimizeStringTable) / \
  76. sizeof(PERFOPTIMIZESTRINGMAP)
  77. CMainDlg* CMainDlg::_pMainDlgInstance = NULL;
  78. //
  79. // UNIWRAP WARNING ~*~*~*~*~*~*~*~*~*~*~*~*~*~~*~*~*~*~*~*~*~*~**~*~*~
  80. // TabControl messages need to be wrapped in the SendMessageThunk
  81. // in uniwrap so the tab control works on 9x with an ANSI comctl32.dll.
  82. //
  83. // If you add anything to the tab control code, make sure it is
  84. // handled by the wrapper.
  85. //
  86. //
  87. CMainDlg::CMainDlg( HWND hwndOwner, HINSTANCE hInst, CSH* pSh,
  88. CContainerWnd* pContainerWnd,
  89. CTscSettings* pTscSettings,
  90. BOOL fStartExpanded,
  91. INT nStartTab) :
  92. CDlgBase( hwndOwner, hInst, UI_IDD_TS_LOGON),
  93. _pSh(pSh),
  94. _pContainerWnd(pContainerWnd),
  95. _pTscSettings(pTscSettings),
  96. _fStartExpanded(fStartExpanded),
  97. _nStartTab(nStartTab)
  98. {
  99. DC_BEGIN_FN("CMainDlg");
  100. TRC_ASSERT((NULL == CMainDlg::_pMainDlgInstance),
  101. (TB,_T("Clobbering existing dlg instance pointer\n")));
  102. TRC_ASSERT((_pSh),
  103. (TB,_T("CMainDlg was passed null _pSh\n")));
  104. TRC_ASSERT(pContainerWnd,
  105. (TB, _T("Null container wnd pointer\n")));
  106. TRC_ASSERT(_pTscSettings,
  107. (TB, _T("NULL _pTscSettings pointer\n")));
  108. CMainDlg::_pMainDlgInstance = this;
  109. _fShowExpanded = FALSE;
  110. _pGeneralPg = NULL;
  111. _pLocalResPg = NULL;
  112. _pPropDisplayPg = NULL;
  113. _pRunPg = NULL;
  114. _pPerfPg = NULL;
  115. _nBrandImageHeight = 0;
  116. _nBrandImageWidth = 0;
  117. _lastValidBpp = 0;
  118. _hBrandPal = NULL;
  119. _hBrandImg = NULL;
  120. _hwndRestoreFocus = NULL;
  121. #ifndef OS_WINCE
  122. _pProgBand = NULL;
  123. #endif
  124. _connectionState = stateNotConnected;
  125. #ifdef OS_WINCE
  126. _fVgaDisplay = (GetSystemMetrics(SM_CYSCREEN) < 480);
  127. //use a small dialog template if we are running in a smaller screen
  128. if (_fVgaDisplay)
  129. {
  130. _dlgResId = UI_IDD_TS_LOGON_VGA;
  131. }
  132. #endif
  133. InitializePerfStrings();
  134. DC_END_FN();
  135. }
  136. CMainDlg::~CMainDlg()
  137. {
  138. CMainDlg::_pMainDlgInstance = NULL;
  139. delete _pGeneralPg;
  140. delete _pLocalResPg;
  141. delete _pPropDisplayPg;
  142. delete _pRunPg;
  143. delete _pPerfPg;
  144. #ifndef OS_WINCE
  145. if (_pProgBand) {
  146. delete _pProgBand;
  147. }
  148. #endif
  149. }
  150. HWND CMainDlg::StartModeless()
  151. {
  152. DC_BEGIN_FN("StartModeless");
  153. #ifdef OS_WINCE
  154. INITCOMMONCONTROLSEX cex;
  155. cex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  156. cex.dwICC = ICC_TAB_CLASSES;
  157. if(!InitCommonControlsEx( &cex ))
  158. {
  159. TRC_ABORT((TB,_T("InitCommonControlsEx failed 0x%x"),
  160. GetLastError()));
  161. }
  162. #endif
  163. _hwndDlg = CreateDialog(_hInstance, MAKEINTRESOURCE(_dlgResId),
  164. _hwndOwner, StaticDialogBoxProc);
  165. TRC_ASSERT(_hwndDlg, (TB,_T("CreateDialog failed")));
  166. DC_END_FN();
  167. return _hwndDlg;
  168. }
  169. INT_PTR CALLBACK CMainDlg::StaticDialogBoxProc (HWND hwndDlg,
  170. UINT uMsg,
  171. WPARAM wParam,
  172. LPARAM lParam)
  173. {
  174. //
  175. // Delegate to appropriate instance (only works for single instance dialogs)
  176. //
  177. DC_BEGIN_FN("StaticDialogBoxProc");
  178. DCINT retVal = 0;
  179. TRC_ASSERT(_pMainDlgInstance, (TB, _T("Logon dialog has NULL static instance ptr\n")));
  180. if(_pMainDlgInstance)
  181. {
  182. retVal = _pMainDlgInstance->DialogBoxProc( hwndDlg, uMsg, wParam, lParam);
  183. }
  184. DC_END_FN();
  185. return retVal;
  186. }
  187. //
  188. // Name: DialogBoxProc
  189. //
  190. // Purpose: Handles Main dialog
  191. //
  192. // Returns: TRUE if message dealt with
  193. // FALSE otherwise
  194. //
  195. // Params: See window documentation
  196. //
  197. //
  198. INT_PTR CALLBACK CMainDlg::DialogBoxProc (HWND hwndDlg,
  199. UINT uMsg,
  200. WPARAM wParam,
  201. LPARAM lParam)
  202. {
  203. INT_PTR rc = FALSE;
  204. #ifndef OS_WINCE
  205. DCUINT intRC ;
  206. #endif
  207. DC_BEGIN_FN("DialogBoxProc");
  208. switch (uMsg)
  209. {
  210. case WM_INITDIALOG:
  211. {
  212. _hwndDlg = hwndDlg;
  213. SetDialogAppIcon(hwndDlg);
  214. if(!_pSh || !_pContainerWnd)
  215. {
  216. return FALSE;
  217. }
  218. CenterWindow(NULL, 2, 4);
  219. SetForegroundWindow(hwndDlg);
  220. //turn off maximize box
  221. LONG style = GetWindowLong(hwndDlg, GWL_STYLE);
  222. style &= ~(WS_MAXIMIZEBOX);
  223. SetWindowLong( hwndDlg, GWL_STYLE, style);
  224. //
  225. // Bind this dialog to the container window
  226. // there is logic where these two windows need to interact
  227. // e.g during a connect:
  228. // if error occurs the error dialog is brought up modal wrt
  229. // to the connect dialog
  230. // also when connect completes it is the container window
  231. // that dismisses this dialog
  232. //
  233. _pContainerWnd->SetConnectDialogHandle( hwndDlg);
  234. _lastValidBpp = CSH::SH_GetScreenBpp();
  235. #ifndef OS_WINCE
  236. if(!InitializeBmps())
  237. {
  238. TRC_ERR((TB,_T("InitializeBmps failed")));
  239. }
  240. _pProgBand = new CProgressBand(hwndDlg,
  241. _hInstance,
  242. _nBrandImageHeight,
  243. UI_IDB_PROGRESS_BAND8,
  244. UI_IDB_PROGRESS_BAND4,
  245. _hBrandPal);
  246. if (_pProgBand) {
  247. if (!_pProgBand->Initialize()) {
  248. TRC_ERR((TB,_T("Progress band failed to init")));
  249. delete _pProgBand;
  250. _pProgBand = NULL;
  251. }
  252. }
  253. SetupDialogSysMenu();
  254. #endif //OS_WINCE
  255. //
  256. // Setup the server combo box
  257. //
  258. HWND hwndSrvCombo = GetDlgItem(hwndDlg, IDC_COMBO_SERVERS);
  259. CSH::InitServerAutoCmplCombo( _pTscSettings, hwndSrvCombo);
  260. SetWindowText(
  261. hwndSrvCombo,
  262. _pTscSettings->GetFlatConnectString()
  263. );
  264. SetFocus(GetDlgItem(hwndDlg, IDC_COMBO_SERVERS));
  265. SetForegroundWindow(hwndDlg);
  266. //
  267. // Load the button text for the Options button
  268. //
  269. if (!LoadString( _hInstance,
  270. UI_IDS_OPTIONS_MORE,
  271. _szOptionsMore,
  272. OPTIONS_STRING_MAX_LEN ))
  273. {
  274. // Some problem with the resources.
  275. TRC_SYSTEM_ERROR("LoadString");
  276. TRC_ERR((TB, _T("Failed to load string ID:%u"),
  277. UI_IDS_OPTIONS_MORE));
  278. //
  279. // splat something in to keep running
  280. //
  281. DC_TSTRCPY(_szOptionsMore, TEXT(""));
  282. }
  283. if (!LoadString( _hInstance,
  284. UI_IDS_CLOSE_TEXT,
  285. _szCloseText,
  286. SIZECHAR(_szCloseText)))
  287. {
  288. // Some problem with the resources.
  289. TRC_ERR((TB, _T("Failed to load string ID:%u : err:%d"),
  290. UI_IDS_CLOSE_TEXT, GetLastError()));
  291. DC_TSTRCPY(_szCloseText, TEXT(""));
  292. }
  293. if (!LoadString( _hInstance,
  294. UI_IDS_CANCEL_TEXT,
  295. _szCancelText,
  296. SIZECHAR(_szCancelText)))
  297. {
  298. // Some problem with the resources.
  299. TRC_ERR((TB, _T("Failed to load string ID:%u : err:%d"),
  300. UI_IDS_CANCEL_TEXT, GetLastError()));
  301. DC_TSTRCPY(_szCancelText, TEXT(""));
  302. }
  303. if (!LoadString( _hInstance,
  304. UI_IDS_OPTIONS_LESS,
  305. _szOptionsLess,
  306. OPTIONS_STRING_MAX_LEN ))
  307. {
  308. // Some problem with the resources.
  309. TRC_SYSTEM_ERROR("LoadString");
  310. TRC_ERR((TB, _T("Failed to load string ID:%u"),
  311. UI_IDS_OPTIONS_LESS));
  312. //
  313. // splat something in to keep running
  314. //
  315. DC_TSTRCPY(_szOptionsLess, TEXT(""));
  316. }
  317. SetWindowText(GetDlgItem(_hwndDlg,ID_BUTTON_OPTIONS),
  318. _fShowExpanded ? _szOptionsLess : _szOptionsMore);
  319. //
  320. // Make sure the 'more' UI is disabled
  321. //
  322. EnableControls(moreUI, numMoreUI, FALSE);
  323. InitTabs();
  324. if(_fStartExpanded)
  325. {
  326. //go expanded
  327. ToggleExpandedState();
  328. int foo = TabCtrl_SetCurSel(GetDlgItem(hwndDlg, IDC_TABS),
  329. _nStartTab);
  330. //SetCurSel does not send a TCN_SELCHANGE
  331. OnTabSelChange();
  332. }
  333. #ifdef OS_WINCE
  334. if ((GetFileAttributes(PEGHELP_EXE) == -1)||
  335. (GetFileAttributes(TSC_HELP_FILE) == -1))
  336. {
  337. LONG lRetVal = 0;
  338. lRetVal = GetWindowLong(_hwndDlg,
  339. GWL_STYLE);
  340. SetWindowLong(_hwndDlg,
  341. GWL_EXSTYLE,
  342. WS_EX_WINDOWEDGE);
  343. if (lRetVal != 0)
  344. {
  345. SetWindowLong(_hwndDlg,
  346. GWL_STYLE,
  347. lRetVal);
  348. }
  349. rc = SetWindowPos(_hwndDlg,NULL,0,0,0,0,
  350. SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
  351. }
  352. #endif
  353. rc = TRUE;
  354. }
  355. break;
  356. #ifdef OS_WINCE
  357. case WM_CLOSE:
  358. {
  359. if(stateConnecting == _connectionState)
  360. {
  361. //Cancel the connection
  362. TRC_NRM((TB, _T("User cancel connect from maindlg")));
  363. _pContainerWnd->Disconnect();
  364. }
  365. else
  366. {
  367. DlgToSettings();
  368. EndDialog(hwndDlg, IDCANCEL);
  369. PostMessage(_pContainerWnd->GetWndHandle(), WM_CLOSE, 0, 0);
  370. }
  371. }
  372. break;
  373. #endif
  374. case UI_SHOW_DISC_ERR_DLG:
  375. {
  376. //
  377. // If this assert fired something went wrong in the states
  378. // because we should have left the connecting state as the
  379. // first step of receiving an OnDisconnected notification
  380. // with WM_TSC_DISCONNECTED.
  381. //
  382. TRC_ASSERT(_connectionState != stateConnecting,
  383. (TB,_T("In connecting state when received Err Dlg popup")));
  384. SetConnectionState( stateNotConnected );
  385. CDisconnectedDlg disconDlg(hwndDlg, _hInstance, _pContainerWnd);
  386. disconDlg.SetDisconnectReason( wParam);
  387. disconDlg.SetExtendedDiscReason(
  388. (ExtendedDisconnectReasonCode) lParam );
  389. disconDlg.DoModal();
  390. }
  391. break;
  392. case WM_TSC_DISCONNECTED: //intentional fallthru
  393. case WM_TSC_CONNECTED:
  394. {
  395. //
  396. // Either we connected or got disconnected
  397. // while connecting. In either case the connection
  398. // has ended so leave the connecting state.
  399. //
  400. if (stateNotConnected != _connectionState)
  401. {
  402. //
  403. // Only end connecting if we're not already disconnected
  404. //
  405. OnEndConnection((WM_TSC_CONNECTED == uMsg));
  406. }
  407. }
  408. break;
  409. //
  410. // On return to connection UI
  411. // (e.g after a disconnection)
  412. //
  413. case WM_TSC_RETURNTOCONUI:
  414. {
  415. //
  416. // Reset the server combo to force it to repaint
  417. // this is a minor hack to fix the ComboBoxEx
  418. // which doesn't want to repaint itself on return
  419. // to the dialog.
  420. //
  421. HWND hwndSrvCombo = GetDlgItem(hwndDlg, IDC_COMBO_SERVERS);
  422. SetWindowText( hwndSrvCombo,
  423. _pTscSettings->GetFlatConnectString());
  424. //
  425. // Notify the active property page
  426. //
  427. if(_fShowExpanded && _tabDlgInfo.hwndCurPropPage)
  428. {
  429. SendMessage(_tabDlgInfo.hwndCurPropPage,
  430. WM_TSC_RETURNTOCONUI,
  431. 0,
  432. 0);
  433. }
  434. //
  435. // Give the default button style back to the connect
  436. // button and remove it from the cancel button.
  437. // While connecting we disable the connect (IDOK) button
  438. // so it is possible that the style goes to the Close/Cancel
  439. // button which confuses the user since the IDOK handler
  440. // is always for the connect button
  441. //
  442. SendDlgItemMessage(hwndDlg, IDCANCEL, BM_SETSTYLE,
  443. BS_PUSHBUTTON, MAKELPARAM(TRUE,0));
  444. SendDlgItemMessage(hwndDlg, IDOK, BM_SETSTYLE,
  445. BS_DEFPUSHBUTTON, MAKELPARAM(TRUE,0));
  446. }
  447. break;
  448. #ifndef OS_WINCE
  449. case WM_ERASEBKGND:
  450. {
  451. HDC hDC = (HDC)wParam;
  452. HPALETTE oldPalette = NULL;
  453. if (_hBrandPal) {
  454. oldPalette = SelectPalette(hDC, _hBrandPal, FALSE);
  455. RealizePalette(hDC);
  456. }
  457. rc = PaintBrandImage(hwndDlg,
  458. (HDC)wParam,
  459. COLOR_BTNFACE );
  460. if (_pProgBand) {
  461. _pProgBand->OnEraseParentBackground((HDC)wParam);
  462. }
  463. if ( oldPalette ) {
  464. SelectPalette(hDC, oldPalette, TRUE);
  465. }
  466. }
  467. break;
  468. case WM_TIMER:
  469. {
  470. if (_pProgBand) {
  471. _pProgBand->OnTimer((INT)wParam);
  472. }
  473. }
  474. break;
  475. #endif // OS_WINCE
  476. case WM_COMMAND:
  477. {
  478. switch(DC_GET_WM_COMMAND_ID(wParam))
  479. {
  480. case IDOK:
  481. {
  482. //
  483. // Update dialog with properties from active prop page
  484. //
  485. if(_fShowExpanded && _tabDlgInfo.hwndCurPropPage)
  486. {
  487. SendMessage(_tabDlgInfo.hwndCurPropPage,
  488. WM_SAVEPROPSHEET, 0, 0);
  489. }
  490. if(!_fShowExpanded)
  491. {
  492. //We're on the minimal tab
  493. //copy dlg settings tscSettings
  494. DlgToSettings();
  495. }
  496. TCHAR szServer[TSC_MAX_ADDRESS_LENGTH];
  497. _tcsncpy(szServer, _pTscSettings->GetFlatConnectString(),
  498. SIZECHAR(szServer));
  499. _pSh->SH_CanonicalizeServerName(szServer);
  500. BOOL bValidate =
  501. CRdpConnectionString::ValidateServerPart(szServer);
  502. if(!bValidate)
  503. {
  504. //
  505. // context sensitive help in validatedlg
  506. // needs in handle to main window
  507. //
  508. CValidateDlg validateDlg(hwndDlg, _hInstance,
  509. _pContainerWnd->GetWndHandle(),
  510. _pSh);
  511. validateDlg.DoModal();
  512. //
  513. // Clear and set the focus on the server edit well
  514. //
  515. HWND hwndSrvItem = NULL;
  516. if(_fShowExpanded)
  517. {
  518. hwndSrvItem = GetDlgItem(_tabDlgInfo.hwndCurPropPage,
  519. IDC_GENERAL_COMBO_SERVERS);
  520. }
  521. else
  522. {
  523. hwndSrvItem = GetDlgItem(hwndDlg, IDC_COMBO_SERVERS);
  524. }
  525. if(hwndSrvItem)
  526. {
  527. SetWindowText(hwndSrvItem, _T(""));
  528. TRC_DBG((TB, _T("Set focus to edit box")));
  529. SetFocus(hwndSrvItem);
  530. }
  531. break;
  532. }
  533. else
  534. {
  535. //
  536. // It's all good
  537. //
  538. _pTscSettings->SetConnectString(szServer);
  539. //
  540. // We have to kick off the connection
  541. // while the dialog is still active
  542. // in case it fails, we want the error message
  543. // to be parented off the connection dialog.
  544. //
  545. // Code in the parent window will dismiss this
  546. // dialog when the connection (which is asynchronous)
  547. // completes.
  548. //
  549. OnStartConnection();
  550. if(!_pContainerWnd->StartConnection())
  551. {
  552. TRC_ERR((TB,_T("StartConnection failed")));
  553. //Async connection start failed so end
  554. OnEndConnection(FALSE);
  555. break;
  556. }
  557. }
  558. }
  559. break;
  560. case IDCANCEL:
  561. {
  562. if(stateConnecting == _connectionState)
  563. {
  564. //Cancel the connection
  565. TRC_NRM((TB, _T("User cancel connect from maindlg")));
  566. _pContainerWnd->Disconnect();
  567. }
  568. else
  569. {
  570. DlgToSettings();
  571. EndDialog(hwndDlg, IDCANCEL);
  572. PostMessage(_pContainerWnd->GetWndHandle(), WM_CLOSE, 0, 0);
  573. }
  574. }
  575. break;
  576. case ID_BUTTON_LOGON_HELP:
  577. {
  578. TRC_NRM((TB, _T("Display the appropriate help page")));
  579. if(_pContainerWnd->GetWndHandle())
  580. {
  581. #ifndef OS_WINCE
  582. _pSh->SH_DisplayClientHelp(
  583. _pContainerWnd->GetWndHandle(),
  584. HH_DISPLAY_TOPIC);
  585. #endif // OS_WINCE
  586. }
  587. }
  588. break;
  589. case ID_BUTTON_OPTIONS:
  590. {
  591. //
  592. // Need to do the switch to/from the expanded dialog
  593. //
  594. ToggleExpandedState();
  595. }
  596. break;
  597. case IDC_NEXTTAB:
  598. case IDC_PREVTAB:
  599. {
  600. //
  601. // Only allow toggle of UI tabs while not connected
  602. // since in the connecting state the UI elements other
  603. // than the cancel button are meant to be disabled
  604. //
  605. if(_fShowExpanded && (_connectionState == stateNotConnected))
  606. {
  607. int iSel = TabCtrl_GetCurSel( GetDlgItem( _hwndDlg, IDC_TABS));
  608. iSel += (DC_GET_WM_COMMAND_ID(wParam) == IDC_NEXTTAB) ? 1 : -1;
  609. if(iSel >= NUM_TABS)
  610. {
  611. iSel = 0;
  612. }
  613. else if(iSel < 0)
  614. {
  615. iSel = NUM_TABS - 1;
  616. }
  617. TabCtrl_SetCurSel( GetDlgItem( _hwndDlg, IDC_TABS), iSel);
  618. //SetCurSel does not send a TCN_SELCHANGE
  619. OnTabSelChange();
  620. }
  621. }
  622. break;
  623. case IDC_COMBO_SERVERS:
  624. {
  625. //
  626. // Bring up the brwse for servers dlg
  627. // if the user chose the last item in the combo
  628. //
  629. if(HIWORD(wParam) == CBN_SELCHANGE)
  630. {
  631. CSH::HandleServerComboChange(
  632. (HWND)lParam,
  633. hwndDlg,
  634. _hInstance,
  635. (LPTSTR)_pTscSettings->GetFlatConnectString()
  636. );
  637. }
  638. }
  639. break;
  640. }
  641. }
  642. break; //WM_COMMAND
  643. //
  644. // tab notification
  645. //
  646. case WM_NOTIFY:
  647. {
  648. LPNMHDR pnmh = (LPNMHDR) lParam;
  649. if(pnmh)
  650. {
  651. switch( pnmh->code)
  652. {
  653. case TCN_SELCHANGE:
  654. {
  655. OnTabSelChange();
  656. }
  657. break;
  658. }
  659. }
  660. }
  661. break;
  662. case WM_SYSCOMMAND:
  663. {
  664. if(UI_IDM_ABOUT == DC_GET_WM_COMMAND_ID(wParam))
  665. {
  666. // Show the about box dialog
  667. CAboutDlg aboutDialog( hwndDlg, _hInstance,
  668. _pSh->GetCipherStrength(),
  669. _pSh->GetControlVersionString());
  670. aboutDialog.DoModal();
  671. }
  672. }
  673. break;
  674. case WM_UPDATEFROMSETTINGS:
  675. {
  676. SettingsToDlg();
  677. //
  678. // Update the server MRU list
  679. //
  680. HWND hwndSrvCombo = GetDlgItem(hwndDlg, IDC_COMBO_SERVERS);
  681. CSH::InitServerAutoCmplCombo( _pTscSettings, hwndSrvCombo);
  682. SetWindowText(
  683. hwndSrvCombo,
  684. _pTscSettings->GetFlatConnectString()
  685. );
  686. if(_fShowExpanded && _tabDlgInfo.hwndCurPropPage)
  687. {
  688. SendMessage(_tabDlgInfo.hwndCurPropPage, WM_INITDIALOG, 0, 0);
  689. }
  690. }
  691. break;
  692. case WM_SETTINGCHANGE: //fall thru
  693. case WM_SYSCOLORCHANGE: //fall thru
  694. #ifndef OS_WINCE
  695. case WM_DISPLAYCHANGE: //fall thru
  696. #endif
  697. {
  698. UINT screenBpp = CSH::SH_GetScreenBpp();
  699. if(_lastValidBpp != screenBpp)
  700. {
  701. //Screen color depth changed
  702. TRC_NRM((TB,_T("Detected color depth change from:%d to %d"),
  703. _lastValidBpp, screenBpp));
  704. #ifndef OS_WINCE
  705. //
  706. // Reload the bitmaps
  707. //
  708. TRC_NRM((TB,_T("Reloading images")));
  709. if (_pProgBand) {
  710. if (!_pProgBand->ReLoadBmps()) {
  711. TRC_ERR((TB,_T("ReLoadBitmaps failed")));
  712. }
  713. }
  714. if(InitializeBmps()) {
  715. //trigger a repaint
  716. InvalidateRect( _hwndDlg, NULL, TRUE);
  717. }
  718. else {
  719. TRC_ERR((TB,_T("InitializeBmps failed")));
  720. }
  721. #endif
  722. }
  723. PropagateMsgToChildren(hwndDlg, uMsg, wParam, lParam);
  724. }
  725. break;
  726. #ifndef OS_WINCE
  727. case WM_QUERYNEWPALETTE:
  728. {
  729. rc = BrandingQueryNewPalette(hwndDlg);
  730. InvalidateRect(hwndDlg, NULL, TRUE);
  731. UpdateWindow(hwndDlg);
  732. }
  733. break;
  734. case WM_PALETTECHANGED:
  735. {
  736. rc = BrandingPaletteChanged(hwndDlg, (HWND)wParam);
  737. InvalidateRect(hwndDlg, NULL, TRUE);
  738. UpdateWindow(hwndDlg);
  739. }
  740. break;
  741. #endif
  742. case WM_HELP:
  743. {
  744. _pSh->SH_DisplayClientHelp(
  745. hwndDlg,
  746. HH_DISPLAY_TOPIC);
  747. }
  748. break;
  749. case WM_DESTROY:
  750. {
  751. if (_hBrandPal)
  752. {
  753. DeleteObject(_hBrandPal);
  754. _hBrandPal = NULL;
  755. }
  756. if (_hBrandImg)
  757. {
  758. DeleteObject(_hBrandImg);
  759. _hBrandImg = NULL;
  760. }
  761. }
  762. break;
  763. default:
  764. {
  765. rc = CDlgBase::DialogBoxProc(hwndDlg,
  766. uMsg,
  767. wParam,
  768. lParam);
  769. }
  770. break;
  771. }
  772. DC_END_FN();
  773. return(rc);
  774. } /* UILogonDialogBox */
  775. //
  776. // save from UI->tscSettings
  777. //
  778. void CMainDlg::DlgToSettings()
  779. {
  780. TCHAR szServer[SH_MAX_ADDRESS_LENGTH];
  781. int optLevel = 0;
  782. DC_BEGIN_FN("DlgToSettings");
  783. TRC_ASSERT(_pTscSettings, (TB,_T("_pTscSettings is null")));
  784. TRC_ASSERT(_hwndDlg, (TB,_T("_hwndDlg is null")));
  785. //
  786. // Get the server
  787. //
  788. GetDlgItemText( _hwndDlg, IDC_COMBO_SERVERS,
  789. szServer, SIZECHAR(szServer));
  790. _pTscSettings->SetConnectString(szServer);
  791. DC_END_FN();
  792. }
  793. //
  794. // save from UI->tscSettings
  795. //
  796. void CMainDlg::SettingsToDlg()
  797. {
  798. DC_BEGIN_FN("SettingsToDlg");
  799. TRC_ASSERT(_pTscSettings, (TB,_T("_pTscSettings is null")));
  800. TRC_ASSERT(_hwndDlg, (TB,_T("_hwndDlg is null")));
  801. SetDlgItemText(_hwndDlg, IDC_COMBO_SERVERS,
  802. (LPCTSTR) _pTscSettings->GetFlatConnectString());
  803. DC_END_FN();
  804. }
  805. //
  806. // Toggles the expanded state of the dialog
  807. //
  808. void CMainDlg::ToggleExpandedState()
  809. {
  810. DC_BEGIN_FN("ToggleExpandedState");
  811. WINDOWPLACEMENT wndPlc;
  812. wndPlc.length = sizeof(WINDOWPLACEMENT);
  813. _fShowExpanded = !_fShowExpanded;
  814. #ifndef OS_WINCE
  815. //
  816. // Expand/contract the dlg height
  817. //
  818. GetWindowPlacement( _hwndDlg, &wndPlc);
  819. int cx = wndPlc.rcNormalPosition.right - wndPlc.rcNormalPosition.left;
  820. int cy = wndPlc.rcNormalPosition.bottom - wndPlc.rcNormalPosition.top;
  821. #else
  822. RECT wndRect;
  823. GetWindowRect(_hwndDlg, &wndRect);
  824. int cx = wndRect.right - wndRect.left;
  825. int cy = wndRect.bottom - wndRect.top;
  826. #endif
  827. #ifndef OS_WINCE
  828. int dlgExpDlu = LOGON_DLG_EXPAND_AMOUNT;
  829. #else
  830. int dlgExpDlu = (_fVgaDisplay) ? LOGON_DLG_EXPAND_AMOUNT_VGA : LOGON_DLG_EXPAND_AMOUNT;
  831. #endif
  832. RECT rc;
  833. rc.left = 0;
  834. rc.right = 100; //don't care about horiz, dummy vals
  835. rc.top = 0;
  836. rc.bottom = dlgExpDlu;
  837. if(!MapDialogRect(_hwndDlg, &rc))
  838. {
  839. TRC_ASSERT(NULL,(TB,_T("MapDialogRect failed")));
  840. }
  841. int dlgExpandAmountPels = rc.bottom - rc.top;
  842. //
  843. // Compute the dialog vertical expand amount in pixels
  844. // given a dlu based expand size
  845. //
  846. cy += _fShowExpanded ? dlgExpandAmountPels : -dlgExpandAmountPels;
  847. SetWindowPos( _hwndDlg, NULL, 0, 0, cx, cy,
  848. SWP_NOMOVE | SWP_NOZORDER);
  849. //
  850. // Reposition the controls that need to be moved
  851. //
  852. RepositionControls( 0, _fShowExpanded ? dlgExpandAmountPels :
  853. -dlgExpandAmountPels,
  854. moveableControls, numMoveableControls);
  855. if(_fShowExpanded)
  856. {
  857. //we're going expanded save to settings so more
  858. //tab can initiliaze from most recent values.
  859. //must happen before tab sel change (prop pg init)
  860. DlgToSettings();
  861. }
  862. //
  863. // Kill/activate prop page on tab dlg
  864. //
  865. OnTabSelChange();
  866. if(!_fShowExpanded)
  867. {
  868. //going to less mode, init dialog with settings
  869. SettingsToDlg();
  870. }
  871. //
  872. // Options button text
  873. //
  874. SetWindowText(GetDlgItem(_hwndDlg,ID_BUTTON_OPTIONS),
  875. _fShowExpanded ? _szOptionsLess : _szOptionsMore);
  876. //
  877. // Disable+Hide uneeded UI for this mode
  878. //
  879. EnableControls(lessUI, numLessUI, !_fShowExpanded);
  880. EnableControls(moreUI, numMoreUI, _fShowExpanded);
  881. SetFocus(GetDlgItem(_hwndDlg,ID_BUTTON_OPTIONS));
  882. DC_END_FN();
  883. }
  884. //
  885. // Initialize the tabs on the main dialog
  886. //
  887. BOOL CMainDlg::InitTabs()
  888. {
  889. TCITEM tie;
  890. #ifndef OS_WINCE
  891. INITCOMMONCONTROLSEX cex;
  892. RECT rcTabDims;
  893. #endif
  894. POINT tabDims;
  895. int ret = -1;
  896. DC_BEGIN_FN("InitTabs");
  897. if(!_hwndDlg)
  898. {
  899. return FALSE;
  900. }
  901. HWND hwndTab = GetDlgItem( _hwndDlg, IDC_TABS);
  902. if(!hwndTab)
  903. {
  904. return FALSE;
  905. }
  906. #ifndef OS_WINCE
  907. cex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  908. cex.dwICC = ICC_TAB_CLASSES;
  909. if(!InitCommonControlsEx( &cex ))
  910. {
  911. TRC_ABORT((TB,_T("InitCommonControlsEx failed 0x%x"),
  912. GetLastError()));
  913. }
  914. #endif
  915. _pGeneralPg = new CPropGeneral(_hInstance, _pTscSettings, _pSh);
  916. if(!_pGeneralPg)
  917. {
  918. return FALSE;
  919. }
  920. _pLocalResPg = new CPropLocalRes(_hInstance, _pTscSettings, _pSh);
  921. if(!_pLocalResPg)
  922. {
  923. return FALSE;
  924. }
  925. _pPropDisplayPg = new CPropDisplay(_hInstance, _pTscSettings, _pSh);
  926. if(!_pPropDisplayPg)
  927. {
  928. return FALSE;
  929. }
  930. _pRunPg = new CPropRun(_hInstance, _pTscSettings, _pSh);
  931. if(!_pRunPg)
  932. {
  933. return FALSE;
  934. }
  935. _pPerfPg = new CPropPerf(_hInstance, _pTscSettings, _pSh);
  936. if(!_pPerfPg)
  937. {
  938. return FALSE;
  939. }
  940. tie.mask = TCIF_TEXT | TCIF_IMAGE;
  941. tie.iImage = -1;
  942. TCHAR szTabName[MAX_PATH];
  943. //general tab
  944. if (!LoadString( _hInstance,
  945. UI_IDS_GENERAL_TAB_NAME,
  946. szTabName,
  947. SIZECHAR(szTabName) ))
  948. {
  949. return FALSE;
  950. }
  951. tie.pszText = szTabName;
  952. ret = TabCtrl_InsertItem( hwndTab, 0, &tie);
  953. TRC_ASSERT(ret != -1,
  954. (TB,_T("TabCtrl_InsertItem failed %d"),
  955. GetLastError()));
  956. //display tab
  957. if (!LoadString( _hInstance,
  958. UI_IDS_DISPLAY_TAB_NAME,
  959. szTabName,
  960. SIZECHAR(szTabName)))
  961. {
  962. return FALSE;
  963. }
  964. tie.pszText = szTabName;
  965. ret = TabCtrl_InsertItem( hwndTab, 1, &tie);
  966. TRC_ASSERT(ret != -1,
  967. (TB,_T("TabCtrl_InsertItem failed %d"),
  968. GetLastError()));
  969. //local resources tab
  970. if (!LoadString( _hInstance,
  971. UI_IDS_LOCAL_RESOURCES_TAB_NAME,
  972. szTabName,
  973. SIZECHAR(szTabName)))
  974. {
  975. return FALSE;
  976. }
  977. tie.pszText = szTabName;
  978. ret = TabCtrl_InsertItem( hwndTab, 2, &tie);
  979. TRC_ASSERT(ret != -1,
  980. (TB,_T("TabCtrl_InsertItem failed %d"),
  981. GetLastError()));
  982. //run tab
  983. if (!LoadString( _hInstance,
  984. UI_IDS_RUN_TAB_NAME,
  985. szTabName,
  986. SIZECHAR(szTabName)))
  987. {
  988. return FALSE;
  989. }
  990. tie.pszText = szTabName;
  991. ret = TabCtrl_InsertItem( hwndTab, 3, &tie);
  992. TRC_ASSERT(ret != -1,
  993. (TB,_T("TabCtrl_InsertItem failed %d"),
  994. GetLastError()));
  995. //advanced tab
  996. if (!LoadString( _hInstance,
  997. UI_IDS_PERF_TAB_NAME,
  998. szTabName,
  999. SIZECHAR(szTabName)))
  1000. {
  1001. return FALSE;
  1002. }
  1003. tie.pszText = szTabName;
  1004. ret = TabCtrl_InsertItem( hwndTab, 4, &tie);
  1005. TRC_ASSERT(ret != -1,
  1006. (TB,_T("TabCtrl_InsertItem failed %d"),
  1007. GetLastError()));
  1008. //
  1009. // Determine bounding rect for child dialogs
  1010. //
  1011. #ifndef OS_WINCE
  1012. RECT winRect;
  1013. #endif
  1014. GetWindowRect( hwndTab ,&_rcTab);
  1015. TabCtrl_AdjustRect( hwndTab, FALSE, &_rcTab);
  1016. MapWindowPoints( NULL, _hwndDlg, (LPPOINT)&_rcTab, 2);
  1017. tabDims.x = _rcTab.right - _rcTab.left;
  1018. tabDims.y = _rcTab.bottom - _rcTab.top;
  1019. _tabDlgInfo.pdlgTmpl[0] = DoLockDlgRes(MAKEINTRESOURCE(UI_IDD_PROPPAGE_GENERAL));
  1020. _tabDlgInfo.pDlgProc[0] = CPropGeneral::StaticPropPgGeneralDialogProc;
  1021. _tabDlgInfo.pdlgTmpl[1] = DoLockDlgRes(MAKEINTRESOURCE(UI_IDD_PROPPAGE_DISPLAY));
  1022. _tabDlgInfo.pDlgProc[1] = CPropDisplay::StaticPropPgDisplayDialogProc;
  1023. _tabDlgInfo.pdlgTmpl[2] = DoLockDlgRes(MAKEINTRESOURCE(UI_IDD_PROPPAGE_LOCALRESOURCES));
  1024. _tabDlgInfo.pDlgProc[2] = CPropLocalRes::StaticPropPgLocalResDialogProc;
  1025. _tabDlgInfo.pdlgTmpl[3] = DoLockDlgRes(MAKEINTRESOURCE(UI_IDD_PROPPAGE_RUN));
  1026. _tabDlgInfo.pDlgProc[3] = CPropRun::StaticPropPgRunDialogProc;
  1027. _tabDlgInfo.pdlgTmpl[4] = DoLockDlgRes(MAKEINTRESOURCE(UI_IDD_PROPPAGE_PERF));
  1028. _tabDlgInfo.pDlgProc[4] = CPropPerf::StaticPropPgPerfDialogProc;
  1029. #ifdef OS_WINCE
  1030. if (_fVgaDisplay)
  1031. {
  1032. _tabDlgInfo.pdlgTmpl[0] = DoLockDlgRes(MAKEINTRESOURCE(UI_IDD_PROPPAGE_GENERAL_VGA));
  1033. _tabDlgInfo.pdlgTmpl[1] = DoLockDlgRes(MAKEINTRESOURCE(UI_IDD_PROPPAGE_DISPLAY_VGA));
  1034. _tabDlgInfo.pdlgTmpl[2] = DoLockDlgRes(MAKEINTRESOURCE(UI_IDD_PROPPAGE_LOCALRESOURCES_VGA));
  1035. _tabDlgInfo.pdlgTmpl[3] = DoLockDlgRes(MAKEINTRESOURCE(UI_IDD_PROPPAGE_RUN_VGA));
  1036. _tabDlgInfo.pdlgTmpl[4] = DoLockDlgRes(MAKEINTRESOURCE(UI_IDD_PROPPAGE_PERF_VGA));
  1037. }
  1038. #endif
  1039. _tabDlgInfo.hwndCurPropPage = NULL;
  1040. _pGeneralPg->SetTabDisplayArea(_rcTab);
  1041. _pPropDisplayPg->SetTabDisplayArea(_rcTab);
  1042. _pLocalResPg->SetTabDisplayArea(_rcTab);
  1043. _pRunPg->SetTabDisplayArea(_rcTab);
  1044. _pPerfPg->SetTabDisplayArea(_rcTab);
  1045. //
  1046. // Trigger first tab selection
  1047. //
  1048. OnTabSelChange();
  1049. DC_END_FN();
  1050. return TRUE;
  1051. }
  1052. //
  1053. // Tab selection has changed
  1054. //
  1055. BOOL CMainDlg::OnTabSelChange()
  1056. {
  1057. DC_BEGIN_FN("OnTabSelChange");
  1058. int iSel = TabCtrl_GetCurSel( GetDlgItem( _hwndDlg, IDC_TABS));
  1059. //
  1060. // Destroy current child dialog if any
  1061. //
  1062. TRC_ASSERT( iSel >=0 && iSel < NUM_TABS,
  1063. (TB,_T("Tab selection out of range %d"), iSel));
  1064. if(iSel < 0 || iSel > NUM_TABS)
  1065. {
  1066. return FALSE;
  1067. }
  1068. if(_tabDlgInfo.hwndCurPropPage)
  1069. {
  1070. DestroyWindow(_tabDlgInfo.hwndCurPropPage);
  1071. }
  1072. //
  1073. // Only bring in a new tab if we are in expanded mode
  1074. //
  1075. if(_fShowExpanded)
  1076. {
  1077. _tabDlgInfo.hwndCurPropPage =
  1078. CreateDialogIndirect( _hInstance, _tabDlgInfo.pdlgTmpl[iSel],
  1079. _hwndDlg, _tabDlgInfo.pDlgProc[iSel]);
  1080. ShowWindow(_tabDlgInfo.hwndCurPropPage, SW_SHOW);
  1081. #ifdef OS_WINCE
  1082. SetFocus (GetDlgItem (_hwndDlg, IDOK));
  1083. #endif
  1084. }
  1085. DC_END_FN();
  1086. return TRUE;
  1087. }
  1088. #ifndef OS_WINCE
  1089. //
  1090. // Add an 'About' entry to the dialog's system menu
  1091. //
  1092. void CMainDlg::SetupDialogSysMenu()
  1093. {
  1094. DC_BEGIN_FN("SetupDialogSysMenu");
  1095. HANDLE hSystemMenu = GetSystemMenu(_hwndDlg, FALSE);
  1096. DCTCHAR menuStr[SH_SHORT_STRING_MAX_LENGTH];
  1097. if(hSystemMenu)
  1098. {
  1099. //
  1100. // Disable sizing and maximizing
  1101. //
  1102. EnableMenuItem((HMENU)hSystemMenu, SC_MAXIMIZE,
  1103. MF_GRAYED | MF_BYCOMMAND);
  1104. EnableMenuItem((HMENU)hSystemMenu, SC_SIZE,
  1105. MF_GRAYED | MF_BYCOMMAND);
  1106. //load the string for the about help sub menu
  1107. if (LoadString(_hInstance,
  1108. UI_MENU_ABOUT,
  1109. menuStr,
  1110. SH_SHORT_STRING_MAX_LENGTH) != 0)
  1111. {
  1112. AppendMenu((HMENU)hSystemMenu, MF_UNCHECKED|MF_STRING, UI_IDM_ABOUT,
  1113. menuStr);
  1114. }
  1115. else
  1116. {
  1117. //failed to load the sub menu string
  1118. TRC_ERR((TB, _T("Failed to load About Help Sub Menu string ID:%u"),
  1119. UI_MENU_ABOUT));
  1120. }
  1121. }
  1122. DC_END_FN();
  1123. }
  1124. #endif // OS_WINCE
  1125. //
  1126. // Load the image returning the given HBITMAP, having done this we can
  1127. // then get the size from it.
  1128. //
  1129. // In:
  1130. // hInstance,resid - object to be loaded.
  1131. // pSize - filled with size information about the object
  1132. //
  1133. // Out:
  1134. // HBITMAP - NULL if nothing loaded
  1135. //
  1136. HBITMAP CMainDlg::LoadBitmapGetSize(HINSTANCE hInstance,UINT resid,SIZE* pSize)
  1137. {
  1138. HBITMAP hResult = NULL;
  1139. DIBSECTION ds = {0};
  1140. //
  1141. // Load the image from the resource then lets get the DIBSECTION header
  1142. // from the bitmap object we can then read the size from it and
  1143. // return that to the caller.
  1144. //
  1145. #ifndef OS_WINCE
  1146. hResult = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(resid),
  1147. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  1148. #else
  1149. hResult = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(resid),
  1150. IMAGE_BITMAP, 0, 0, 0);
  1151. #endif
  1152. if ( hResult )
  1153. {
  1154. GetObject(hResult, sizeof(ds), &ds);
  1155. pSize->cx = ds.dsBmih.biWidth;
  1156. pSize->cy = ds.dsBmih.biHeight;
  1157. //
  1158. // pSize->cy -ve then make +ve, -ve indicates bits are vertically
  1159. // flipped (bottom left, top left).
  1160. //
  1161. if ( pSize->cy < 0 )
  1162. pSize->cy -= 0;
  1163. }
  1164. return hResult;
  1165. }
  1166. #ifndef OS_WINCE
  1167. BOOL CMainDlg::PaintBrandImage(HWND hwnd,
  1168. HDC hDC,
  1169. INT bgColor)
  1170. {
  1171. DC_BEGIN_FN("PaintBrandImage");
  1172. HBRUSH hBrushBlue;
  1173. HDC hdcBitmap;
  1174. HBITMAP oldBitmap;
  1175. RECT rc = { 0 };
  1176. INT cxRect, cxBand;
  1177. HBITMAP* phbmBrand;
  1178. hdcBitmap = CreateCompatibleDC(hDC);
  1179. if (!hdcBitmap)
  1180. {
  1181. return FALSE;
  1182. }
  1183. GetClientRect(hwnd, &rc);
  1184. HBRUSH hbrBg;
  1185. //Repaint the rest of the background
  1186. //First the portion under the band
  1187. rc.top = _nBrandImageHeight;
  1188. if (_pProgBand) {
  1189. rc.top += _pProgBand->GetBandHeight();
  1190. }
  1191. FillRect(hDC, &rc, (HBRUSH)IntToPtr(1+bgColor));
  1192. //
  1193. // Now paint the brand image
  1194. //
  1195. if (_hBrandImg)
  1196. {
  1197. SelectObject(hdcBitmap, _hBrandImg);
  1198. BitBlt(hDC, 0, 0, _nBrandImageWidth,
  1199. _nBrandImageHeight, hdcBitmap,
  1200. 0,0,SRCCOPY);
  1201. }
  1202. DeleteDC(hdcBitmap);
  1203. DC_END_FN();
  1204. return TRUE;
  1205. }
  1206. #endif
  1207. BOOL CMainDlg::OnStartConnection()
  1208. {
  1209. DC_BEGIN_FN("OnStartConnection");
  1210. TRC_ASSERT(stateNotConnected == _connectionState,
  1211. (TB,_T("Start connecting while already connecting. State %d"),
  1212. _connectionState));
  1213. SetConnectionState( stateConnecting );
  1214. #ifndef OS_WINCE
  1215. //Kick off the progress band animation timer
  1216. if (_pProgBand) {
  1217. _pProgBand->StartSpinning();
  1218. }
  1219. #endif
  1220. //
  1221. // Change the cancel dialog button text to "Cancel"
  1222. // to abort the connection
  1223. //
  1224. SetDlgItemText( _hwndDlg, IDCANCEL, _szCancelText);
  1225. _hwndRestoreFocus = SetFocus(GetDlgItem( _hwndDlg, IDCANCEL));
  1226. CSH::EnableControls( _hwndDlg,
  1227. connectingDisableControls,
  1228. numConnectingDisableControls,
  1229. FALSE );
  1230. //
  1231. // Inform the current property page
  1232. // to disable all it's controls
  1233. //
  1234. if(_fShowExpanded && _tabDlgInfo.hwndCurPropPage)
  1235. {
  1236. SendMessage(_tabDlgInfo.hwndCurPropPage,
  1237. WM_TSC_ENABLECONTROLS,
  1238. FALSE, //disable controls
  1239. 0);
  1240. }
  1241. DC_END_FN();
  1242. return TRUE;
  1243. }
  1244. //
  1245. // Event that fires when the process of connecting ends
  1246. // fConnected - flag that is TRUE if we are now connected
  1247. // FALSE if we are now disconnected (e.g if
  1248. // if the connection failed.
  1249. //
  1250. BOOL CMainDlg::OnEndConnection(BOOL fConnected)
  1251. {
  1252. DC_BEGIN_FN("OnEndConnection");
  1253. //
  1254. // If we're already disconnected then do nothing
  1255. // e.g EndConnecting can be called once to indicate
  1256. // successful connection and then again on disconnection
  1257. //
  1258. if( stateNotConnected != _connectionState)
  1259. {
  1260. if (fConnected)
  1261. {
  1262. SetConnectionState( stateConnected );
  1263. }
  1264. else
  1265. {
  1266. SetConnectionState( stateNotConnected );
  1267. }
  1268. #ifndef OS_WINCE
  1269. //
  1270. // End the animation
  1271. //
  1272. if (_pProgBand) {
  1273. _pProgBand->StopSpinning();
  1274. }
  1275. #endif
  1276. //
  1277. // Change the cancel dialog button text to "Close"
  1278. // because we have connected at least once
  1279. //
  1280. SetDlgItemText( _hwndDlg, IDCANCEL, _szCloseText);
  1281. #ifndef OS_WINCE
  1282. // Reset band offset
  1283. if (_pProgBand) {
  1284. _pProgBand->ResetBandOffset();
  1285. }
  1286. #endif
  1287. CSH::EnableControls( _hwndDlg,
  1288. connectingDisableControls,
  1289. numConnectingDisableControls,
  1290. TRUE );
  1291. //
  1292. // Inform the current property page
  1293. // to renable all controls it needs enabled
  1294. //
  1295. if(_fShowExpanded && _tabDlgInfo.hwndCurPropPage)
  1296. {
  1297. SendMessage(_tabDlgInfo.hwndCurPropPage,
  1298. WM_TSC_ENABLECONTROLS,
  1299. TRUE, //enable controls
  1300. 0);
  1301. }
  1302. //
  1303. // Make sure to correctly disable or enable
  1304. // less UI items to prevent mnemomincs (e.g ALT-C)
  1305. // leaking thru to the non-expanded dialog
  1306. //
  1307. CSH::EnableControls(_hwndDlg, lessUI, numLessUI,
  1308. !_fShowExpanded);
  1309. //
  1310. // Trigger a repaint to reposition the bar
  1311. //
  1312. InvalidateRect( _hwndDlg, NULL, TRUE);
  1313. //
  1314. // If we just went disconnected (fConnected is false)
  1315. // then restore the focus to the control that
  1316. // had it before the connection
  1317. //
  1318. if (!fConnected && _hwndRestoreFocus)
  1319. {
  1320. SetFocus(_hwndRestoreFocus);
  1321. }
  1322. }
  1323. DC_END_FN();
  1324. return TRUE;
  1325. }
  1326. VOID CMainDlg::SetConnectionState(mainDlgConnectionState newState)
  1327. {
  1328. DC_BEGIN_FN("SetConnectionState");
  1329. TRC_NRM((TB,_T("Prev state = %d. New State = %d"),
  1330. _connectionState, newState ));
  1331. _connectionState = newState;
  1332. DC_END_FN();
  1333. }
  1334. #ifndef OS_WINCE
  1335. BOOL CMainDlg::PaintBrandingText(HBITMAP hbmBrandImage)
  1336. {
  1337. HDC hdcBitmap;
  1338. HBITMAP hbmOld;
  1339. RECT rc;
  1340. COLORREF oldCol;
  1341. INT oldMode;
  1342. RECT textRc;
  1343. INT textHeight = 0;
  1344. TCHAR szBrandLine1[MAX_PATH];
  1345. TCHAR szBrandLine2[MAX_PATH];
  1346. TCHAR szLineDelta[20];
  1347. HFONT hOldFont = NULL;
  1348. HFONT hFontBrandLine1 = NULL;
  1349. HFONT hFontBrandLine2 = NULL;
  1350. BOOL bRet = FALSE;
  1351. INT rightEdge = 0;
  1352. INT nTextLineDelta = 0;
  1353. UINT dtTextAlign = DT_LEFT;
  1354. //
  1355. // These values determined based on the branding
  1356. // bitmap, they are constant and don't change with
  1357. // font sizes. But if the branding bitmap is updated
  1358. // the values may need to be tweaked
  1359. //
  1360. static const int TextLine1Top = 8;
  1361. static const int TextLine1Left = 80;
  1362. static const int TextLineDistFromRightEdge = 20;
  1363. static const int TextLineDelta = 5;
  1364. DC_BEGIN_FN("PaintBrandingText");
  1365. if(!LoadString( _hInstance, UI_IDS_BRANDING_LINE1,
  1366. szBrandLine1, SIZECHAR(szBrandLine1) ))
  1367. {
  1368. TRC_ERR((TB,_T("LoadString for UI_IDS_BRANDING_LINE1 failed 0x%x"),
  1369. GetLastError()));
  1370. return FALSE;
  1371. }
  1372. if(!LoadString( _hInstance, UI_IDS_BRANDING_LINE2,
  1373. szBrandLine2, SIZECHAR(szBrandLine2)))
  1374. {
  1375. TRC_ERR((TB,_T("LoadString for UI_IDS_BRANDING_LINE2 failed 0x%x"),
  1376. GetLastError()));
  1377. return FALSE;
  1378. }
  1379. //
  1380. // Figure out if this is Bidi, if so flip text alignment
  1381. //
  1382. if (GetWindowLongPtr(_hwndDlg, GWL_EXSTYLE) & WS_EX_LAYOUTRTL)
  1383. {
  1384. TRC_NRM((TB,_T("RTL layout detected, flip text alignment")));
  1385. dtTextAlign = DT_RIGHT;
  1386. }
  1387. else
  1388. {
  1389. dtTextAlign = DT_LEFT;
  1390. }
  1391. hFontBrandLine1 = LoadFontFromResourceInfo( UI_IDS_BRANDING_LN1FONT,
  1392. UI_IDS_BRANDING_LN1SIZE,
  1393. FALSE );
  1394. if(!hFontBrandLine1)
  1395. {
  1396. TRC_ERR((TB,_T("LoadFontFromResourceInfo for brandln1 failed")));
  1397. DC_QUIT;
  1398. }
  1399. hFontBrandLine2 = LoadFontFromResourceInfo( UI_IDS_BRANDING_LN2FONT,
  1400. UI_IDS_BRANDING_LN2SIZE,
  1401. TRUE );
  1402. if(!hFontBrandLine2)
  1403. {
  1404. TRC_ERR((TB,_T("LoadFontFromResourceInfo for brandln1 failed")));
  1405. DC_QUIT;
  1406. }
  1407. if (LoadString( _hInstance, UI_IDS_LINESPACING_DELTA,
  1408. szLineDelta, SIZECHAR(szLineDelta)))
  1409. {
  1410. nTextLineDelta = _ttol(szLineDelta);
  1411. }
  1412. else
  1413. {
  1414. TRC_ERR((TB,_T("Failed to load text line delta using default")));
  1415. nTextLineDelta = TextLineDelta;
  1416. }
  1417. hdcBitmap = CreateCompatibleDC(NULL);
  1418. if(hdcBitmap)
  1419. {
  1420. hbmOld = (HBITMAP)SelectObject(hdcBitmap, hbmBrandImage);
  1421. hOldFont = (HFONT)SelectObject( hdcBitmap, hFontBrandLine1);
  1422. // Set text transparency and color
  1423. //White text
  1424. SetTextColor(hdcBitmap, RGB(255,255,255));
  1425. SetBkMode(hdcBitmap, TRANSPARENT);
  1426. SetMapMode(hdcBitmap, MM_TEXT);
  1427. GetClientRect( _hwndDlg, &rc );
  1428. rightEdge = min(_nBrandImageWidth, rc.right);
  1429. textRc.right = rightEdge - TextLineDistFromRightEdge;
  1430. textRc.top = TextLine1Top;
  1431. textRc.bottom = 40;
  1432. textRc.left = TextLine1Left;
  1433. //
  1434. // Draw first branding line
  1435. //
  1436. textHeight = DrawText(hdcBitmap,
  1437. szBrandLine1,
  1438. _tcslen(szBrandLine1),
  1439. &textRc, //rect
  1440. dtTextAlign);
  1441. if(!textHeight)
  1442. {
  1443. TRC_ERR((TB,_T("DrawText for brand line1 failed 0x%x"),
  1444. GetLastError()));
  1445. }
  1446. textRc.top += textHeight - nTextLineDelta;
  1447. textRc.bottom += textHeight - nTextLineDelta;
  1448. SelectObject( hdcBitmap, hFontBrandLine2);
  1449. //
  1450. // Draw second branding line
  1451. //
  1452. textHeight = DrawText(hdcBitmap,
  1453. szBrandLine2,
  1454. _tcslen(szBrandLine2),
  1455. &textRc, //rect
  1456. dtTextAlign);
  1457. if(!textHeight)
  1458. {
  1459. TRC_ERR((TB,_T("DrawText for brand line1 failed 0x%x"),
  1460. GetLastError()));
  1461. }
  1462. SelectObject( hdcBitmap, hOldFont );
  1463. SelectObject(hdcBitmap, hbmOld);
  1464. DeleteDC(hdcBitmap);
  1465. bRet = TRUE;
  1466. }
  1467. else
  1468. {
  1469. DC_QUIT;
  1470. }
  1471. DC_EXIT_POINT:
  1472. DC_END_FN();
  1473. if(hFontBrandLine1)
  1474. {
  1475. DeleteObject( hFontBrandLine1 );
  1476. }
  1477. if(hFontBrandLine2)
  1478. {
  1479. DeleteObject( hFontBrandLine2 );
  1480. }
  1481. return bRet;
  1482. }
  1483. #endif
  1484. void CMainDlg::SetFontFaceFromResource(PLOGFONT plf, UINT idFaceName)
  1485. {
  1486. DC_BEGIN_FN("SetFontFaceFromResource");
  1487. // Read the face name and point size from the resource file
  1488. if (LoadString(_hInstance, idFaceName, plf->lfFaceName, LF_FACESIZE) == 0)
  1489. {
  1490. _tcscpy(plf->lfFaceName, TEXT("Tahoma"));
  1491. TRC_ERR((TB,_T("Could not read welcome font face from resource")));
  1492. }
  1493. DC_END_FN();
  1494. }
  1495. //
  1496. // Note this is pixel size and not font size
  1497. //
  1498. void CMainDlg::SetFontSizeFromResource(PLOGFONT plf, UINT idSizeName)
  1499. {
  1500. DC_BEGIN_FN("SetFontFaceFromResource");
  1501. TCHAR szPixelSize[10];
  1502. LONG nSize;
  1503. if (LoadString(_hInstance, idSizeName, szPixelSize, SIZECHAR(szPixelSize)) != 0)
  1504. {
  1505. nSize = _ttol(szPixelSize);
  1506. }
  1507. else
  1508. {
  1509. // Make it really obvious something is wrong
  1510. nSize = 40;
  1511. }
  1512. plf->lfHeight = -nSize;
  1513. DC_END_FN();
  1514. }
  1515. #ifndef OS_WINCE
  1516. HFONT CMainDlg::LoadFontFromResourceInfo(UINT idFace, UINT idSize, BOOL fBold)
  1517. {
  1518. LOGFONT lf = {0};
  1519. CHARSETINFO csInfo;
  1520. HFONT hFont;
  1521. DC_BEGIN_FN("LoadFontFromResourceInfo");
  1522. lf.lfWidth = 0;
  1523. lf.lfWeight = fBold ? FW_HEAVY : FW_NORMAL;
  1524. lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
  1525. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  1526. lf.lfQuality = DEFAULT_QUALITY;
  1527. lf.lfPitchAndFamily = DEFAULT_PITCH;
  1528. // Set charset
  1529. if (TranslateCharsetInfo((LPDWORD)UIntToPtr(GetACP()), &csInfo,
  1530. TCI_SRCCODEPAGE) == 0)
  1531. {
  1532. TRC_ASSERT(0,(TB,_T("TranslateCharsetInfo failed")));
  1533. csInfo.ciCharset = 0;
  1534. }
  1535. lf.lfCharSet = (UCHAR)csInfo.ciCharset;
  1536. SetFontFaceFromResource(&lf, idFace);
  1537. SetFontSizeFromResource(&lf, idSize);
  1538. hFont = CreateFontIndirect(&lf);
  1539. TRC_ASSERT(hFont, (TB,_T("CreateFontIndirect failed")));
  1540. DC_END_FN();
  1541. return hFont;
  1542. }
  1543. #endif
  1544. //
  1545. // Propagates a message to all child windows
  1546. // used so common controls get notifications
  1547. // e.g of color changes
  1548. //
  1549. VOID CMainDlg::PropagateMsgToChildren(HWND hwndDlg,
  1550. UINT uMsg,
  1551. WPARAM wParam,
  1552. LPARAM lParam)
  1553. {
  1554. HWND hwndChild;
  1555. DC_BEGIN_FN("PropagateMsgToChildren");
  1556. for( hwndChild = GetWindow(hwndDlg, GW_CHILD);
  1557. hwndChild != NULL;
  1558. hwndChild = GetWindow(hwndChild, GW_HWNDNEXT) )
  1559. {
  1560. #ifdef DC_DEBUG
  1561. /* GetClassName doesn't have a uniwrap wrapper yet...
  1562. TCHAR szTmp[256];
  1563. GetClassName(hwndChild, szTmp, 256);
  1564. TRC_DBG((TB,
  1565. _T("PropagateMessage: ( 0x%08lX cls:%s, 0x%08X, 0x%08lX, 0x%08lX )\n"),
  1566. hwndChild, uMsg, wParam, lParam ));
  1567. */
  1568. #endif
  1569. SendMessage(hwndChild, uMsg, wParam, lParam);
  1570. }
  1571. DC_END_FN();
  1572. }
  1573. #ifndef OS_WINCE
  1574. //
  1575. // Initializes the images (branding and band bitmap)
  1576. // taking into account the current color depth.
  1577. //
  1578. // This function can be recalled if there is a color
  1579. // depth change
  1580. //
  1581. //
  1582. BOOL CMainDlg::InitializeBmps()
  1583. {
  1584. HBITMAP hbmBrandImage = NULL;
  1585. UINT screenBpp;
  1586. UINT imgResID;
  1587. HBITMAP hbmFromRsrc = NULL;
  1588. INT nBmpWidth = 0;
  1589. INT nBmpHeight = 0;
  1590. BOOL fDeepImgs = FALSE;
  1591. RECT rc;
  1592. INT nDlgWidth;
  1593. DC_BEGIN_FN("InitializeBmps");
  1594. //
  1595. // _hwndDlg should be set early in WM_INITDIALOG
  1596. //
  1597. TRC_ASSERT(_hwndDlg,
  1598. (TB,_T("_hwndDlg is null")));
  1599. screenBpp = CSH::SH_GetScreenBpp();
  1600. if (screenBpp <= 8)
  1601. {
  1602. _fUse16ColorBitmaps = TRUE;
  1603. imgResID = UI_IDB_BRANDIMAGE_16;
  1604. }
  1605. else
  1606. {
  1607. _fUse16ColorBitmaps = FALSE;
  1608. imgResID = UI_IDB_BRANDIMAGE;
  1609. }
  1610. GetClientRect( _hwndDlg, &rc );
  1611. nDlgWidth = rc.right - rc.left;
  1612. if (!nDlgWidth)
  1613. {
  1614. //
  1615. // We've seen cases in FUS where the client area is returned
  1616. // as 0. Be robust to that and just bail out of initilizing
  1617. // the bmp with a fail code
  1618. //
  1619. TRC_ERR((TB,_T("Got 0 client width")));
  1620. return FALSE;
  1621. }
  1622. if (screenBpp >= 8)
  1623. {
  1624. fDeepImgs = TRUE;
  1625. }
  1626. TRC_NRM((TB,_T("Use16 color bmp :%d. Img res id:%d"),
  1627. _fUse16ColorBitmaps,imgResID));
  1628. hbmFromRsrc = (HBITMAP)LoadImage(_hInstance,
  1629. MAKEINTRESOURCE(imgResID),IMAGE_BITMAP,
  1630. 0, 0, LR_CREATEDIBSECTION);
  1631. if (hbmFromRsrc)
  1632. {
  1633. //
  1634. // Figure out the dimensions of the resrc bmp
  1635. //
  1636. DIBSECTION ds = {0};
  1637. if (GetObject(hbmFromRsrc, sizeof(ds), &ds))
  1638. {
  1639. nBmpHeight = ds.dsBm.bmHeight;
  1640. if(nBmpHeight < 0)
  1641. {
  1642. nBmpHeight -= 0;
  1643. }
  1644. nBmpWidth = ds.dsBm.bmWidth;
  1645. }
  1646. //
  1647. // Create a new brand bitmap that spans
  1648. // the width of the dialog. This is necessary
  1649. // so that we can just set it up once e.g
  1650. // drawing branding text etc. The bitmap has to match
  1651. // the dialog width because on localized builds the dialog
  1652. // can be much wider than the resource version of the bitmap
  1653. // and the text can span a wider area.
  1654. //
  1655. HDC hDC = GetWindowDC(_hwndDlg);
  1656. if (hDC)
  1657. {
  1658. hbmBrandImage = CreateCompatibleBitmap(hDC,
  1659. nDlgWidth,
  1660. nBmpHeight);
  1661. HDC hMemDCSrc = CreateCompatibleDC(hDC);
  1662. HDC hMemDCDest = CreateCompatibleDC(hDC);
  1663. if (hMemDCSrc && hMemDCDest)
  1664. {
  1665. RECT rcFill;
  1666. RGBQUAD rgb[256];
  1667. HBITMAP hbmDestOld = NULL;
  1668. LPLOGPALETTE pLogPalette = NULL;
  1669. HPALETTE hScreenPalOld = NULL;
  1670. HPALETTE hMemPalOld = NULL;
  1671. UINT nCol = 0;
  1672. //
  1673. // Get brand img palette
  1674. //
  1675. _hBrandPal = CUT::UT_GetPaletteForBitmap(hDC, hbmFromRsrc);
  1676. if (_hBrandPal) {
  1677. hScreenPalOld = SelectPalette(hDC, _hBrandPal, FALSE);
  1678. hMemPalOld = SelectPalette(hMemDCDest, _hBrandPal, FALSE);
  1679. RealizePalette(hDC);
  1680. }
  1681. HBITMAP hbmSrcOld = (HBITMAP)SelectObject(
  1682. hMemDCSrc, hbmFromRsrc);
  1683. hbmDestOld = (HBITMAP)SelectObject(
  1684. hMemDCDest, hbmBrandImage);
  1685. rcFill.left = 0;
  1686. rcFill.top = 0;
  1687. rcFill.bottom = nBmpHeight;
  1688. rcFill.right = nDlgWidth;
  1689. HBRUSH hSolidBr = CreateSolidBrush(
  1690. _fUse16ColorBitmaps ? IMAGE_BG_COL_16 : IMAGE_BG_COL);
  1691. if (hSolidBr)
  1692. {
  1693. FillRect(hMemDCDest,
  1694. &rcFill,
  1695. hSolidBr);
  1696. DeleteObject( hSolidBr );
  1697. }
  1698. BitBlt(hMemDCDest, 0, 0, nDlgWidth, nBmpHeight,
  1699. hMemDCSrc, 0, 0, SRCCOPY);
  1700. if (hbmDestOld)
  1701. {
  1702. SelectObject(hMemDCDest, hbmDestOld);
  1703. }
  1704. if (hbmSrcOld)
  1705. {
  1706. SelectObject(hMemDCSrc, hbmSrcOld);
  1707. }
  1708. if (hScreenPalOld)
  1709. {
  1710. SelectPalette(hDC, hScreenPalOld, TRUE);
  1711. }
  1712. if (hMemPalOld)
  1713. {
  1714. SelectPalette(hDC, hMemPalOld, TRUE);
  1715. }
  1716. DeleteDC(hMemDCSrc);
  1717. DeleteDC(hMemDCDest);
  1718. }
  1719. ReleaseDC(_hwndDlg, hDC);
  1720. }
  1721. else
  1722. {
  1723. TRC_ERR((TB,_T("GetDC failed 0x%x"),
  1724. GetLastError()));
  1725. }
  1726. DeleteObject( hbmFromRsrc );
  1727. _nBrandImageWidth = nDlgWidth;
  1728. _nBrandImageHeight = nBmpHeight;
  1729. }
  1730. if(!hbmBrandImage)
  1731. {
  1732. TRC_ERR((TB,_T("Error setting up brand bmp")));
  1733. return FALSE;
  1734. }
  1735. if(hbmBrandImage)
  1736. {
  1737. PaintBrandingText( hbmBrandImage );
  1738. }
  1739. //
  1740. // Delete any old brand img and keep track of this one
  1741. //
  1742. if (_hBrandImg)
  1743. {
  1744. DeleteObject(_hBrandImg);
  1745. }
  1746. _hBrandImg = hbmBrandImage;
  1747. TRC_ASSERT(_nBrandImageHeight,
  1748. (TB,_T("_nBrandImageHeight is 0!")));
  1749. _lastValidBpp = screenBpp;
  1750. DC_END_FN();
  1751. return TRUE;
  1752. }
  1753. //
  1754. // BrandingQueryNewPalette / BrandingPaletteChanged
  1755. // code 'borrowed' from winlogon
  1756. // Handle palette change messages from the system so that we can work correctly
  1757. // on <= 8 bit per pixel devices.
  1758. //
  1759. // In:
  1760. // -
  1761. // Out:
  1762. // -
  1763. //
  1764. BOOL CMainDlg::BrandingQueryNewPalette(HWND hDlg)
  1765. {
  1766. HDC hDC;
  1767. HPALETTE oldPalette;
  1768. DC_BEGIN_FN("BrandingQueryNewPalette");
  1769. if ( !_hBrandPal )
  1770. return FALSE;
  1771. hDC = GetDC(hDlg);
  1772. if ( !hDC )
  1773. return FALSE;
  1774. oldPalette = SelectPalette(hDC, _hBrandPal, FALSE);
  1775. RealizePalette(hDC);
  1776. UpdateColors(hDC);
  1777. //
  1778. // Update the window
  1779. //
  1780. UpdateWindow(hDlg);
  1781. if ( oldPalette )
  1782. SelectPalette(hDC, oldPalette, FALSE);
  1783. ReleaseDC(hDlg, hDC);
  1784. DC_END_FN();
  1785. return TRUE;
  1786. }
  1787. BOOL CMainDlg::BrandingPaletteChanged(HWND hDlg, HWND hWndPalChg)
  1788. {
  1789. HDC hDC;
  1790. HPALETTE oldPalette;
  1791. DC_BEGIN_FN("BrandingPaletteChanged");
  1792. if ( !_hBrandPal )
  1793. {
  1794. return FALSE;
  1795. }
  1796. if ( hDlg != hWndPalChg )
  1797. {
  1798. hDC = GetDC(hDlg);
  1799. if ( !hDC )
  1800. return FALSE;
  1801. oldPalette = SelectPalette(hDC, _hBrandPal, FALSE);
  1802. RealizePalette(hDC);
  1803. UpdateColors(hDC);
  1804. if ( oldPalette )
  1805. SelectPalette(hDC, oldPalette, FALSE);
  1806. ReleaseDC(hDlg, hDC);
  1807. }
  1808. DC_END_FN();
  1809. return FALSE;
  1810. }
  1811. #endif
  1812. //
  1813. // Load the perf strings into a global table
  1814. // that will also be used by the perf property page
  1815. //
  1816. BOOL CMainDlg::InitializePerfStrings()
  1817. {
  1818. DC_BEGIN_FN("InitializePerfStrings");
  1819. if (!g_fPropPageStringMapInitialized)
  1820. {
  1821. //
  1822. // Load color strings
  1823. //
  1824. for(int i = 0; i< NUM_PERFSTRINGS; i++)
  1825. {
  1826. if (!LoadString( _hInstance,
  1827. g_PerfOptimizeStringTable[i].resID,
  1828. g_PerfOptimizeStringTable[i].szString,
  1829. PERF_OPTIMIZE_STRING_LEN ))
  1830. {
  1831. TRC_ERR((TB, _T("Failed to load color string %d"),
  1832. g_PerfOptimizeStringTable[i].resID));
  1833. return FALSE;
  1834. }
  1835. }
  1836. g_fPropPageStringMapInitialized = TRUE;
  1837. TRC_NRM((TB,_T("Successfully loaded perf strings")));
  1838. return TRUE;
  1839. }
  1840. else
  1841. {
  1842. TRC_NRM((TB,_T("Strings were already loaded")));
  1843. return TRUE;
  1844. }
  1845. DC_END_FN();
  1846. }