Source code of Windows XP (NT5)
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.

3060 lines
82 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows NT Security
  4. // Copyright (C) Microsoft Corporation, 1992 - 1999
  5. //
  6. // File: acuictl.cpp
  7. //
  8. // Contents: Authenticode Default UI controls
  9. //
  10. // History: 12-May-97 kirtd Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <stdpch.h>
  14. #include <richedit.h>
  15. #include "secauth.h"
  16. IACUIControl::IACUIControl(CInvokeInfoHelper& riih) : m_riih( riih ),
  17. m_hrInvokeResult( TRUST_E_SUBJECT_NOT_TRUSTED )
  18. {
  19. m_hrInvokeResult = TRUST_E_SUBJECT_NOT_TRUSTED;
  20. m_pszCopyActionText = NULL;
  21. m_pszCopyActionTextNoTS = NULL;
  22. m_pszCopyActionTextNotSigned = NULL;
  23. if ((riih.ProviderData()) &&
  24. (riih.ProviderData()->psPfns) &&
  25. (riih.ProviderData()->psPfns->psUIpfns) &&
  26. (riih.ProviderData()->psPfns->psUIpfns->psUIData))
  27. {
  28. if (_ISINSTRUCT(CRYPT_PROVUI_DATA,
  29. riih.ProviderData()->psPfns->psUIpfns->psUIData->cbStruct,
  30. pCopyActionTextNotSigned))
  31. {
  32. this->LoadActionText(&m_pszCopyActionText,
  33. riih.ProviderData()->psPfns->psUIpfns->psUIData->pCopyActionText, IDS_ACTIONSIGNED);
  34. this->LoadActionText(&m_pszCopyActionTextNoTS,
  35. riih.ProviderData()->psPfns->psUIpfns->psUIData->pCopyActionTextNoTS, IDS_ACTIONSIGNED_NODATE);
  36. this->LoadActionText(&m_pszCopyActionTextNotSigned,
  37. riih.ProviderData()->psPfns->psUIpfns->psUIData->pCopyActionTextNotSigned, IDS_ACTIONNOTSIGNED);
  38. }
  39. }
  40. if (!(m_pszCopyActionText))
  41. {
  42. this->LoadActionText(&m_pszCopyActionText, NULL, IDS_ACTIONSIGNED);
  43. }
  44. if (!(m_pszCopyActionTextNoTS))
  45. {
  46. this->LoadActionText(&m_pszCopyActionTextNoTS, NULL, IDS_ACTIONSIGNED_NODATE);
  47. }
  48. if (!(m_pszCopyActionTextNotSigned))
  49. {
  50. this->LoadActionText(&m_pszCopyActionTextNotSigned, NULL, IDS_ACTIONNOTSIGNED);
  51. }
  52. }
  53. void IACUIControl::LoadActionText(WCHAR **ppszRet, WCHAR *pwszIn, DWORD dwDefId)
  54. {
  55. WCHAR sz[MAX_PATH];
  56. *ppszRet = NULL;
  57. sz[0] = NULL;
  58. if ((pwszIn) && (*pwszIn))
  59. {
  60. sz[0] = NULL;
  61. if (wcslen(pwszIn) < MAX_PATH)
  62. {
  63. wcscpy(&sz[0], pwszIn);
  64. }
  65. if (sz[0])
  66. {
  67. if (*ppszRet = new WCHAR[wcslen(&sz[0]) + 1])
  68. {
  69. wcscpy(*ppszRet, &sz[0]);
  70. }
  71. }
  72. }
  73. if (!(sz[0]))
  74. {
  75. sz[0] = NULL;
  76. LoadStringU(g_hModule, dwDefId, &sz[0], MAX_PATH);
  77. if (sz[0])
  78. {
  79. if (*ppszRet = new WCHAR[wcslen(&sz[0]) + 1])
  80. {
  81. wcscpy(*ppszRet, &sz[0]);
  82. }
  83. }
  84. }
  85. }
  86. IACUIControl::~IACUIControl ()
  87. {
  88. DELETE_OBJECT(m_pszCopyActionText);
  89. DELETE_OBJECT(m_pszCopyActionTextNoTS);
  90. DELETE_OBJECT(m_pszCopyActionTextNotSigned);
  91. }
  92. void IACUIControl::SetupButtons(HWND hWnd)
  93. {
  94. char sz[MAX_PATH];
  95. if ((m_riih.ProviderData()) &&
  96. (m_riih.ProviderData()->psPfns) &&
  97. (m_riih.ProviderData()->psPfns->psUIpfns) &&
  98. (m_riih.ProviderData()->psPfns->psUIpfns->psUIData))
  99. {
  100. if (m_riih.ProviderData()->psPfns->psUIpfns->psUIData->pYesButtonText)
  101. {
  102. if (!(m_riih.ProviderData()->psPfns->psUIpfns->psUIData->pYesButtonText[0]))
  103. {
  104. ShowWindow(GetDlgItem(hWnd, IDYES), SW_HIDE);
  105. }
  106. else
  107. {
  108. SetWindowTextU(GetDlgItem(hWnd, IDYES), m_riih.ProviderData()->psPfns->psUIpfns->psUIData->pYesButtonText);
  109. }
  110. }
  111. if (m_riih.ProviderData()->psPfns->psUIpfns->psUIData->pNoButtonText)
  112. {
  113. if (!(m_riih.ProviderData()->psPfns->psUIpfns->psUIData->pNoButtonText[0]))
  114. {
  115. ShowWindow(GetDlgItem(hWnd, IDNO), SW_HIDE);
  116. }
  117. else
  118. {
  119. SetWindowTextU(GetDlgItem(hWnd, IDNO), m_riih.ProviderData()->psPfns->psUIpfns->psUIData->pNoButtonText);
  120. }
  121. }
  122. }
  123. }
  124. //+---------------------------------------------------------------------------
  125. //
  126. // Member: IACUIControl::OnUIMessage, public
  127. //
  128. // Synopsis: responds to UI messages
  129. //
  130. // Arguments: [hwnd] -- window
  131. // [uMsg] -- message id
  132. // [wParam] -- parameter 1
  133. // [lParam] -- parameter 2
  134. //
  135. // Returns: TRUE if message processing should continue, FALSE otherwise
  136. //
  137. // Notes:
  138. //
  139. //----------------------------------------------------------------------------
  140. BOOL
  141. IACUIControl::OnUIMessage (
  142. HWND hwnd,
  143. UINT uMsg,
  144. WPARAM wParam,
  145. LPARAM lParam
  146. )
  147. {
  148. switch ( uMsg )
  149. {
  150. case WM_INITDIALOG:
  151. {
  152. BOOL fReturn;
  153. HICON hIcon;
  154. fReturn = OnInitDialog(hwnd, wParam, lParam);
  155. ACUICenterWindow(hwnd);
  156. // hIcon = LoadIcon((HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), MAKEINTRESOURCE(IDI_LOCK));
  157. // dwOrigIcon = SetClassLongPtr(hwnd, GCLP_HICON,
  158. // (LONG_PTR)LoadIcon((HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE),
  159. // MAKEINTRESOURCE(IDI_LOCK)));
  160. // PostMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
  161. // PostMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
  162. return( fReturn );
  163. }
  164. break;
  165. case WM_COMMAND:
  166. {
  167. WORD wNotifyCode = HIWORD(wParam);
  168. WORD wId = LOWORD(wParam);
  169. HWND hwndControl = (HWND)lParam;
  170. if ( wNotifyCode == BN_CLICKED )
  171. {
  172. if ( wId == IDYES )
  173. {
  174. return( OnYes(hwnd) );
  175. }
  176. else if ( wId == IDNO )
  177. {
  178. return( OnNo(hwnd) );
  179. }
  180. else if ( wId == IDMORE )
  181. {
  182. return( OnMore(hwnd) );
  183. }
  184. }
  185. return( FALSE );
  186. }
  187. break;
  188. case WM_CLOSE:
  189. return( OnNo(hwnd) );
  190. break;
  191. default:
  192. return( FALSE );
  193. }
  194. return( TRUE );
  195. }
  196. //+---------------------------------------------------------------------------
  197. //
  198. // Member: CVerifiedTrustUI::CVerifiedTrustUI, public
  199. //
  200. // Synopsis: Constructor
  201. //
  202. // Arguments: [riih] -- invoke info helper reference
  203. //
  204. // Returns: (none)
  205. //
  206. // Notes:
  207. //
  208. //----------------------------------------------------------------------------
  209. CVerifiedTrustUI::CVerifiedTrustUI (CInvokeInfoHelper& riih, HRESULT& rhr)
  210. : IACUIControl( riih ),
  211. m_pszInstallAndRun( NULL ),
  212. m_pszAuthenticity( NULL ),
  213. m_pszCaution( NULL ),
  214. m_pszPersonalTrust( NULL )
  215. {
  216. DWORD_PTR aMessageArgument[3];
  217. //
  218. // Initialize the hot-link subclass data
  219. //
  220. m_lsdPublisher.uId = IDC_PUBLISHER;
  221. m_lsdPublisher.hwndParent = NULL;
  222. m_lsdPublisher.wpPrev = (WNDPROC)NULL;
  223. m_lsdPublisher.pvData = (LPVOID)&riih;
  224. m_lsdPublisher.uToolTipText = IDS_CLICKHEREFORCERT;
  225. m_lsdOpusInfo.uId = IDC_INSTALLANDRUN;
  226. m_lsdOpusInfo.hwndParent = NULL;
  227. m_lsdOpusInfo.wpPrev = (WNDPROC)NULL;
  228. m_lsdOpusInfo.pvData = &riih;
  229. m_lsdOpusInfo.uToolTipText = (DWORD_PTR)riih.ControlWebPage();
  230. m_lsdCA.uId = IDC_AUTHENTICITY;
  231. m_lsdCA.hwndParent = NULL;
  232. m_lsdCA.wpPrev = (WNDPROC)NULL;
  233. m_lsdCA.pvData = &riih;
  234. m_lsdCA.uToolTipText = (DWORD_PTR)riih.CAWebPage(); // IDS_CLICKHEREFORCAINFO;
  235. m_lsdAdvanced.uId = IDC_ADVANCED;
  236. m_lsdAdvanced.hwndParent = NULL;
  237. m_lsdAdvanced.wpPrev = (WNDPROC)NULL;
  238. m_lsdAdvanced.pvData = &riih;
  239. m_lsdAdvanced.uToolTipText = IDS_CLICKHEREFORADVANCED;
  240. //
  241. // Format the install and run string
  242. //
  243. aMessageArgument[2] = NULL;
  244. if (m_riih.CertTimestamp())
  245. {
  246. aMessageArgument[0] = (DWORD_PTR)m_pszCopyActionText;
  247. aMessageArgument[1] = (DWORD_PTR)m_riih.Subject();
  248. aMessageArgument[2] = (DWORD_PTR)m_riih.CertTimestamp();
  249. }
  250. else
  251. {
  252. aMessageArgument[0] = (DWORD_PTR)m_pszCopyActionTextNoTS;
  253. aMessageArgument[1] = (DWORD_PTR)m_riih.Subject();
  254. aMessageArgument[2] = NULL;
  255. }
  256. rhr = FormatACUIResourceString(0, aMessageArgument, &m_pszInstallAndRun);
  257. //
  258. // Format the authenticity string
  259. //
  260. if ( rhr == S_OK )
  261. {
  262. aMessageArgument[0] = (DWORD_PTR)m_riih.PublisherCertIssuer();
  263. rhr = FormatACUIResourceString(
  264. IDS_AUTHENTICITY,
  265. aMessageArgument,
  266. &m_pszAuthenticity
  267. );
  268. }
  269. //
  270. // Get the publisher as a message argument
  271. //
  272. aMessageArgument[0] = (DWORD_PTR)m_riih.Publisher();
  273. //
  274. // Format the caution string
  275. //
  276. if ( rhr == S_OK )
  277. {
  278. rhr = FormatACUIResourceString(
  279. IDS_CAUTION,
  280. aMessageArgument,
  281. &m_pszCaution
  282. );
  283. }
  284. //
  285. // Format the personal trust string
  286. //
  287. if ( rhr == S_OK )
  288. {
  289. rhr = FormatACUIResourceString(
  290. IDS_PERSONALTRUST,
  291. aMessageArgument,
  292. &m_pszPersonalTrust
  293. );
  294. }
  295. }
  296. //+---------------------------------------------------------------------------
  297. //
  298. // Member: CVerifiedTrustUI::~CVerifiedTrustUI, public
  299. //
  300. // Synopsis: Destructor
  301. //
  302. // Arguments: (none)
  303. //
  304. // Returns: (none)
  305. //
  306. // Notes:
  307. //
  308. //----------------------------------------------------------------------------
  309. CVerifiedTrustUI::~CVerifiedTrustUI ()
  310. {
  311. DELETE_OBJECT(m_pszInstallAndRun);
  312. DELETE_OBJECT(m_pszAuthenticity);
  313. DELETE_OBJECT(m_pszCaution);
  314. DELETE_OBJECT(m_pszPersonalTrust);
  315. }
  316. //+---------------------------------------------------------------------------
  317. //
  318. // Member: CVerifiedTrustUI::InvokeUI, public
  319. //
  320. // Synopsis: invoke the UI
  321. //
  322. // Arguments: [hDisplay] -- parent window
  323. //
  324. // Returns: S_OK, user trusts the subject
  325. // TRUST_E_SUBJECT_NOT_TRUSTED, user does NOT trust the subject
  326. // Any other valid HRESULT
  327. //
  328. // Notes:
  329. //
  330. //----------------------------------------------------------------------------
  331. HRESULT
  332. CVerifiedTrustUI::InvokeUI (HWND hDisplay)
  333. {
  334. //
  335. // Bring up the dialog
  336. //
  337. if ( DialogBoxParamU(
  338. g_hModule,
  339. (LPWSTR) MAKEINTRESOURCE(IDD_DIALOG1_VERIFIED),
  340. hDisplay,
  341. ACUIMessageProc,
  342. (LPARAM)this
  343. ) == -1 )
  344. {
  345. return( HRESULT_FROM_WIN32(GetLastError()) );
  346. }
  347. //
  348. // The result has been stored as a member
  349. //
  350. return( m_hrInvokeResult );
  351. }
  352. //+---------------------------------------------------------------------------
  353. //
  354. // Member: CVerifiedTrustUI::OnInitDialog, public
  355. //
  356. // Synopsis: dialog initialization
  357. //
  358. // Arguments: [hwnd] -- dialog window
  359. // [wParam] -- parameter 1
  360. // [lParam] -- parameter 2
  361. //
  362. // Returns: TRUE if successful init, FALSE otherwise
  363. //
  364. // Notes:
  365. //
  366. //----------------------------------------------------------------------------
  367. BOOL
  368. CVerifiedTrustUI::OnInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam)
  369. {
  370. WCHAR psz[MAX_LOADSTRING_BUFFER];
  371. HWND hControl;
  372. int deltavpos = 0;
  373. int deltaheight;
  374. int bmptosep;
  375. int septodlg;
  376. int savevpos;
  377. int hkcharpos;
  378. RECT rect;
  379. //
  380. // Setup the publisher link subclass data parent window
  381. //
  382. m_lsdPublisher.hwndParent = hwnd;
  383. m_lsdOpusInfo.hwndParent = hwnd;
  384. m_lsdCA.hwndParent = hwnd;
  385. m_lsdAdvanced.hwndParent = hwnd;
  386. //
  387. // Render the install and run string
  388. //
  389. deltavpos = RenderACUIStringToEditControl(
  390. hwnd,
  391. IDC_INSTALLANDRUN,
  392. IDC_PUBLISHER,
  393. m_pszInstallAndRun,
  394. deltavpos,
  395. (m_riih.ControlWebPage()) ? TRUE : FALSE,
  396. (WNDPROC)ACUILinkSubclass,
  397. &m_lsdOpusInfo,
  398. 0,
  399. m_riih.Subject());
  400. //
  401. // Render the publisher, give it a "link" look and feel if it is a known
  402. // publisher
  403. //
  404. //
  405. // if there was a test cert in the chain, add it to the text...
  406. //
  407. if (m_riih.TestCertInChain())
  408. {
  409. WCHAR *pszCombine;
  410. pszCombine = new WCHAR[wcslen(m_riih.Publisher()) + wcslen(m_riih.TestCertInChain()) + 3];
  411. if (pszCombine != NULL)
  412. {
  413. wcscpy(pszCombine, m_riih.Publisher());
  414. wcscat(pszCombine, L"\r\n");
  415. wcscat(pszCombine, m_riih.TestCertInChain());
  416. deltavpos = RenderACUIStringToEditControl(
  417. hwnd,
  418. IDC_PUBLISHER,
  419. IDC_AUTHENTICITY,
  420. pszCombine,
  421. deltavpos,
  422. m_riih.IsKnownPublisher() &&
  423. m_riih.IsCertViewPropertiesAvailable(),
  424. (WNDPROC)ACUILinkSubclass,
  425. &m_lsdPublisher,
  426. 0,
  427. NULL
  428. );
  429. delete[] pszCombine;
  430. }
  431. if (LoadStringU(g_hModule, IDS_TESTCERTTITLE, psz, MAX_LOADSTRING_BUFFER) != 0)
  432. {
  433. int wtlen;
  434. wtlen = wcslen(psz) + GetWindowTextLength(hwnd);
  435. pszCombine = new WCHAR[wtlen + 1];
  436. if (pszCombine != NULL)
  437. {
  438. GetWindowTextU(hwnd, pszCombine, wtlen + 1);
  439. wcscat(pszCombine, psz);
  440. SetWindowTextU(hwnd, pszCombine);
  441. delete[] pszCombine;
  442. }
  443. }
  444. }
  445. else
  446. {
  447. deltavpos = RenderACUIStringToEditControl(
  448. hwnd,
  449. IDC_PUBLISHER,
  450. IDC_AUTHENTICITY,
  451. m_riih.Publisher(),
  452. deltavpos,
  453. m_riih.IsKnownPublisher() &&
  454. m_riih.IsCertViewPropertiesAvailable(),
  455. (WNDPROC)ACUILinkSubclass,
  456. &m_lsdPublisher,
  457. 0,
  458. NULL
  459. );
  460. }
  461. //
  462. // Render the authenticity statement
  463. //
  464. deltavpos = RenderACUIStringToEditControl(
  465. hwnd,
  466. IDC_AUTHENTICITY,
  467. IDC_CAUTION,
  468. m_pszAuthenticity,
  469. deltavpos,
  470. (m_riih.CAWebPage()) ? TRUE : FALSE,
  471. (WNDPROC)ACUILinkSubclass,
  472. &m_lsdCA,
  473. 0,
  474. m_riih.PublisherCertIssuer());
  475. //
  476. // Render the caution statement
  477. //
  478. deltavpos = RenderACUIStringToEditControl(
  479. hwnd,
  480. IDC_CAUTION,
  481. IDC_ADVANCED,
  482. m_pszCaution,
  483. deltavpos,
  484. FALSE,
  485. NULL,
  486. NULL,
  487. 0,
  488. NULL
  489. );
  490. //
  491. // Render the advanced string
  492. //
  493. if ((m_riih.AdvancedLink()) &&
  494. (m_riih.ProviderData()->psPfns->psUIpfns->pfnOnAdvancedClick))
  495. {
  496. deltavpos = RenderACUIStringToEditControl(
  497. hwnd,
  498. IDC_ADVANCED,
  499. IDC_PERSONALTRUST,
  500. m_riih.AdvancedLink(),
  501. deltavpos,
  502. TRUE,
  503. (WNDPROC)ACUILinkSubclass,
  504. &m_lsdAdvanced,
  505. 0,
  506. NULL
  507. );
  508. }
  509. else
  510. {
  511. ShowWindow(GetDlgItem(hwnd, IDC_ADVANCED), SW_HIDE);
  512. }
  513. //
  514. // Calculate the distances from the bottom of the bitmap to the top
  515. // of the separator and from the bottom of the separator to the bottom
  516. // of the dialog
  517. //
  518. bmptosep = CalculateControlVerticalDistance(
  519. hwnd,
  520. IDC_VERBMP,
  521. IDC_SEPARATORLINE
  522. );
  523. septodlg = CalculateControlVerticalDistanceFromDlgBottom(
  524. hwnd,
  525. IDC_SEPARATORLINE
  526. );
  527. //
  528. // Rebase the check box and render the personal trust statement or hide
  529. // them the publisher is not known
  530. //
  531. if ( m_riih.IsKnownPublisher() == TRUE )
  532. {
  533. hControl = GetDlgItem(hwnd, IDC_PTCHECK);
  534. RebaseControlVertical(
  535. hwnd,
  536. hControl,
  537. NULL,
  538. FALSE,
  539. deltavpos,
  540. 0,
  541. bmptosep,
  542. &deltaheight
  543. );
  544. assert( deltaheight == 0 );
  545. //
  546. // Find the hotkey character position for the personal trust
  547. // check box
  548. //
  549. #if (0) //DSIE: Bug 34325
  550. hkcharpos = GetHotKeyCharPosition(GetDlgItem(hwnd, IDC_PTCHECK));
  551. #else
  552. hkcharpos = GetHotKeyCharPositionFromString(m_pszPersonalTrust);
  553. #endif
  554. deltavpos = RenderACUIStringToEditControl(
  555. hwnd,
  556. IDC_PERSONALTRUST,
  557. IDC_SEPARATORLINE,
  558. m_pszPersonalTrust,
  559. deltavpos,
  560. FALSE,
  561. NULL,
  562. NULL,
  563. bmptosep,
  564. NULL
  565. );
  566. if ( hkcharpos != 0 )
  567. {
  568. FormatHotKeyOnEditControl(
  569. GetDlgItem(hwnd, IDC_PERSONALTRUST),
  570. hkcharpos
  571. );
  572. }
  573. }
  574. else
  575. {
  576. ShowWindow(GetDlgItem(hwnd, IDC_PTCHECK), SW_HIDE);
  577. ShowWindow(GetDlgItem(hwnd, IDC_PERSONALTRUST), SW_HIDE);
  578. }
  579. //
  580. // Rebase the static line
  581. //
  582. hControl = GetDlgItem(hwnd, IDC_SEPARATORLINE);
  583. RebaseControlVertical(hwnd, hControl, NULL, FALSE, deltavpos, 0, 0, &deltaheight);
  584. assert( deltaheight == 0 );
  585. //
  586. // Rebase the buttons
  587. //
  588. hControl = GetDlgItem(hwnd, IDYES);
  589. RebaseControlVertical(hwnd, hControl, NULL, FALSE, deltavpos, 0, 0, &deltaheight);
  590. assert( deltaheight == 0 );
  591. hControl = GetDlgItem(hwnd, IDNO);
  592. RebaseControlVertical(hwnd, hControl, NULL, FALSE, deltavpos, 0, 0, &deltaheight);
  593. assert( deltaheight == 0 );
  594. hControl = GetDlgItem(hwnd, IDMORE);
  595. RebaseControlVertical(hwnd, hControl, NULL, FALSE, deltavpos, 0, 0, &deltaheight);
  596. assert( deltaheight == 0 );
  597. //
  598. // Resize the bitmap and the dialog rectangle if necessary
  599. //
  600. if ( deltavpos > 0 )
  601. {
  602. int cyupd;
  603. hControl = GetDlgItem(hwnd, IDC_VERBMP);
  604. GetWindowRect(hControl, &rect);
  605. cyupd = CalculateControlVerticalDistance(
  606. hwnd,
  607. IDC_VERBMP,
  608. IDC_SEPARATORLINE
  609. );
  610. cyupd -= bmptosep;
  611. SetWindowPos(
  612. hControl,
  613. NULL,
  614. 0,
  615. 0,
  616. rect.right - rect.left,
  617. (rect.bottom - rect.top) + cyupd,
  618. SWP_NOZORDER | SWP_NOMOVE
  619. );
  620. GetWindowRect(hwnd, &rect);
  621. cyupd = CalculateControlVerticalDistanceFromDlgBottom(
  622. hwnd,
  623. IDC_SEPARATORLINE
  624. );
  625. cyupd = septodlg - cyupd;
  626. SetWindowPos(
  627. hwnd,
  628. NULL,
  629. 0,
  630. 0,
  631. rect.right - rect.left,
  632. (rect.bottom - rect.top) + cyupd,
  633. SWP_NOZORDER | SWP_NOMOVE
  634. );
  635. }
  636. //
  637. // check for overridden button texts
  638. //
  639. this->SetupButtons(hwnd);
  640. //
  641. // Set focus to appropriate control
  642. //
  643. hControl = GetDlgItem(hwnd, IDNO);
  644. ::PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM) hControl, (LPARAM) MAKEWORD(TRUE, 0));
  645. return( FALSE );
  646. }
  647. //+---------------------------------------------------------------------------
  648. //
  649. // Member: CVerifiedTrustUI::OnYes, public
  650. //
  651. // Synopsis: process IDYES button click
  652. //
  653. // Arguments: [hwnd] -- window handle
  654. //
  655. // Returns: TRUE
  656. //
  657. // Notes:
  658. //
  659. //----------------------------------------------------------------------------
  660. BOOL
  661. CVerifiedTrustUI::OnYes (HWND hwnd)
  662. {
  663. //
  664. // Set the invoke result
  665. //
  666. m_hrInvokeResult = S_OK;
  667. //
  668. // Add the publisher to the trust database
  669. //
  670. if ( SendDlgItemMessage(
  671. hwnd,
  672. IDC_PTCHECK,
  673. BM_GETCHECK,
  674. 0,
  675. 0
  676. ) == BST_CHECKED )
  677. {
  678. m_riih.AddPublisherToPersonalTrust();
  679. }
  680. //
  681. // End the dialog processing
  682. //
  683. EndDialog(hwnd, (int)m_hrInvokeResult);
  684. return( TRUE );
  685. }
  686. //+---------------------------------------------------------------------------
  687. //
  688. // Member: CVerifiedTrustUI::OnNo, public
  689. //
  690. // Synopsis: process IDNO button click
  691. //
  692. // Arguments: [hwnd] -- window handle
  693. //
  694. // Returns: TRUE
  695. //
  696. // Notes:
  697. //
  698. //----------------------------------------------------------------------------
  699. BOOL
  700. CVerifiedTrustUI::OnNo (HWND hwnd)
  701. {
  702. m_hrInvokeResult = TRUST_E_SUBJECT_NOT_TRUSTED;
  703. EndDialog(hwnd, (int)m_hrInvokeResult);
  704. return( TRUE );
  705. }
  706. //+---------------------------------------------------------------------------
  707. //
  708. // Member: CVerifiedTrustUI::OnMore, public
  709. //
  710. // Synopsis: process the IDMORE button click
  711. //
  712. // Arguments: [hwnd] -- window handle
  713. //
  714. // Returns: TRUE
  715. //
  716. // Notes:
  717. //
  718. //----------------------------------------------------------------------------
  719. BOOL
  720. CVerifiedTrustUI::OnMore (HWND hwnd)
  721. {
  722. WinHelp(hwnd, "SECAUTH.HLP", HELP_CONTEXT, IDH_SECAUTH_SIGNED);
  723. // ACUIViewHTMLHelpTopic(hwnd, "sec_signed.htm");
  724. return( TRUE );
  725. }
  726. //+---------------------------------------------------------------------------
  727. //
  728. // Member: CUnverifiedTrustUI::CUnverifiedTrustUI, public
  729. //
  730. // Synopsis: Constructor
  731. //
  732. // Arguments: [riih] -- invoke info helper reference
  733. //
  734. // Returns: (none)
  735. //
  736. // Notes:
  737. //
  738. //----------------------------------------------------------------------------
  739. CUnverifiedTrustUI::CUnverifiedTrustUI (CInvokeInfoHelper& riih, HRESULT& rhr)
  740. : IACUIControl( riih ),
  741. m_pszNoAuthenticity( NULL ),
  742. m_pszProblemsBelow( NULL ),
  743. m_pszInstallAndRun3( NULL )
  744. {
  745. DWORD_PTR aMessageArgument[3];
  746. //
  747. // Initialize the publisher link subclass data
  748. //
  749. m_lsdPublisher.uId = IDC_PUBLISHER;
  750. m_lsdPublisher.hwndParent = NULL;
  751. m_lsdPublisher.wpPrev = (WNDPROC)NULL;
  752. m_lsdPublisher.pvData = (LPVOID)&riih;
  753. m_lsdPublisher.uToolTipText = IDS_CLICKHEREFORCERT;
  754. m_lsdOpusInfo.uId = IDC_INSTALLANDRUN;
  755. m_lsdOpusInfo.hwndParent = NULL;
  756. m_lsdOpusInfo.wpPrev = (WNDPROC)NULL;
  757. m_lsdOpusInfo.pvData = &riih;
  758. m_lsdOpusInfo.uToolTipText = (DWORD_PTR)riih.ControlWebPage(); // IDS_CLICKHEREFOROPUSINFO;
  759. m_lsdAdvanced.uId = IDC_ADVANCED;
  760. m_lsdAdvanced.hwndParent = NULL;
  761. m_lsdAdvanced.wpPrev = (WNDPROC)NULL;
  762. m_lsdAdvanced.pvData = &riih;
  763. m_lsdAdvanced.uToolTipText = IDS_CLICKHEREFORADVANCED;
  764. //
  765. // Format the no authenticity string
  766. //
  767. rhr = FormatACUIResourceString(
  768. IDS_NOAUTHENTICITY,
  769. NULL,
  770. &m_pszNoAuthenticity
  771. );
  772. //
  773. // Format the problems below string
  774. //
  775. if ( rhr == S_OK )
  776. {
  777. aMessageArgument[0] = (DWORD_PTR)m_riih.ErrorStatement();
  778. rhr = FormatACUIResourceString(
  779. IDS_PROBLEMSBELOW,
  780. aMessageArgument,
  781. &m_pszProblemsBelow
  782. );
  783. }
  784. //
  785. // Format the install and run string
  786. //
  787. if ( rhr == S_OK )
  788. {
  789. if (m_riih.CertTimestamp())
  790. {
  791. aMessageArgument[0] = (DWORD_PTR)m_pszCopyActionText;
  792. aMessageArgument[1] = (DWORD_PTR)m_riih.Subject();
  793. aMessageArgument[2] = (DWORD_PTR)m_riih.CertTimestamp();
  794. }
  795. else
  796. {
  797. aMessageArgument[0] = (DWORD_PTR)m_pszCopyActionTextNoTS;
  798. aMessageArgument[1] = (DWORD_PTR)m_riih.Subject();
  799. aMessageArgument[2] = NULL;
  800. }
  801. rhr = FormatACUIResourceString(0, aMessageArgument, &m_pszInstallAndRun3);
  802. }
  803. }
  804. //+---------------------------------------------------------------------------
  805. //
  806. // Member: CUnverifiedTrustUI::~CUnverifiedTrustUI, public
  807. //
  808. // Synopsis: Destructor
  809. //
  810. // Arguments: (none)
  811. //
  812. // Returns: (none)
  813. //
  814. // Notes:
  815. //
  816. //----------------------------------------------------------------------------
  817. CUnverifiedTrustUI::~CUnverifiedTrustUI ()
  818. {
  819. DELETE_OBJECT(m_pszNoAuthenticity);
  820. DELETE_OBJECT(m_pszProblemsBelow);
  821. DELETE_OBJECT(m_pszInstallAndRun3);
  822. }
  823. //+---------------------------------------------------------------------------
  824. //
  825. // Member: CUnverifiedTrustUI::InvokeUI, public
  826. //
  827. // Synopsis: invoke the UI
  828. //
  829. // Arguments: [hDisplay] -- parent window
  830. //
  831. // Returns: S_OK, user trusts the subject
  832. // TRUST_E_SUBJECT_NOT_TRUSTED, user does NOT trust the subject
  833. // Any other valid HRESULT
  834. //
  835. // Notes:
  836. //
  837. //----------------------------------------------------------------------------
  838. HRESULT
  839. CUnverifiedTrustUI::InvokeUI (HWND hDisplay)
  840. {
  841. HRESULT hr = S_OK;
  842. //
  843. // Bring up the dialog
  844. //
  845. if ( DialogBoxParamU(
  846. g_hModule,
  847. (LPWSTR) MAKEINTRESOURCE(IDD_DIALOG2_UNVERIFIED),
  848. hDisplay,
  849. ACUIMessageProc,
  850. (LPARAM)this
  851. ) == -1 )
  852. {
  853. return( HRESULT_FROM_WIN32(GetLastError()) );
  854. }
  855. //
  856. // The result has been stored as a member
  857. //
  858. return( m_hrInvokeResult );
  859. }
  860. //+---------------------------------------------------------------------------
  861. //
  862. // Member: CUnverifiedTrustUI::OnInitDialog, public
  863. //
  864. // Synopsis: dialog initialization
  865. //
  866. // Arguments: [hwnd] -- dialog window
  867. // [wParam] -- parameter 1
  868. // [lParam] -- parameter 2
  869. //
  870. // Returns: TRUE if successful init, FALSE otherwise
  871. //
  872. // Notes:
  873. //
  874. //----------------------------------------------------------------------------
  875. BOOL
  876. CUnverifiedTrustUI::OnInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam)
  877. {
  878. HWND hControl;
  879. int deltavpos = 0;
  880. int deltaheight;
  881. int bmptosep;
  882. int septodlg;
  883. RECT rect;
  884. //
  885. // Setup the publisher link subclass data parent window
  886. //
  887. m_lsdPublisher.hwndParent = hwnd;
  888. m_lsdOpusInfo.hwndParent = hwnd;
  889. m_lsdAdvanced.hwndParent = hwnd;
  890. //
  891. // Render the no authenticity statement
  892. //
  893. deltavpos = RenderACUIStringToEditControl(
  894. hwnd,
  895. IDC_NOAUTHENTICITY,
  896. IDC_PROBLEMSBELOW,
  897. m_pszNoAuthenticity,
  898. deltavpos,
  899. FALSE,
  900. NULL,
  901. NULL,
  902. 0,
  903. NULL
  904. );
  905. //
  906. // Render the problems below string
  907. //
  908. deltavpos = RenderACUIStringToEditControl(
  909. hwnd,
  910. IDC_PROBLEMSBELOW,
  911. IDC_INSTALLANDRUN3,
  912. m_pszProblemsBelow,
  913. deltavpos,
  914. FALSE,
  915. NULL,
  916. NULL,
  917. 0,
  918. NULL
  919. );
  920. //
  921. // Render the install and run string
  922. //
  923. deltavpos = RenderACUIStringToEditControl(
  924. hwnd,
  925. IDC_INSTALLANDRUN3,
  926. IDC_PUBLISHER2,
  927. m_pszInstallAndRun3,
  928. deltavpos,
  929. (m_riih.ControlWebPage()) ? TRUE : FALSE,
  930. (WNDPROC)ACUILinkSubclass,
  931. &m_lsdOpusInfo,
  932. 0,
  933. m_riih.Subject());
  934. //
  935. // Calculate the distances from the bottom of the bitmap to the top
  936. // of the separator and from the bottom of the separator to the bottom
  937. // of the dialog
  938. //
  939. bmptosep = CalculateControlVerticalDistance(
  940. hwnd,
  941. IDC_NOVERBMP2,
  942. IDC_SEPARATORLINE
  943. );
  944. septodlg = CalculateControlVerticalDistanceFromDlgBottom(
  945. hwnd,
  946. IDC_SEPARATORLINE
  947. );
  948. //
  949. // Render the publisher, give it a "link" look and feel
  950. //
  951. deltavpos = RenderACUIStringToEditControl(
  952. hwnd,
  953. IDC_PUBLISHER2,
  954. IDC_ADVANCED,
  955. m_riih.Publisher(),
  956. deltavpos,
  957. m_riih.IsKnownPublisher() &&
  958. m_riih.IsCertViewPropertiesAvailable(),
  959. (WNDPROC)ACUILinkSubclass,
  960. &m_lsdPublisher,
  961. bmptosep,
  962. NULL
  963. );
  964. if ((m_riih.AdvancedLink()) &&
  965. (m_riih.ProviderData()->psPfns->psUIpfns->pfnOnAdvancedClick))
  966. {
  967. deltavpos = RenderACUIStringToEditControl(
  968. hwnd,
  969. IDC_ADVANCED,
  970. IDC_SEPARATORLINE,
  971. m_riih.AdvancedLink(),
  972. deltavpos,
  973. TRUE,
  974. (WNDPROC)ACUILinkSubclass,
  975. &m_lsdAdvanced,
  976. 0,
  977. NULL
  978. );
  979. }
  980. else
  981. {
  982. ShowWindow(GetDlgItem(hwnd, IDC_ADVANCED), SW_HIDE);
  983. }
  984. //
  985. // Rebase the static line
  986. //
  987. hControl = GetDlgItem(hwnd, IDC_SEPARATORLINE);
  988. RebaseControlVertical(hwnd, hControl, NULL, FALSE, deltavpos, 0, 0, &deltaheight);
  989. assert( deltaheight == 0 );
  990. //
  991. // Rebase the buttons
  992. //
  993. hControl = GetDlgItem(hwnd, IDYES);
  994. RebaseControlVertical(hwnd, hControl, NULL, FALSE, deltavpos, 0, 0, &deltaheight);
  995. assert( deltaheight == 0 );
  996. hControl = GetDlgItem(hwnd, IDNO);
  997. RebaseControlVertical(hwnd, hControl, NULL, FALSE, deltavpos, 0, 0, &deltaheight);
  998. assert( deltaheight == 0 );
  999. hControl = GetDlgItem(hwnd, IDMORE);
  1000. RebaseControlVertical(hwnd, hControl, NULL, FALSE, deltavpos, 0, 0, &deltaheight);
  1001. assert( deltaheight == 0 );
  1002. //
  1003. // Resize the bitmap and the dialog rectangle if necessary
  1004. //
  1005. if ( deltavpos > 0 )
  1006. {
  1007. int cyupd;
  1008. hControl = GetDlgItem(hwnd, IDC_NOVERBMP2);
  1009. GetWindowRect(hControl, &rect);
  1010. cyupd = CalculateControlVerticalDistance(
  1011. hwnd,
  1012. IDC_NOVERBMP2,
  1013. IDC_SEPARATORLINE
  1014. );
  1015. cyupd -= bmptosep;
  1016. SetWindowPos(
  1017. hControl,
  1018. NULL,
  1019. 0,
  1020. 0,
  1021. rect.right - rect.left,
  1022. (rect.bottom - rect.top) + cyupd,
  1023. SWP_NOZORDER | SWP_NOMOVE
  1024. );
  1025. GetWindowRect(hwnd, &rect);
  1026. cyupd = CalculateControlVerticalDistanceFromDlgBottom(
  1027. hwnd,
  1028. IDC_SEPARATORLINE
  1029. );
  1030. cyupd = septodlg - cyupd;
  1031. SetWindowPos(
  1032. hwnd,
  1033. NULL,
  1034. 0,
  1035. 0,
  1036. rect.right - rect.left,
  1037. (rect.bottom - rect.top) + cyupd,
  1038. SWP_NOZORDER | SWP_NOMOVE
  1039. );
  1040. }
  1041. //
  1042. // check for overridden button texts
  1043. //
  1044. this->SetupButtons(hwnd);
  1045. //
  1046. // Set focus to appropriate control
  1047. //
  1048. hControl = GetDlgItem(hwnd, IDNO);
  1049. ::PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM) hControl, (LPARAM) MAKEWORD(TRUE, 0));
  1050. return( FALSE );
  1051. }
  1052. //+---------------------------------------------------------------------------
  1053. //
  1054. // Member: CUnverifiedTrustUI::OnYes, public
  1055. //
  1056. // Synopsis: process IDYES button click
  1057. //
  1058. // Arguments: [hwnd] -- window handle
  1059. //
  1060. // Returns: TRUE
  1061. //
  1062. // Notes:
  1063. //
  1064. //----------------------------------------------------------------------------
  1065. BOOL
  1066. CUnverifiedTrustUI::OnYes (HWND hwnd)
  1067. {
  1068. m_hrInvokeResult = S_OK;
  1069. EndDialog(hwnd, (int)m_hrInvokeResult);
  1070. return( TRUE );
  1071. }
  1072. //+---------------------------------------------------------------------------
  1073. //
  1074. // Member: CUnverifiedTrustUI::OnNo, public
  1075. //
  1076. // Synopsis: process IDNO button click
  1077. //
  1078. // Arguments: [hwnd] -- window handle
  1079. //
  1080. // Returns: TRUE
  1081. //
  1082. // Notes:
  1083. //
  1084. //----------------------------------------------------------------------------
  1085. BOOL
  1086. CUnverifiedTrustUI::OnNo (HWND hwnd)
  1087. {
  1088. m_hrInvokeResult = TRUST_E_SUBJECT_NOT_TRUSTED;
  1089. EndDialog(hwnd, (int)m_hrInvokeResult);
  1090. return( TRUE );
  1091. }
  1092. //+---------------------------------------------------------------------------
  1093. //
  1094. // Member: CUnverifiedTrustUI::OnMore, public
  1095. //
  1096. // Synopsis: process the IDMORE button click
  1097. //
  1098. // Arguments: [hwnd] -- window handle
  1099. //
  1100. // Returns: TRUE
  1101. //
  1102. // Notes:
  1103. //
  1104. //----------------------------------------------------------------------------
  1105. BOOL
  1106. CUnverifiedTrustUI::OnMore (HWND hwnd)
  1107. {
  1108. WinHelp(hwnd, "SECAUTH.HLP", HELP_CONTEXT, IDH_SECAUTH_SIGNED_N_INVALID);
  1109. // ACUIViewHTMLHelpTopic(hwnd, "sec_signed_n_invalid.htm");
  1110. return( TRUE );
  1111. }
  1112. //+---------------------------------------------------------------------------
  1113. //
  1114. // Member: CNoSignatureUI::CNoSignatureUI, public
  1115. //
  1116. // Synopsis: Constructor
  1117. //
  1118. // Arguments: [riih] -- invoke info helper
  1119. // [rhr] -- result code reference
  1120. //
  1121. // Returns: (none)
  1122. //
  1123. // Notes:
  1124. //
  1125. //----------------------------------------------------------------------------
  1126. CNoSignatureUI::CNoSignatureUI (CInvokeInfoHelper& riih, HRESULT& rhr)
  1127. : IACUIControl( riih ),
  1128. m_pszInstallAndRun2( NULL ),
  1129. m_pszNoPublisherFound( NULL )
  1130. {
  1131. DWORD_PTR aMessageArgument[2];
  1132. //
  1133. // Format the install and run string
  1134. //
  1135. aMessageArgument[0] = (DWORD_PTR)m_pszCopyActionTextNotSigned;
  1136. aMessageArgument[1] = (DWORD_PTR)m_riih.Subject();
  1137. rhr = FormatACUIResourceString(0, aMessageArgument, &m_pszInstallAndRun2);
  1138. //
  1139. // Format the no publisher found string
  1140. //
  1141. if ( rhr == S_OK )
  1142. {
  1143. aMessageArgument[0] = (DWORD_PTR)m_riih.ErrorStatement();
  1144. rhr = FormatACUIResourceString(
  1145. IDS_NOPUBLISHERFOUND,
  1146. aMessageArgument,
  1147. &m_pszNoPublisherFound
  1148. );
  1149. }
  1150. }
  1151. //+---------------------------------------------------------------------------
  1152. //
  1153. // Member: CNoSignatureUI::~CNoSignatureUI, public
  1154. //
  1155. // Synopsis: Destructor
  1156. //
  1157. // Arguments: (none)
  1158. //
  1159. // Returns: (none)
  1160. //
  1161. // Notes:
  1162. //
  1163. //----------------------------------------------------------------------------
  1164. CNoSignatureUI::~CNoSignatureUI ()
  1165. {
  1166. DELETE_OBJECT(m_pszInstallAndRun2);
  1167. DELETE_OBJECT(m_pszNoPublisherFound);
  1168. }
  1169. //+---------------------------------------------------------------------------
  1170. //
  1171. // Member: CNoSignatureUI::InvokeUI, public
  1172. //
  1173. // Synopsis: invoke the UI
  1174. //
  1175. // Arguments: [hDisplay] -- parent window
  1176. //
  1177. // Returns: S_OK, user trusts the subject
  1178. // TRUST_E_SUBJECT_NOT_TRUSTED, user does NOT trust the subject
  1179. // Any other valid HRESULT
  1180. //
  1181. // Notes:
  1182. //
  1183. //----------------------------------------------------------------------------
  1184. HRESULT
  1185. CNoSignatureUI::InvokeUI (HWND hDisplay)
  1186. {
  1187. HRESULT hr = S_OK;
  1188. //
  1189. // Bring up the dialog
  1190. //
  1191. if ( DialogBoxParamU(
  1192. g_hModule,
  1193. (LPWSTR) MAKEINTRESOURCE(IDD_DIALOG3_NOSIGNATURE),
  1194. hDisplay,
  1195. ACUIMessageProc,
  1196. (LPARAM)this
  1197. ) == -1 )
  1198. {
  1199. return( HRESULT_FROM_WIN32(GetLastError()) );
  1200. }
  1201. //
  1202. // The result has been stored as a member
  1203. //
  1204. return( m_hrInvokeResult );
  1205. }
  1206. //+---------------------------------------------------------------------------
  1207. //
  1208. // Member: CNoSignatureUI::OnInitDialog, public
  1209. //
  1210. // Synopsis: dialog initialization
  1211. //
  1212. // Arguments: [hwnd] -- dialog window
  1213. // [wParam] -- parameter 1
  1214. // [lParam] -- parameter 2
  1215. //
  1216. // Returns: TRUE if successful init, FALSE otherwise
  1217. //
  1218. // Notes:
  1219. //
  1220. //----------------------------------------------------------------------------
  1221. BOOL
  1222. CNoSignatureUI::OnInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam)
  1223. {
  1224. HWND hControl;
  1225. int deltavpos = 0;
  1226. int deltaheight;
  1227. int bmptosep;
  1228. int septodlg;
  1229. RECT rect;
  1230. //
  1231. // Render the install and run string
  1232. //
  1233. deltavpos = RenderACUIStringToEditControl(
  1234. hwnd,
  1235. IDC_INSTALLANDRUN2,
  1236. IDC_NOPUBLISHERFOUND,
  1237. m_pszInstallAndRun2,
  1238. deltavpos,
  1239. FALSE,
  1240. NULL,
  1241. NULL,
  1242. 0,
  1243. NULL
  1244. );
  1245. //
  1246. // Calculate the distances from the bottom of the bitmap to the top
  1247. // of the separator and from the bottom of the separator to the bottom
  1248. // of the dialog
  1249. //
  1250. bmptosep = CalculateControlVerticalDistance(
  1251. hwnd,
  1252. IDC_NOVERBMP,
  1253. IDC_SEPARATORLINE
  1254. );
  1255. septodlg = CalculateControlVerticalDistanceFromDlgBottom(
  1256. hwnd,
  1257. IDC_SEPARATORLINE
  1258. );
  1259. //
  1260. // Render the no publisher found statement
  1261. //
  1262. deltavpos = RenderACUIStringToEditControl(
  1263. hwnd,
  1264. IDC_NOPUBLISHERFOUND,
  1265. IDC_SEPARATORLINE,
  1266. m_pszNoPublisherFound,
  1267. deltavpos,
  1268. FALSE,
  1269. NULL,
  1270. NULL,
  1271. bmptosep,
  1272. NULL
  1273. );
  1274. //
  1275. // Rebase the static line
  1276. //
  1277. hControl = GetDlgItem(hwnd, IDC_SEPARATORLINE);
  1278. RebaseControlVertical(hwnd, hControl, NULL, FALSE, deltavpos, 0, 0, &deltaheight);
  1279. assert( deltaheight == 0 );
  1280. //
  1281. // Rebase the buttons
  1282. //
  1283. hControl = GetDlgItem(hwnd, IDYES);
  1284. RebaseControlVertical(hwnd, hControl, NULL, FALSE, deltavpos, 0, 0, &deltaheight);
  1285. assert( deltaheight == 0 );
  1286. hControl = GetDlgItem(hwnd, IDNO);
  1287. RebaseControlVertical(hwnd, hControl, NULL, FALSE, deltavpos, 0, 0, &deltaheight);
  1288. assert( deltaheight == 0 );
  1289. hControl = GetDlgItem(hwnd, IDMORE);
  1290. RebaseControlVertical(hwnd, hControl, NULL, FALSE, deltavpos, 0, 0, &deltaheight);
  1291. assert( deltaheight == 0 );
  1292. //
  1293. // Resize the bitmap and the dialog rectangle if necessary
  1294. //
  1295. if ( deltavpos > 0 )
  1296. {
  1297. int cyupd;
  1298. hControl = GetDlgItem(hwnd, IDC_NOVERBMP);
  1299. GetWindowRect(hControl, &rect);
  1300. cyupd = CalculateControlVerticalDistance(
  1301. hwnd,
  1302. IDC_NOVERBMP,
  1303. IDC_SEPARATORLINE
  1304. );
  1305. cyupd -= bmptosep;
  1306. SetWindowPos(
  1307. hControl,
  1308. NULL,
  1309. 0,
  1310. 0,
  1311. rect.right - rect.left,
  1312. (rect.bottom - rect.top) + cyupd,
  1313. SWP_NOZORDER | SWP_NOMOVE
  1314. );
  1315. GetWindowRect(hwnd, &rect);
  1316. cyupd = CalculateControlVerticalDistanceFromDlgBottom(
  1317. hwnd,
  1318. IDC_SEPARATORLINE
  1319. );
  1320. cyupd = septodlg - cyupd;
  1321. SetWindowPos(
  1322. hwnd,
  1323. NULL,
  1324. 0,
  1325. 0,
  1326. rect.right - rect.left,
  1327. (rect.bottom - rect.top) + cyupd,
  1328. SWP_NOZORDER | SWP_NOMOVE
  1329. );
  1330. }
  1331. //
  1332. // check for overridden button texts
  1333. //
  1334. this->SetupButtons(hwnd);
  1335. //
  1336. // Set focus to appropriate control
  1337. //
  1338. hControl = GetDlgItem(hwnd, IDNO);
  1339. ::PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM) hControl, (LPARAM) MAKEWORD(TRUE, 0));
  1340. return( FALSE );
  1341. }
  1342. //+---------------------------------------------------------------------------
  1343. //
  1344. // Member: CNoSignatureUI::OnYes, public
  1345. //
  1346. // Synopsis: process IDYES button click
  1347. //
  1348. // Arguments: [hwnd] -- window handle
  1349. //
  1350. // Returns: TRUE
  1351. //
  1352. // Notes:
  1353. //
  1354. //----------------------------------------------------------------------------
  1355. BOOL
  1356. CNoSignatureUI::OnYes (HWND hwnd)
  1357. {
  1358. m_hrInvokeResult = S_OK;
  1359. EndDialog(hwnd, (int)m_hrInvokeResult);
  1360. return( TRUE );
  1361. }
  1362. //+---------------------------------------------------------------------------
  1363. //
  1364. // Member: CNoSignatureUI::OnNo, public
  1365. //
  1366. // Synopsis: process IDNO button click
  1367. //
  1368. // Arguments: [hwnd] -- window handle
  1369. //
  1370. // Returns: TRUE
  1371. //
  1372. // Notes:
  1373. //
  1374. //----------------------------------------------------------------------------
  1375. BOOL
  1376. CNoSignatureUI::OnNo (HWND hwnd)
  1377. {
  1378. m_hrInvokeResult = TRUST_E_SUBJECT_NOT_TRUSTED;
  1379. EndDialog(hwnd, (int)m_hrInvokeResult);
  1380. return( TRUE );
  1381. }
  1382. //+---------------------------------------------------------------------------
  1383. //
  1384. // Member: CNoSignatureUI::OnMore, public
  1385. //
  1386. // Synopsis: process the IDMORE button click
  1387. //
  1388. // Arguments: [hwnd] -- window handle
  1389. //
  1390. // Returns: TRUE
  1391. //
  1392. // Notes:
  1393. //
  1394. //----------------------------------------------------------------------------
  1395. BOOL
  1396. CNoSignatureUI::OnMore (HWND hwnd)
  1397. {
  1398. WinHelp(hwnd, "SECAUTH.HLP", HELP_CONTEXT, IDH_SECAUTH_UNSIGNED);
  1399. // ACUIViewHTMLHelpTopic(hwnd, "sec_unsigned.htm");
  1400. return( TRUE );
  1401. }
  1402. //+---------------------------------------------------------------------------
  1403. //
  1404. // Function: ACUIMessageProc
  1405. //
  1406. // Synopsis: message proc to process UI messages
  1407. //
  1408. // Arguments: [hwnd] -- window
  1409. // [uMsg] -- message id
  1410. // [wParam] -- parameter 1
  1411. // [lParam] -- parameter 2
  1412. //
  1413. // Returns: TRUE if message processing should continue, FALSE otherwise
  1414. //
  1415. // Notes:
  1416. //
  1417. //----------------------------------------------------------------------------
  1418. INT_PTR CALLBACK ACUIMessageProc (
  1419. HWND hwnd,
  1420. UINT uMsg,
  1421. WPARAM wParam,
  1422. LPARAM lParam
  1423. )
  1424. {
  1425. IACUIControl* pUI = NULL;
  1426. //
  1427. // Get the control
  1428. //
  1429. if (uMsg == WM_INITDIALOG)
  1430. {
  1431. pUI = (IACUIControl *)lParam;
  1432. SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam);
  1433. }
  1434. else
  1435. {
  1436. pUI = (IACUIControl *)GetWindowLongPtr(hwnd, DWLP_USER);
  1437. }
  1438. //
  1439. // If we couldn't find it, we must not have set it yet, so ignore this
  1440. // message
  1441. //
  1442. if ( pUI == NULL )
  1443. {
  1444. return( FALSE );
  1445. }
  1446. //
  1447. // Pass the message on to the control
  1448. //
  1449. return( pUI->OnUIMessage(hwnd, uMsg, wParam, lParam) );
  1450. }
  1451. int GetRichEditControlLineHeight(HWND hwnd)
  1452. {
  1453. RECT rect;
  1454. POINT pointInFirstRow;
  1455. POINT pointInSecondRow;
  1456. int secondLineCharIndex;
  1457. int i;
  1458. RECT originalRect;
  1459. GetWindowRect(hwnd, &originalRect);
  1460. //
  1461. // HACK ALERT, believe it or not there is no way to get the height of the current
  1462. // font in the edit control, so get the position a character in the first row and the position
  1463. // of a character in the second row, and do the subtraction to get the
  1464. // height of the font
  1465. //
  1466. SendMessageA(hwnd, EM_POSFROMCHAR, (WPARAM) &pointInFirstRow, (LPARAM) 0);
  1467. //
  1468. // HACK ON TOP OF HACK ALERT,
  1469. // since there may not be a second row in the edit box, keep reducing the width
  1470. // by half until the first row falls over into the second row, then get the position
  1471. // of the first char in the second row and finally reset the edit box size back to
  1472. // it's original size
  1473. //
  1474. secondLineCharIndex = (int)SendMessageA(hwnd, EM_LINEINDEX, (WPARAM) 1, (LPARAM) 0);
  1475. if (secondLineCharIndex == -1)
  1476. {
  1477. for (i=0; i<20; i++)
  1478. {
  1479. GetWindowRect(hwnd, &rect);
  1480. SetWindowPos( hwnd,
  1481. NULL,
  1482. 0,
  1483. 0,
  1484. (rect.right-rect.left)/2,
  1485. rect.bottom-rect.top,
  1486. SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
  1487. secondLineCharIndex = (int)SendMessageA(hwnd, EM_LINEINDEX, (WPARAM) 1, (LPARAM) 0);
  1488. if (secondLineCharIndex != -1)
  1489. {
  1490. break;
  1491. }
  1492. }
  1493. if (secondLineCharIndex == -1)
  1494. {
  1495. // if we failed after twenty tries just reset the control to its original size
  1496. // and get the heck outa here!!
  1497. SetWindowPos(hwnd,
  1498. NULL,
  1499. 0,
  1500. 0,
  1501. originalRect.right-originalRect.left,
  1502. originalRect.bottom-originalRect.top,
  1503. SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
  1504. return 0;
  1505. }
  1506. SendMessageA(hwnd, EM_POSFROMCHAR, (WPARAM) &pointInSecondRow, (LPARAM) secondLineCharIndex);
  1507. SetWindowPos(hwnd,
  1508. NULL,
  1509. 0,
  1510. 0,
  1511. originalRect.right-originalRect.left,
  1512. originalRect.bottom-originalRect.top,
  1513. SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
  1514. }
  1515. else
  1516. {
  1517. SendMessageA(hwnd, EM_POSFROMCHAR, (WPARAM) &pointInSecondRow, (LPARAM) secondLineCharIndex);
  1518. }
  1519. return (pointInSecondRow.y - pointInFirstRow.y);
  1520. }
  1521. //+---------------------------------------------------------------------------
  1522. //
  1523. // Function: RebaseControlVertical
  1524. //
  1525. // Synopsis: Take the window control, if it has to be resized for text, do
  1526. // so. Reposition it adjusted for delta pos and return any
  1527. // height difference for the text resizing
  1528. //
  1529. // Arguments: [hwndDlg] -- host dialog
  1530. // [hwnd] -- control
  1531. // [hwndNext] -- next control
  1532. // [fResizeForText] -- resize for text flag
  1533. // [deltavpos] -- delta vertical position
  1534. // [oline] -- original number of lines
  1535. // [minsep] -- minimum separator
  1536. // [pdeltaheight] -- delta in control height
  1537. //
  1538. // Returns: (none)
  1539. //
  1540. // Notes:
  1541. //
  1542. //----------------------------------------------------------------------------
  1543. VOID RebaseControlVertical (
  1544. HWND hwndDlg,
  1545. HWND hwnd,
  1546. HWND hwndNext,
  1547. BOOL fResizeForText,
  1548. int deltavpos,
  1549. int oline,
  1550. int minsep,
  1551. int* pdeltaheight
  1552. )
  1553. {
  1554. int x = 0;
  1555. int y = 0;
  1556. int odn = 0;
  1557. int orig_w;
  1558. RECT rect;
  1559. RECT rectNext;
  1560. RECT rectDlg;
  1561. TEXTMETRIC tm;
  1562. //
  1563. // Set the delta height to zero for now. If we resize the text
  1564. // a new one will be calculated
  1565. //
  1566. *pdeltaheight = 0;
  1567. //
  1568. // Get the control window rectangle
  1569. //
  1570. GetWindowRect(hwnd, &rect);
  1571. GetWindowRect(hwndNext, &rectNext);
  1572. odn = rectNext.top - rect.bottom;
  1573. orig_w = rect.right - rect.left;
  1574. MapWindowPoints(NULL, hwndDlg, (LPPOINT) &rect, 2);
  1575. //
  1576. // If we have to resize the control due to text, find out what font
  1577. // is being used and the number of lines of text. From that we'll
  1578. // calculate what the new height for the control is and set it up
  1579. //
  1580. if ( fResizeForText == TRUE )
  1581. {
  1582. HDC hdc;
  1583. HFONT hfont;
  1584. HFONT hfontOld;
  1585. int cline;
  1586. int h;
  1587. int w;
  1588. int dh;
  1589. int lineHeight;
  1590. //
  1591. // Get the metrics of the current control font
  1592. //
  1593. hdc = GetDC(hwnd);
  1594. if (hdc == NULL)
  1595. {
  1596. hdc = GetDC(NULL);
  1597. if (hdc == NULL)
  1598. {
  1599. return;
  1600. }
  1601. }
  1602. hfont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
  1603. if ( hfont == NULL )
  1604. {
  1605. hfont = (HFONT)SendMessage(hwndDlg, WM_GETFONT, 0, 0);
  1606. }
  1607. hfontOld = (HFONT)SelectObject(hdc, hfont);
  1608. GetTextMetrics(hdc, &tm);
  1609. lineHeight = GetRichEditControlLineHeight(hwnd);
  1610. if (lineHeight == 0)
  1611. {
  1612. lineHeight = tm.tmHeight;
  1613. }
  1614. //
  1615. // Set the minimum separation value
  1616. //
  1617. if ( minsep == 0 )
  1618. {
  1619. minsep = lineHeight;
  1620. }
  1621. //
  1622. // Calculate the width and the new height needed
  1623. //
  1624. cline = (int)SendMessage(hwnd, EM_GETLINECOUNT, 0, 0);
  1625. h = cline * lineHeight;
  1626. w = GetEditControlMaxLineWidth(hwnd, hdc, cline);
  1627. w += 3; // a little bump to make sure string will fit
  1628. if (w > orig_w)
  1629. {
  1630. w = orig_w;
  1631. }
  1632. SelectObject(hdc, hfontOld);
  1633. ReleaseDC(hwnd, hdc);
  1634. //
  1635. // Calculate an addition to height by checking how much space was
  1636. // left when there were the original # of lines and making sure that
  1637. // that amount is still left when we do any adjustments
  1638. //
  1639. h += ( ( rect.bottom - rect.top ) - ( oline * lineHeight ) );
  1640. dh = h - ( rect.bottom - rect.top );
  1641. //
  1642. // If the current height is too small, adjust for it, otherwise
  1643. // leave the current height and just adjust for the width
  1644. //
  1645. if ( dh > 0 )
  1646. {
  1647. SetWindowPos(hwnd, NULL, 0, 0, w, h, SWP_NOZORDER | SWP_NOMOVE);
  1648. }
  1649. else
  1650. {
  1651. SetWindowPos(
  1652. hwnd,
  1653. NULL,
  1654. 0,
  1655. 0,
  1656. w,
  1657. ( rect.bottom - rect.top ),
  1658. SWP_NOZORDER | SWP_NOMOVE
  1659. );
  1660. }
  1661. if ( cline < SendMessage(hwnd, EM_GETLINECOUNT, 0, 0) )
  1662. {
  1663. AdjustEditControlWidthToLineCount(hwnd, cline, &tm);
  1664. }
  1665. }
  1666. //
  1667. // If we have to use deltavpos then calculate the X and the new Y
  1668. // and set the window position appropriately
  1669. //
  1670. if ( deltavpos != 0 )
  1671. {
  1672. GetWindowRect(hwndDlg, &rectDlg);
  1673. MapWindowPoints(NULL, hwndDlg, (LPPOINT) &rectDlg, 2);
  1674. x = rect.left - rectDlg.left - GetSystemMetrics(SM_CXEDGE);
  1675. y = rect.top - rectDlg.top - GetSystemMetrics(SM_CYCAPTION) + deltavpos;
  1676. SetWindowPos(hwnd, NULL, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
  1677. }
  1678. //
  1679. // Get the window rect for the next control and see what the distance
  1680. // is between the current control and it. With that we must now
  1681. // adjust our deltaheight, if the distance to the next control is less
  1682. // than a line height then make it a line height, otherwise just let it
  1683. // be
  1684. //
  1685. if ( hwndNext != NULL )
  1686. {
  1687. int dn;
  1688. GetWindowRect(hwnd, &rect);
  1689. GetWindowRect(hwndNext, &rectNext);
  1690. dn = rectNext.top - rect.bottom;
  1691. if ( odn > minsep )
  1692. {
  1693. if ( dn < minsep )
  1694. {
  1695. *pdeltaheight = minsep - dn;
  1696. }
  1697. }
  1698. else
  1699. {
  1700. if ( dn < odn )
  1701. {
  1702. *pdeltaheight = odn - dn;
  1703. }
  1704. }
  1705. }
  1706. }
  1707. //+---------------------------------------------------------------------------
  1708. //
  1709. // Function: ACUISetArrowCursorSubclass
  1710. //
  1711. // Synopsis: subclass routine for setting the arrow cursor. This can be
  1712. // set on multiline edit routines used in the dialog UIs for
  1713. // the default Authenticode provider
  1714. //
  1715. // Arguments: [hwnd] -- window handle
  1716. // [uMsg] -- message id
  1717. // [wParam] -- parameter 1
  1718. // [lParam] -- parameter 2
  1719. //
  1720. // Returns: TRUE if message handled, FALSE otherwise
  1721. //
  1722. // Notes:
  1723. //
  1724. //----------------------------------------------------------------------------
  1725. LRESULT CALLBACK ACUISetArrowCursorSubclass (
  1726. HWND hwnd,
  1727. UINT uMsg,
  1728. WPARAM wParam,
  1729. LPARAM lParam
  1730. )
  1731. {
  1732. HDC hdc;
  1733. WNDPROC wndproc;
  1734. PAINTSTRUCT ps;
  1735. wndproc = (WNDPROC)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  1736. switch ( uMsg )
  1737. {
  1738. case WM_SETCURSOR:
  1739. SetCursor(LoadCursor(NULL, IDC_ARROW));
  1740. return( TRUE );
  1741. break;
  1742. case WM_CHAR:
  1743. if ( wParam != (WPARAM)' ' )
  1744. {
  1745. break;
  1746. }
  1747. case WM_LBUTTONDOWN:
  1748. if ( hwnd == GetDlgItem(GetParent(hwnd), IDC_PERSONALTRUST) )
  1749. {
  1750. int check;
  1751. HWND hwndCheck;
  1752. //
  1753. // Toggle the check state of the PTCHECK control if the
  1754. // personal trust statement is clicked on
  1755. //
  1756. hwndCheck = GetDlgItem(GetParent(hwnd), IDC_PTCHECK);
  1757. check = (int)SendMessage(hwndCheck, BM_GETCHECK, 0, 0);
  1758. if ( check == BST_CHECKED )
  1759. {
  1760. check = BST_UNCHECKED;
  1761. }
  1762. else if ( check == BST_UNCHECKED )
  1763. {
  1764. check = BST_CHECKED;
  1765. }
  1766. else
  1767. {
  1768. check = BST_UNCHECKED;
  1769. }
  1770. SendMessage(hwndCheck, BM_SETCHECK, (WPARAM)check, 0);
  1771. SetFocus(hwnd);
  1772. return( TRUE );
  1773. }
  1774. return(TRUE);
  1775. case WM_LBUTTONDBLCLK:
  1776. case WM_MBUTTONDBLCLK:
  1777. case WM_RBUTTONDBLCLK:
  1778. case WM_RBUTTONUP:
  1779. case WM_MBUTTONUP:
  1780. case WM_RBUTTONDOWN:
  1781. case WM_MBUTTONDOWN:
  1782. return( TRUE );
  1783. break;
  1784. case EM_SETSEL:
  1785. return( TRUE );
  1786. break;
  1787. case WM_PAINT:
  1788. CallWindowProc(wndproc, hwnd, uMsg, wParam, lParam);
  1789. if ( hwnd == GetFocus() )
  1790. {
  1791. DrawFocusRectangle(hwnd, NULL);
  1792. }
  1793. return( TRUE );
  1794. break;
  1795. case WM_SETFOCUS:
  1796. if ( hwnd != GetDlgItem(GetParent(hwnd), IDC_PERSONALTRUST) )
  1797. {
  1798. SetFocus(GetNextDlgTabItem(GetParent(hwnd), hwnd, FALSE));
  1799. return( TRUE );
  1800. }
  1801. else
  1802. {
  1803. InvalidateRect(hwnd, NULL, FALSE);
  1804. UpdateWindow(hwnd);
  1805. SetCursor(LoadCursor(NULL, IDC_ARROW));
  1806. return( TRUE );
  1807. }
  1808. break;
  1809. case WM_KILLFOCUS:
  1810. InvalidateRect(hwnd, NULL, TRUE);
  1811. UpdateWindow(hwnd);
  1812. return( TRUE );
  1813. }
  1814. return(CallWindowProc(wndproc, hwnd, uMsg, wParam, lParam));
  1815. }
  1816. //+---------------------------------------------------------------------------
  1817. //
  1818. // Function: SubclassEditControlForArrowCursor
  1819. //
  1820. // Synopsis: subclasses edit control so that the arrow cursor can replace
  1821. // the edit bar
  1822. //
  1823. // Arguments: [hwndEdit] -- edit control
  1824. //
  1825. // Returns: (none)
  1826. //
  1827. // Notes:
  1828. //
  1829. //----------------------------------------------------------------------------
  1830. VOID SubclassEditControlForArrowCursor (HWND hwndEdit)
  1831. {
  1832. LONG_PTR PrevWndProc;
  1833. PrevWndProc = GetWindowLongPtr(hwndEdit, GWLP_WNDPROC);
  1834. SetWindowLongPtr(hwndEdit, GWLP_USERDATA, (LONG_PTR)PrevWndProc);
  1835. SetWindowLongPtr(hwndEdit, GWLP_WNDPROC, (LONG_PTR)ACUISetArrowCursorSubclass);
  1836. }
  1837. //+---------------------------------------------------------------------------
  1838. //
  1839. // Function: SubclassEditControlForLink
  1840. //
  1841. // Synopsis: subclasses the edit control for a link using the link subclass
  1842. // data
  1843. //
  1844. // Arguments: [hwndDlg] -- dialog
  1845. // [hwndEdit] -- edit control
  1846. // [wndproc] -- window proc to subclass with
  1847. // [plsd] -- data to pass on to window proc
  1848. //
  1849. // Returns: (none)
  1850. //
  1851. // Notes:
  1852. //
  1853. //----------------------------------------------------------------------------
  1854. VOID SubclassEditControlForLink (
  1855. HWND hwndDlg,
  1856. HWND hwndEdit,
  1857. WNDPROC wndproc,
  1858. PTUI_LINK_SUBCLASS_DATA plsd
  1859. )
  1860. {
  1861. HWND hwndTip;
  1862. plsd->hwndTip = CreateWindowA(
  1863. TOOLTIPS_CLASSA,
  1864. (LPSTR)NULL,
  1865. WS_POPUP | TTS_ALWAYSTIP,
  1866. CW_USEDEFAULT,
  1867. CW_USEDEFAULT,
  1868. CW_USEDEFAULT,
  1869. CW_USEDEFAULT,
  1870. hwndDlg,
  1871. (HMENU)NULL,
  1872. g_hModule,
  1873. NULL
  1874. );
  1875. if ( plsd->hwndTip != NULL )
  1876. {
  1877. TOOLINFOA tia;
  1878. DWORD cb;
  1879. LPSTR psz;
  1880. memset(&tia, 0, sizeof(TOOLINFOA));
  1881. tia.cbSize = sizeof(TOOLINFOA);
  1882. tia.hwnd = hwndEdit;
  1883. tia.uId = 1;
  1884. tia.hinst = g_hModule;
  1885. //GetClientRect(hwndEdit, &tia.rect);
  1886. SendMessage(hwndEdit, EM_GETRECT, 0, (LPARAM)&tia.rect);
  1887. //
  1888. // if plsd->uToolTipText is a string then convert it
  1889. //
  1890. if (plsd->uToolTipText &0xffff0000)
  1891. {
  1892. cb = WideCharToMultiByte(
  1893. 0,
  1894. 0,
  1895. (LPWSTR)plsd->uToolTipText,
  1896. -1,
  1897. NULL,
  1898. 0,
  1899. NULL,
  1900. NULL);
  1901. if (NULL == (psz = new char[cb]))
  1902. {
  1903. return;
  1904. }
  1905. WideCharToMultiByte(
  1906. 0,
  1907. 0,
  1908. (LPWSTR)plsd->uToolTipText,
  1909. -1,
  1910. psz,
  1911. cb,
  1912. NULL,
  1913. NULL);
  1914. tia.lpszText = psz;
  1915. }
  1916. else
  1917. {
  1918. tia.lpszText = (LPSTR)plsd->uToolTipText;
  1919. }
  1920. SendMessage(plsd->hwndTip, TTM_ADDTOOL, 0, (LPARAM)&tia);
  1921. if (plsd->uToolTipText &0xffff0000)
  1922. {
  1923. delete[] psz;
  1924. }
  1925. }
  1926. plsd->fMouseCaptured = FALSE;
  1927. plsd->wpPrev = (WNDPROC)GetWindowLongPtr(hwndEdit, GWLP_WNDPROC);
  1928. SetWindowLongPtr(hwndEdit, GWLP_USERDATA, (LONG_PTR)plsd);
  1929. SetWindowLongPtr(hwndEdit, GWLP_WNDPROC, (LONG_PTR)wndproc);
  1930. }
  1931. //+---------------------------------------------------------------------------
  1932. //
  1933. // Function: ACUILinkSubclass
  1934. //
  1935. // Synopsis: subclass for the publisher link
  1936. //
  1937. // Arguments: [hwnd] -- window handle
  1938. // [uMsg] -- message id
  1939. // [wParam] -- parameter 1
  1940. // [lParam] -- parameter 2
  1941. //
  1942. // Returns: TRUE if message handled, FALSE otherwise
  1943. //
  1944. // Notes:
  1945. //
  1946. //----------------------------------------------------------------------------
  1947. LRESULT CALLBACK ACUILinkSubclass (
  1948. HWND hwnd,
  1949. UINT uMsg,
  1950. WPARAM wParam,
  1951. LPARAM lParam
  1952. )
  1953. {
  1954. PTUI_LINK_SUBCLASS_DATA plsd;
  1955. CInvokeInfoHelper* piih;
  1956. plsd = (PTUI_LINK_SUBCLASS_DATA)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  1957. piih = (CInvokeInfoHelper *)plsd->pvData;
  1958. switch ( uMsg )
  1959. {
  1960. case WM_SETCURSOR:
  1961. if (!plsd->fMouseCaptured)
  1962. {
  1963. SetCapture(hwnd);
  1964. plsd->fMouseCaptured = TRUE;
  1965. }
  1966. SetCursor(LoadCursor((HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE),
  1967. MAKEINTRESOURCE(IDC_TUIHAND)));
  1968. return( TRUE );
  1969. break;
  1970. case WM_CHAR:
  1971. if ( wParam != (WPARAM)' ')
  1972. {
  1973. break;
  1974. }
  1975. // fall through to wm_lbuttondown....
  1976. case WM_LBUTTONDOWN:
  1977. SetFocus(hwnd);
  1978. switch(plsd->uId)
  1979. {
  1980. case IDC_PUBLISHER:
  1981. piih->CallCertViewProperties(plsd->hwndParent);
  1982. break;
  1983. case IDC_INSTALLANDRUN:
  1984. piih->CallWebLink(plsd->hwndParent, (WCHAR *)piih->ControlWebPage());
  1985. break;
  1986. case IDC_AUTHENTICITY:
  1987. piih->CallWebLink(plsd->hwndParent, (WCHAR *)piih->CAWebPage());
  1988. break;
  1989. case IDC_ADVANCED:
  1990. piih->CallAdvancedLink(plsd->hwndParent);
  1991. break;
  1992. }
  1993. return( TRUE );
  1994. case WM_LBUTTONDBLCLK:
  1995. case WM_MBUTTONDBLCLK:
  1996. case WM_RBUTTONDBLCLK:
  1997. case WM_RBUTTONUP:
  1998. case WM_MBUTTONUP:
  1999. case WM_RBUTTONDOWN:
  2000. case WM_MBUTTONDOWN:
  2001. return( TRUE );
  2002. case EM_SETSEL:
  2003. return( TRUE );
  2004. case WM_PAINT:
  2005. CallWindowProc(plsd->wpPrev, hwnd, uMsg, wParam, lParam);
  2006. if ( hwnd == GetFocus() )
  2007. {
  2008. DrawFocusRectangle(hwnd, NULL);
  2009. }
  2010. return( TRUE );
  2011. case WM_SETFOCUS:
  2012. if ( hwnd == GetFocus() )
  2013. {
  2014. InvalidateRect(hwnd, NULL, FALSE);
  2015. UpdateWindow(hwnd);
  2016. SetCursor(LoadCursor((HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE),
  2017. MAKEINTRESOURCE(IDC_TUIHAND)));
  2018. return( TRUE );
  2019. }
  2020. break;
  2021. case WM_KILLFOCUS:
  2022. InvalidateRect(hwnd, NULL, TRUE);
  2023. UpdateWindow(hwnd);
  2024. SetCursor(LoadCursor(NULL, IDC_ARROW));
  2025. return( TRUE );
  2026. case WM_MOUSEMOVE:
  2027. MSG msg;
  2028. DWORD dwCharLine;
  2029. CHARFORMAT sCharFmt;
  2030. RECT rect;
  2031. int xPos, yPos;
  2032. memset(&msg, 0, sizeof(MSG));
  2033. msg.hwnd = hwnd;
  2034. msg.message = uMsg;
  2035. msg.wParam = wParam;
  2036. msg.lParam = lParam;
  2037. SendMessage(plsd->hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
  2038. // check to see if the mouse is in this windows rect, if not, then reset
  2039. // the cursor to an arrow and release the mouse
  2040. GetClientRect(hwnd, &rect);
  2041. xPos = LOWORD(lParam);
  2042. yPos = HIWORD(lParam);
  2043. if ((xPos < 0) ||
  2044. (yPos < 0) ||
  2045. (xPos > (rect.right - rect.left)) ||
  2046. (yPos > (rect.bottom - rect.top)))
  2047. {
  2048. SetCursor(LoadCursor(NULL, IDC_ARROW));
  2049. ReleaseCapture();
  2050. plsd->fMouseCaptured = FALSE;
  2051. }
  2052. /*
  2053. warning!
  2054. EM_CHARFROMPOS gets an access violation!
  2055. dwCharLine = SendMessage(hwnd, EM_CHARFROMPOS, 0, lParam);
  2056. if (dwCharLine == (-1))
  2057. {
  2058. return(TRUE);
  2059. }
  2060. SendMessage(hwnd, EM_SETSEL, (WPARAM)LOWORD(dwCharLine), (LPARAM)(LOWORD(dwCharLine) + 1));
  2061. memset(&sCharFmt, 0x00, sizeof(CHARFORMAT));
  2062. sCharFmt.cbSize = sizeof(CHARFORMAT);
  2063. SendMessage(hwnd, EM_GETCHARFORMAT, TRUE, (LPARAM)&sCharFmt);
  2064. if (sCharFmt.dwEffects & CFE_UNDERLINE)
  2065. {
  2066. SetCursor(LoadCursor((HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE),
  2067. MAKEINTRESOURCE(IDC_TUIHAND)));
  2068. }
  2069. else
  2070. {
  2071. SetCursor(LoadCursor(NULL, IDC_ARROW));
  2072. }
  2073. */
  2074. return( TRUE );
  2075. }
  2076. return(CallWindowProc(plsd->wpPrev, hwnd, uMsg, wParam, lParam));
  2077. }
  2078. //+---------------------------------------------------------------------------
  2079. //
  2080. // Function: FormatACUIResourceString
  2081. //
  2082. // Synopsis: formats a string given a resource id and message arguments
  2083. //
  2084. // Arguments: [StringResourceId] -- resource id
  2085. // [aMessageArgument] -- message arguments
  2086. // [ppszFormatted] -- formatted string goes here
  2087. //
  2088. // Returns: S_OK if successful, any valid HRESULT otherwise
  2089. //
  2090. //----------------------------------------------------------------------------
  2091. HRESULT FormatACUIResourceString (
  2092. UINT StringResourceId,
  2093. DWORD_PTR* aMessageArgument,
  2094. LPWSTR* ppszFormatted
  2095. )
  2096. {
  2097. HRESULT hr = S_OK;
  2098. WCHAR sz[MAX_LOADSTRING_BUFFER];
  2099. LPVOID pvMsg;
  2100. pvMsg = NULL;
  2101. sz[0] = NULL;
  2102. //
  2103. // Load the string resource and format the message with that string and
  2104. // the message arguments
  2105. //
  2106. if (StringResourceId != 0)
  2107. {
  2108. if ( LoadStringU(g_hModule, StringResourceId, sz, MAX_LOADSTRING_BUFFER) == 0 )
  2109. {
  2110. return(HRESULT_FROM_WIN32(GetLastError()));
  2111. }
  2112. if ( FormatMessageU(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING |
  2113. FORMAT_MESSAGE_ARGUMENT_ARRAY, sz, 0, 0, (LPWSTR)&pvMsg, 0,
  2114. (va_list *)aMessageArgument) == 0)
  2115. {
  2116. hr = HRESULT_FROM_WIN32(GetLastError());
  2117. }
  2118. }
  2119. else
  2120. {
  2121. if ( FormatMessageU(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING |
  2122. FORMAT_MESSAGE_ARGUMENT_ARRAY, (char *)aMessageArgument[0], 0, 0,
  2123. (LPWSTR)&pvMsg, 0, (va_list *)&aMessageArgument[1]) == 0)
  2124. {
  2125. hr = HRESULT_FROM_WIN32(GetLastError());
  2126. }
  2127. }
  2128. if (pvMsg)
  2129. {
  2130. *ppszFormatted = new WCHAR[wcslen((WCHAR *)pvMsg) + 1];
  2131. if (*ppszFormatted)
  2132. {
  2133. wcscpy(*ppszFormatted, (WCHAR *)pvMsg);
  2134. }
  2135. LocalFree(pvMsg);
  2136. }
  2137. return( hr );
  2138. }
  2139. //+---------------------------------------------------------------------------
  2140. //
  2141. // Function: RenderACUIStringToEditControl
  2142. //
  2143. // Synopsis: renders a string to the control given and if requested, gives
  2144. // it a link look and feel, subclassed to the wndproc and plsd
  2145. // given
  2146. //
  2147. // Arguments: [hwndDlg] -- dialog window handle
  2148. // [ControlId] -- control id
  2149. // [NextControlId] -- next control id
  2150. // [psz] -- string
  2151. // [deltavpos] -- delta vertical position
  2152. // [fLink] -- a link?
  2153. // [wndproc] -- optional wndproc, valid if fLink == TRUE
  2154. // [plsd] -- optional plsd, valid if fLink === TRUE
  2155. // [minsep] -- minimum separation
  2156. // [pszThisTextOnlyInLink -- only change this text.
  2157. //
  2158. // Returns: delta in height of the control
  2159. //
  2160. // Notes:
  2161. //
  2162. //----------------------------------------------------------------------------
  2163. int RenderACUIStringToEditControl (
  2164. HWND hwndDlg,
  2165. UINT ControlId,
  2166. UINT NextControlId,
  2167. LPCWSTR psz,
  2168. int deltavpos,
  2169. BOOL fLink,
  2170. WNDPROC wndproc,
  2171. PTUI_LINK_SUBCLASS_DATA plsd,
  2172. int minsep,
  2173. LPCWSTR pszThisTextOnlyInLink
  2174. )
  2175. {
  2176. HWND hControl;
  2177. int deltaheight = 0;
  2178. int oline = 0;
  2179. int hkcharpos;
  2180. //
  2181. // Get the control and set the text on it, make sure the background
  2182. // is right if it is a rich edit control
  2183. //
  2184. hControl = GetDlgItem(hwndDlg, ControlId);
  2185. oline = (int)SendMessage(hControl, EM_GETLINECOUNT, 0, 0);
  2186. CryptUISetRicheditTextW(hwndDlg, ControlId, L"");
  2187. CryptUISetRicheditTextW(hwndDlg, ControlId, psz); //SetWindowTextU(hControl, psz);
  2188. //
  2189. // If there is a '&' in the string, then get rid of it
  2190. //
  2191. hkcharpos = GetHotKeyCharPosition(hControl);
  2192. if (IDC_PERSONALTRUST == ControlId && hkcharpos != 0)
  2193. {
  2194. CHARRANGE cr;
  2195. CHARFORMAT cf;
  2196. cr.cpMin = hkcharpos - 1;
  2197. cr.cpMax = hkcharpos;
  2198. SendMessage(hControl, EM_EXSETSEL, 0, (LPARAM) &cr);
  2199. SendMessage(hControl, EM_REPLACESEL, FALSE, (LPARAM) "");
  2200. cr.cpMin = -1;
  2201. cr.cpMax = 0;
  2202. SendMessage(hControl, EM_EXSETSEL, 0, (LPARAM) &cr);
  2203. }
  2204. SendMessage(
  2205. hControl,
  2206. EM_SETBKGNDCOLOR,
  2207. 0,
  2208. (LPARAM)GetSysColor(COLOR_3DFACE)
  2209. );
  2210. //
  2211. // If we have a link then update for the link look
  2212. //
  2213. if ( fLink == TRUE )
  2214. {
  2215. CHARFORMAT cf;
  2216. memset(&cf, 0, sizeof(CHARFORMAT));
  2217. cf.cbSize = sizeof(CHARFORMAT);
  2218. cf.dwMask = CFM_COLOR | CFM_UNDERLINE;
  2219. cf.crTextColor = RGB(0, 0, 255);
  2220. cf.dwEffects |= CFM_UNDERLINE;
  2221. if (pszThisTextOnlyInLink)
  2222. {
  2223. FINDTEXTEX ft;
  2224. DWORD pos;
  2225. char *pszOnlyThis;
  2226. DWORD cb;
  2227. cb = WideCharToMultiByte(
  2228. 0,
  2229. 0,
  2230. pszThisTextOnlyInLink,
  2231. -1,
  2232. NULL,
  2233. 0,
  2234. NULL,
  2235. NULL);
  2236. if (NULL == (pszOnlyThis = new char[cb]))
  2237. {
  2238. return 0;
  2239. }
  2240. WideCharToMultiByte(
  2241. 0,
  2242. 0,
  2243. pszThisTextOnlyInLink,
  2244. -1,
  2245. pszOnlyThis,
  2246. cb,
  2247. NULL,
  2248. NULL);
  2249. memset(&ft, 0x00, sizeof(FINDTEXTEX));
  2250. ft.chrg.cpMin = 0;
  2251. ft.chrg.cpMax = (-1);
  2252. ft.lpstrText = (char *)pszOnlyThis;
  2253. if ((pos = (DWORD)SendMessage(hControl, EM_FINDTEXTEX, 0, (LPARAM)&ft)) != (-1))
  2254. {
  2255. SendMessage(hControl, EM_EXSETSEL, 0, (LPARAM)&ft.chrgText);
  2256. SendMessage(hControl, EM_SETCHARFORMAT, SCF_WORD | SCF_SELECTION, (LPARAM)&cf);
  2257. ft.chrgText.cpMin = 0;
  2258. ft.chrgText.cpMax = 0;
  2259. SendMessage(hControl, EM_EXSETSEL, 0, (LPARAM)&ft.chrgText);
  2260. }
  2261. delete[] pszOnlyThis;
  2262. }
  2263. else
  2264. {
  2265. SendMessage(hControl, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
  2266. }
  2267. }
  2268. //
  2269. // Rebase the control
  2270. //
  2271. RebaseControlVertical(
  2272. hwndDlg,
  2273. hControl,
  2274. GetDlgItem(hwndDlg, NextControlId),
  2275. TRUE,
  2276. deltavpos,
  2277. oline,
  2278. minsep,
  2279. &deltaheight
  2280. );
  2281. //
  2282. // If we have the link look then we must subclass for the appropriate
  2283. // link feel, otherwise we subclass for a static text control feel
  2284. //
  2285. if ( fLink == TRUE )
  2286. {
  2287. SubclassEditControlForLink(hwndDlg, hControl, wndproc, plsd);
  2288. }
  2289. else
  2290. {
  2291. SubclassEditControlForArrowCursor(hControl);
  2292. }
  2293. return( deltaheight );
  2294. }
  2295. //+---------------------------------------------------------------------------
  2296. //
  2297. // Function: CalculateControlVerticalDistance
  2298. //
  2299. // Synopsis: calculates the vertical distance from the bottom of Control1
  2300. // to the top of Control2
  2301. //
  2302. // Arguments: [hwnd] -- parent dialog
  2303. // [Control1] -- first control
  2304. // [Control2] -- second control
  2305. //
  2306. // Returns: the distance in pixels
  2307. //
  2308. // Notes: assumes control1 is above control2
  2309. //
  2310. //----------------------------------------------------------------------------
  2311. int CalculateControlVerticalDistance (HWND hwnd, UINT Control1, UINT Control2)
  2312. {
  2313. RECT rect1;
  2314. RECT rect2;
  2315. GetWindowRect(GetDlgItem(hwnd, Control1), &rect1);
  2316. GetWindowRect(GetDlgItem(hwnd, Control2), &rect2);
  2317. return( rect2.top - rect1.bottom );
  2318. }
  2319. //+---------------------------------------------------------------------------
  2320. //
  2321. // Function: CalculateControlVerticalDistanceFromDlgBottom
  2322. //
  2323. // Synopsis: calculates the distance from the bottom of the control to
  2324. // the bottom of the dialog
  2325. //
  2326. // Arguments: [hwnd] -- dialog
  2327. // [Control] -- control
  2328. //
  2329. // Returns: the distance in pixels
  2330. //
  2331. // Notes:
  2332. //
  2333. //----------------------------------------------------------------------------
  2334. int CalculateControlVerticalDistanceFromDlgBottom (HWND hwnd, UINT Control)
  2335. {
  2336. RECT rect;
  2337. RECT rectControl;
  2338. GetClientRect(hwnd, &rect);
  2339. GetWindowRect(GetDlgItem(hwnd, Control), &rectControl);
  2340. return( rect.bottom - rectControl.bottom );
  2341. }
  2342. //+---------------------------------------------------------------------------
  2343. //
  2344. // Function: ACUICenterWindow
  2345. //
  2346. // Synopsis: centers the given window
  2347. //
  2348. // Arguments: [hWndToCenter] -- window handle
  2349. //
  2350. // Returns: (none)
  2351. //
  2352. // Notes: This code was stolen from ATL and hacked upon madly :-)
  2353. //
  2354. //----------------------------------------------------------------------------
  2355. VOID ACUICenterWindow (HWND hWndToCenter)
  2356. {
  2357. HWND hWndCenter;
  2358. // determine owner window to center against
  2359. DWORD dwStyle = (DWORD)GetWindowLong(hWndToCenter, GWL_STYLE);
  2360. if(dwStyle & WS_CHILD)
  2361. hWndCenter = ::GetParent(hWndToCenter);
  2362. else
  2363. hWndCenter = ::GetWindow(hWndToCenter, GW_OWNER);
  2364. if (hWndCenter == NULL)
  2365. {
  2366. return;
  2367. }
  2368. // get coordinates of the window relative to its parent
  2369. RECT rcDlg;
  2370. ::GetWindowRect(hWndToCenter, &rcDlg);
  2371. RECT rcArea;
  2372. RECT rcCenter;
  2373. HWND hWndParent;
  2374. if(!(dwStyle & WS_CHILD))
  2375. {
  2376. // don't center against invisible or minimized windows
  2377. if(hWndCenter != NULL)
  2378. {
  2379. DWORD dwStyle2 = ::GetWindowLong(hWndCenter, GWL_STYLE);
  2380. if(!(dwStyle2 & WS_VISIBLE) || (dwStyle2 & WS_MINIMIZE))
  2381. hWndCenter = NULL;
  2382. }
  2383. // center within screen coordinates
  2384. ::SystemParametersInfo(SPI_GETWORKAREA, NULL, &rcArea, NULL);
  2385. if(hWndCenter == NULL)
  2386. rcCenter = rcArea;
  2387. else
  2388. ::GetWindowRect(hWndCenter, &rcCenter);
  2389. }
  2390. else
  2391. {
  2392. // center within parent client coordinates
  2393. hWndParent = ::GetParent(hWndToCenter);
  2394. ::GetClientRect(hWndParent, &rcArea);
  2395. ::GetClientRect(hWndCenter, &rcCenter);
  2396. ::MapWindowPoints(hWndCenter, hWndParent, (POINT*)&rcCenter, 2);
  2397. }
  2398. int DlgWidth = rcDlg.right - rcDlg.left;
  2399. int DlgHeight = rcDlg.bottom - rcDlg.top;
  2400. // find dialog's upper left based on rcCenter
  2401. int xLeft = (rcCenter.left + rcCenter.right) / 2 - DlgWidth / 2;
  2402. int yTop = (rcCenter.top + rcCenter.bottom) / 2 - DlgHeight / 2;
  2403. // if the dialog is outside the screen, move it inside
  2404. if(xLeft < rcArea.left)
  2405. xLeft = rcArea.left;
  2406. else if(xLeft + DlgWidth > rcArea.right)
  2407. xLeft = rcArea.right - DlgWidth;
  2408. if(yTop < rcArea.top)
  2409. yTop = rcArea.top;
  2410. else if(yTop + DlgHeight > rcArea.bottom)
  2411. yTop = rcArea.bottom - DlgHeight;
  2412. // map screen coordinates to child coordinates
  2413. ::SetWindowPos(
  2414. hWndToCenter,
  2415. HWND_TOPMOST,
  2416. xLeft,
  2417. yTop,
  2418. -1,
  2419. -1,
  2420. SWP_NOSIZE | SWP_NOACTIVATE
  2421. );
  2422. }
  2423. //+---------------------------------------------------------------------------
  2424. //
  2425. // Function: ACUIViewHTMLHelpTopic
  2426. //
  2427. // Synopsis: html help viewer
  2428. //
  2429. // Arguments: [hwnd] -- caller window
  2430. // [pszTopic] -- topic
  2431. //
  2432. // Returns: (none)
  2433. //
  2434. // Notes:
  2435. //
  2436. //----------------------------------------------------------------------------
  2437. VOID ACUIViewHTMLHelpTopic (HWND hwnd, LPSTR pszTopic)
  2438. {
  2439. // HtmlHelpA(
  2440. // hwnd,
  2441. // "%SYSTEMROOT%\\help\\iexplore.chm>large_context",
  2442. // HH_DISPLAY_TOPIC,
  2443. // (DWORD)pszTopic
  2444. // );
  2445. }
  2446. //+---------------------------------------------------------------------------
  2447. //
  2448. // Function: GetEditControlMaxLineWidth
  2449. //
  2450. // Synopsis: gets the maximum line width of the edit control
  2451. //
  2452. //----------------------------------------------------------------------------
  2453. int GetEditControlMaxLineWidth (HWND hwndEdit, HDC hdc, int cline)
  2454. {
  2455. int index;
  2456. int line;
  2457. int charwidth;
  2458. int maxwidth = 0;
  2459. CHAR szMaxBuffer[1024];
  2460. WCHAR wsz[1024];
  2461. TEXTRANGEA tr;
  2462. SIZE size;
  2463. tr.lpstrText = szMaxBuffer;
  2464. for ( line = 0; line < cline; line++ )
  2465. {
  2466. index = (int)SendMessage(hwndEdit, EM_LINEINDEX, (WPARAM)line, 0);
  2467. charwidth = (int)SendMessage(hwndEdit, EM_LINELENGTH, (WPARAM)index, 0);
  2468. tr.chrg.cpMin = index;
  2469. tr.chrg.cpMax = index + charwidth;
  2470. SendMessage(hwndEdit, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
  2471. wsz[0] = NULL;
  2472. MultiByteToWideChar(0, 0, (const char *)tr.lpstrText, -1, &wsz[0], 1024);
  2473. if (wsz[0])
  2474. {
  2475. GetTextExtentPoint32W(hdc, &wsz[0], charwidth, &size);
  2476. if ( size.cx > maxwidth )
  2477. {
  2478. maxwidth = size.cx;
  2479. }
  2480. }
  2481. }
  2482. return( maxwidth );
  2483. }
  2484. //+---------------------------------------------------------------------------
  2485. //
  2486. // Function: DrawFocusRectangle
  2487. //
  2488. // Synopsis: draws the focus rectangle for the edit control
  2489. //
  2490. //----------------------------------------------------------------------------
  2491. void DrawFocusRectangle (HWND hwnd, HDC hdc)
  2492. {
  2493. RECT rect;
  2494. PAINTSTRUCT ps;
  2495. BOOL fReleaseDC = FALSE;
  2496. if ( hdc == NULL )
  2497. {
  2498. hdc = GetDC(hwnd);
  2499. if ( hdc == NULL )
  2500. {
  2501. return;
  2502. }
  2503. fReleaseDC = TRUE;
  2504. }
  2505. GetClientRect(hwnd, &rect);
  2506. DrawFocusRect(hdc, &rect);
  2507. if ( fReleaseDC == TRUE )
  2508. {
  2509. ReleaseDC(hwnd, hdc);
  2510. }
  2511. }
  2512. //+---------------------------------------------------------------------------
  2513. //
  2514. // Function: GetHotKeyCharPositionFromString
  2515. //
  2516. // Synopsis: gets the character position for the hotkey, zero means
  2517. // no-hotkey
  2518. //
  2519. //----------------------------------------------------------------------------
  2520. int GetHotKeyCharPositionFromString (LPWSTR pwszText)
  2521. {
  2522. LPWSTR psz = pwszText;
  2523. while ( ( psz = wcschr(psz, L'&') ) != NULL )
  2524. {
  2525. psz++;
  2526. if ( *psz != L'&' )
  2527. {
  2528. break;
  2529. }
  2530. }
  2531. if ( psz == NULL )
  2532. {
  2533. return( 0 );
  2534. }
  2535. return (int)(( psz - pwszText ) );
  2536. }
  2537. //+---------------------------------------------------------------------------
  2538. //
  2539. // Function: GetHotKeyCharPosition
  2540. //
  2541. // Synopsis: gets the character position for the hotkey, zero means
  2542. // no-hotkey
  2543. //
  2544. //----------------------------------------------------------------------------
  2545. int GetHotKeyCharPosition (HWND hwnd)
  2546. {
  2547. int nPos = 0;
  2548. WCHAR szText[MAX_LOADSTRING_BUFFER] = L"";
  2549. if (GetWindowTextU(hwnd, szText, MAX_LOADSTRING_BUFFER))
  2550. {
  2551. nPos = GetHotKeyCharPositionFromString(szText);
  2552. }
  2553. return nPos;
  2554. }
  2555. //+---------------------------------------------------------------------------
  2556. //
  2557. // Function: FormatHotKeyOnEditControl
  2558. //
  2559. // Synopsis: formats the hot key on an edit control by making it underlined
  2560. //
  2561. //----------------------------------------------------------------------------
  2562. VOID FormatHotKeyOnEditControl (HWND hwnd, int hkcharpos)
  2563. {
  2564. CHARRANGE cr;
  2565. CHARFORMAT cf;
  2566. assert( hkcharpos != 0 );
  2567. cr.cpMin = hkcharpos - 1;
  2568. cr.cpMax = hkcharpos;
  2569. SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&cr);
  2570. memset(&cf, 0, sizeof(CHARFORMAT));
  2571. cf.cbSize = sizeof(CHARFORMAT);
  2572. cf.dwMask = CFM_UNDERLINE;
  2573. cf.dwEffects |= CFM_UNDERLINE;
  2574. SendMessage(hwnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
  2575. cr.cpMin = -1;
  2576. cr.cpMax = 0;
  2577. SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&cr);
  2578. }
  2579. //+---------------------------------------------------------------------------
  2580. //
  2581. // Function: AdjustEditControlWidthToLineCount
  2582. //
  2583. // Synopsis: adjust edit control width to the given line count
  2584. //
  2585. //----------------------------------------------------------------------------
  2586. void AdjustEditControlWidthToLineCount(HWND hwnd, int cline, TEXTMETRIC* ptm)
  2587. {
  2588. RECT rect;
  2589. int w;
  2590. int h;
  2591. GetWindowRect(hwnd, &rect);
  2592. h = rect.bottom - rect.top;
  2593. w = rect.right - rect.left;
  2594. while ( cline < SendMessage(hwnd, EM_GETLINECOUNT, 0, 0) )
  2595. {
  2596. w += ptm->tmMaxCharWidth;
  2597. SetWindowPos(hwnd, NULL, 0, 0, w, h, SWP_NOZORDER | SWP_NOMOVE);
  2598. printf(
  2599. "Line count adjusted to = %d\n",
  2600. (DWORD) SendMessage(hwnd, EM_GETLINECOUNT, 0, 0)
  2601. );
  2602. }
  2603. }