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.

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