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.

1253 lines
36 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1992 **/
  4. /**********************************************************************/
  5. /*
  6. MPRMisc.cxx
  7. This file contains miscellaneous support routines for the MPR DLL.
  8. FILE HISTORY:
  9. Johnl 08-Jan-1992 Created
  10. Congpay 25-Oct-1992 Add ShowReconectDialog,
  11. ErrorDialog,
  12. RECONNECT_INFO_WINDOW class,
  13. and ERROR_DIALOG class
  14. YiHsinS 23-Dec-1992 Added GetNetworkDisplayName
  15. */
  16. #define INCL_DOSERRORS
  17. #define INCL_NETLIB
  18. #define INCL_NETERRORS
  19. #define INCL_WINDOWS
  20. #include <lmui.hxx>
  21. #define INCL_BLT_MSGPOPUP
  22. #define INCL_BLT_DIALOG
  23. #define INCL_BLT_CONTROL
  24. #include <blt.hxx>
  25. #include <dbgstr.hxx>
  26. #include <strnumer.hxx> // DEC_STR
  27. extern "C"
  28. {
  29. #include <helpnums.h>
  30. #include <mprconn.h>
  31. #include <mpr.h>
  32. #include <uirsrc.h>
  33. #include <winnetp.h>
  34. #include <windowsx.h> // Edit_LimitText
  35. #include <wincred.h> // CredUI
  36. }
  37. #include <mprmisc.hxx>
  38. //
  39. // Globals
  40. //
  41. HINSTANCE g_hInstance;
  42. static ULONG
  43. s_aulHelpIds[] =
  44. {
  45. IDD_PASSWORD, IDH_PASSWORD,
  46. 0,0
  47. };
  48. //
  49. // Structures
  50. //
  51. struct ERRORDLGPARAMETERS
  52. {
  53. HANDLE hDoneErrorDlg;
  54. const TCHAR * pchDevice;
  55. const TCHAR * pchResource;
  56. const TCHAR * pchProvider;
  57. DWORD dwError;
  58. BOOL fDisconnect;
  59. BOOL fContinue;
  60. BOOL fHideErrors;
  61. DWORD dwExtError;
  62. const TCHAR * pchErrorText;
  63. const TCHAR * pchErrorProvider;
  64. };
  65. typedef struct
  66. {
  67. LPTSTR lpRemoteName;
  68. LPTSTR lpUserName;
  69. LPTSTR lpPassword;
  70. ULONG cbPassword;
  71. LPBOOL pfDidCancel;
  72. }
  73. PWDPARAMS, *LPPWDPARAMS;
  74. BOOL
  75. MprUIRegister(
  76. HINSTANCE DllHandle
  77. );
  78. VOID
  79. MprUIDeregister(
  80. VOID
  81. );
  82. INT_PTR CALLBACK
  83. PasswordDlgProc(
  84. HWND hWnd,
  85. UINT uMsg,
  86. WPARAM wParam,
  87. LPARAM lParam
  88. );
  89. VOID
  90. InvokeWinHelp(
  91. UINT message,
  92. WPARAM wParam,
  93. LPARAM lParam,
  94. LPCWSTR wszHelpFileName,
  95. ULONG aulControlIdToHelpIdMap[]
  96. );
  97. APIERR
  98. ErrorDialog(
  99. HWND hwndParent,
  100. const TCHAR *pchText1,
  101. const TCHAR *pchText2,
  102. const TCHAR *pchText3,
  103. BOOL fAllowCancel,
  104. BOOL *pfDisconnect,
  105. BOOL *pfContinue,
  106. BOOL *pfHideErrors
  107. );
  108. DWORD ShowErrorDialog (
  109. HWND hwndParent,
  110. const TCHAR * pchDevice,
  111. const TCHAR * pchResource,
  112. const TCHAR * pchProvider,
  113. DWORD dwError,
  114. BOOL fAllowCancel,
  115. BOOL * pfDisconnect,
  116. BOOL * pfContinue,
  117. BOOL * pfHideErrors,
  118. DWORD dwExtError,
  119. const TCHAR * pchErrorText,
  120. const TCHAR * pchErrorProvider
  121. )
  122. {
  123. APIERR err = NERR_Success;
  124. do //Error break out.
  125. {
  126. NLS_STR nlsDevice ( pchDevice);
  127. NLS_STR nlsResource( pchResource );
  128. NLS_STR nlsProvider( pchProvider );
  129. NLS_STR nlsErrorText;
  130. if (((err = nlsDevice.QueryError()) != NERR_Success) ||
  131. ((err = nlsResource.QueryError()) != NERR_Success) ||
  132. ((err = nlsProvider.QueryError()) != NERR_Success) ||
  133. ((err = nlsErrorText.QueryError())!= NERR_Success))
  134. {
  135. break;
  136. }
  137. STACK_NLS_STR (nlsErrNum, CCH_INT);
  138. const NLS_STR * apnlsParamStrings[6];
  139. // Find the error text.
  140. if (dwError == WN_EXTENDED_ERROR)
  141. {
  142. DEC_STR nlsError( (ULONG)dwExtError );
  143. if (((err = nlsError.QueryError()) != NERR_Success) ||
  144. ((err = nlsErrNum.CopyFrom( nlsError )) != NERR_Success) ||
  145. ((err = nlsErrorText.CopyFrom( pchErrorText)) != NERR_Success) ||
  146. ((err = nlsProvider.CopyFrom (pchErrorProvider)) != NERR_Success))
  147. {
  148. break;
  149. }
  150. }
  151. else
  152. {
  153. if (dwError == WN_CANCEL)
  154. err = nlsErrorText.Load ((MSGID) IDS_NO_PASSWORD);
  155. else
  156. err = nlsErrorText.Load ((MSGID) dwError );
  157. if (err != NERR_Success)
  158. break;
  159. }
  160. if (nlsDevice.QueryTextLength() == 0)
  161. {
  162. if (nlsDevice.Load(IDS_DEVICELESS_CONNECTION_NAME) != NERR_Success)
  163. nlsDevice = NULL ; // alwats succeeds.
  164. }
  165. apnlsParamStrings[0] = &nlsDevice;
  166. apnlsParamStrings[1] = &nlsResource;
  167. apnlsParamStrings[2] = &nlsProvider;
  168. apnlsParamStrings[3] = &nlsErrNum;
  169. apnlsParamStrings[4] = &nlsErrorText;
  170. apnlsParamStrings[5] = NULL;
  171. if (pfDisconnect == NULL) // Used by winfile.
  172. {
  173. MSGID msgid = IERR_ProfileLoadError;
  174. MsgPopup (hwndParent,
  175. msgid,
  176. MPSEV_WARNING,
  177. (ULONG)HC_NO_HELP, //HC_CONNECT_ERROR,
  178. MP_OK,
  179. (NLS_STR **) apnlsParamStrings,
  180. MP_OK);
  181. }
  182. else // Used by log on procedure.
  183. {
  184. RESOURCE_STR nlsText1((MSGID) IERR_TEXT1);
  185. nlsText1.InsertParams( apnlsParamStrings );
  186. RESOURCE_STR nlsText2((MSGID) IERR_TEXT2);
  187. nlsText2.InsertParams( apnlsParamStrings );
  188. RESOURCE_STR nlsText3((MSGID) IERR_TEXT3);
  189. nlsText3.InsertParams( apnlsParamStrings );
  190. if (((err = nlsText1.QueryError()) != NERR_Success) ||
  191. ((err = nlsText2.QueryError()) != NERR_Success) ||
  192. ((err = nlsText3.QueryError()) != NERR_Success))
  193. {
  194. break;
  195. }
  196. err = ErrorDialog (hwndParent,
  197. nlsText1.QueryPch(),
  198. nlsText2.QueryPch(),
  199. nlsText3.QueryPch(),
  200. fAllowCancel,
  201. pfDisconnect,
  202. pfContinue,
  203. pfHideErrors);
  204. }
  205. } while (FALSE);
  206. if (err != NERR_Success)
  207. {
  208. MsgPopup (hwndParent, (MSGID) err);
  209. }
  210. return (err);
  211. }
  212. /*******************************************************************
  213. NAME: DllMain
  214. SYNOPSIS: DLL entry point
  215. ENTRY: DllHandle - Instance handle of this DLL
  216. Reason - The reason for which this routine is being called.
  217. This might be one of the following:
  218. DLL_PROCESS_ATTACH
  219. DLL_THREAD_ATTACH
  220. DLL_THREAD_DETACH
  221. DLL_PROCESS_DETACH
  222. lpReserved -
  223. EXIT:
  224. RETURNS: TRUE if successful, FALSE otherwise
  225. NOTES:
  226. HISTORY:
  227. ChuckC 27-Jul-1992 Created
  228. ********************************************************************/
  229. BOOL
  230. DllMain(
  231. HINSTANCE DllHandle,
  232. DWORD Reason,
  233. LPVOID lpReserved
  234. )
  235. {
  236. UNREFERENCED(lpReserved);
  237. if (Reason == DLL_PROCESS_ATTACH)
  238. {
  239. g_hInstance = DllHandle;
  240. DisableThreadLibraryCalls(DllHandle);
  241. // initialize BLT, etc.
  242. if ( !MprUIRegister(DllHandle) )
  243. return FALSE ;
  244. }
  245. else if (Reason == DLL_PROCESS_DETACH)
  246. {
  247. MprUIDeregister() ;
  248. }
  249. return(TRUE);
  250. }
  251. /*******************************************************************
  252. NAME: MprUIRegister
  253. SYNOPSIS: UI Side registration function, called upon DLL Initialization
  254. ENTRY: DllHandle - Instance handle of this DLL
  255. EXIT:
  256. RETURNS: TRUE if successful, FALSE otherwise
  257. NOTES:
  258. HISTORY:
  259. Johnl 08-Jan-1992 Created
  260. beng 03-Aug-1992 Changes for dllization of BLT
  261. ********************************************************************/
  262. BOOL
  263. MprUIRegister(
  264. HINSTANCE DllHandle
  265. )
  266. {
  267. APIERR err = BLT::Init( DllHandle,
  268. IDRSRC_MPRUI_BASE, IDRSRC_MPRUI_LAST,
  269. IDS_UI_MPR_BASE, IDS_UI_MPR_LAST ) ;
  270. if ( err )
  271. {
  272. DBGEOL("::MprUIRegister - BLT Failed to initialize, error code "
  273. << err ) ;
  274. return FALSE ;
  275. }
  276. err = BLT::RegisterHelpFile( DllHandle, IDS_MPRHELPFILENAME,
  277. HC_UI_MPR_BASE, HC_UI_MPR_LAST );
  278. if ( err )
  279. {
  280. DBGEOL("::MprUIRegister - BLT Help File Failed to initialize, error code " << err ) ;
  281. return FALSE ;
  282. }
  283. return TRUE ;
  284. }
  285. /*******************************************************************
  286. NAME: MprUIDeregister
  287. SYNOPSIS: UI Side uninitialization, called upon DLL process detach
  288. NOTES:
  289. HISTORY:
  290. Johnl 08-Jan-1992 Created
  291. beng 03-Aug-1992 Changes for dllization of BLT
  292. ********************************************************************/
  293. VOID
  294. MprUIDeregister(
  295. VOID
  296. )
  297. {
  298. if (g_hInstance != NULL)
  299. {
  300. BLT::DeregisterHelpFile(g_hInstance, 0);
  301. BLT::Term(g_hInstance);
  302. g_hInstance = NULL;
  303. }
  304. }
  305. /*******************************************************************
  306. NAME: MsgExtendedError
  307. SYNOPSIS: Retrieves the last error using WNetGetLastError and puts
  308. up a MsgPopup with the error information.
  309. ENTRY: This should be called immediately after WN_EXTENDED_ERROR
  310. is returned from a WNet* API.
  311. powin - Pointer to owner window we should use for the MsgPopup
  312. EXIT:
  313. NOTES:
  314. HISTORY:
  315. Johnl 09-Jan-1992 Created
  316. ********************************************************************/
  317. void MsgExtendedError( HWND hwndParent )
  318. {
  319. APIERR err ;
  320. BUFFER buffErrorText( 256*sizeof(TCHAR) ) ;
  321. BUFFER buffProviderName( 256*sizeof(TCHAR) ) ;
  322. if ( (err = buffErrorText.QueryError()) ||
  323. (err = buffProviderName.QueryError()) )
  324. {
  325. MsgPopup( hwndParent, (MSGID) err ) ;
  326. return ;
  327. }
  328. DWORD dwErr ;
  329. switch ( WNetGetLastError( &dwErr,
  330. (LPTSTR) buffErrorText.QueryPtr(),
  331. (DWORD) buffErrorText.QuerySize()/sizeof(TCHAR),
  332. (LPTSTR) buffProviderName.QueryPtr(),
  333. (DWORD) buffProviderName.QuerySize()/sizeof(TCHAR) ))
  334. {
  335. case WN_SUCCESS:
  336. break ;
  337. case WN_BAD_POINTER:
  338. default:
  339. MsgPopup( hwndParent, (MSGID) ERROR_GEN_FAILURE ) ;
  340. return ;
  341. }
  342. ALIAS_STR nlsProvider( (const TCHAR *) buffProviderName.QueryPtr() );
  343. ALIAS_STR nlsErrorText( (const TCHAR *) buffErrorText.QueryPtr() );
  344. DEC_STR nlsError( dwErr );
  345. if ( (err = nlsError.QueryError()) != NERR_Success )
  346. {
  347. ::MsgPopup( hwndParent, err );
  348. }
  349. else
  350. {
  351. NLS_STR *apnls[4];
  352. apnls[0] = &nlsProvider;
  353. apnls[1] = &nlsError;
  354. apnls[2] = &nlsErrorText;
  355. apnls[3] = NULL;
  356. ::MsgPopup( hwndParent,
  357. IDS_WN_EXTENDED_ERROR,
  358. MPSEV_ERROR,
  359. (ULONG)HC_NO_HELP,
  360. MP_OK,
  361. apnls );
  362. }
  363. }
  364. /*******************************************************************
  365. NAME: GetNetworkDisplayName
  366. SYNOPSIS: Helper function
  367. ENTRY:
  368. EXIT:
  369. NOTES:
  370. HISTORY:
  371. YiHsinS 23-Dec-1992 Created
  372. ********************************************************************/
  373. APIERR
  374. GetNetworkDisplayName(
  375. const TCHAR *pszProvider,
  376. const TCHAR *pszRemoteName,
  377. DWORD dwFlags,
  378. DWORD dwAveCharPerLine,
  379. NLS_STR *pnls )
  380. {
  381. APIERR err = NERR_Success;
  382. BUFFER buf( MAX_PATH * sizeof( TCHAR) );
  383. DWORD dwbufsize = buf.QuerySize() / sizeof( TCHAR );
  384. if ( (err = buf.QueryError()) != NERR_Success )
  385. {
  386. return err;
  387. }
  388. do
  389. {
  390. err = WNetFormatNetworkName(
  391. pszProvider,
  392. pszRemoteName,
  393. (LPTSTR) buf.QueryPtr(),
  394. &dwbufsize,
  395. dwFlags,
  396. dwAveCharPerLine );
  397. if ( err == NERR_Success )
  398. {
  399. pnls->CopyFrom( (TCHAR *) buf.QueryPtr() );
  400. break;
  401. }
  402. else if ( err == WN_MORE_DATA )
  403. {
  404. err = buf.Resize( (UINT) dwbufsize * sizeof( TCHAR ));
  405. if ( err != NERR_Success )
  406. {
  407. break;
  408. }
  409. }
  410. else
  411. {
  412. err = pnls->CopyFrom( pszRemoteName );
  413. break;
  414. }
  415. }
  416. while ( TRUE );
  417. return err;
  418. }
  419. /*******************************************************************
  420. NAME: MPRUI_WNetClearConnections
  421. SYNOPSIS: Cancels all active connections using force. No prompting
  422. is currently performed.
  423. ENTRY: hWndParent - Parent window handle in case we ever want to
  424. prompt/warn the user
  425. RETURNS: Standard windows/winnet error code
  426. NOTES:
  427. HISTORY:
  428. Johnl 19-Mar-1992 Created
  429. ********************************************************************/
  430. DWORD
  431. MPRUI_WNetClearConnections(
  432. HWND hWndParent
  433. )
  434. {
  435. UNREFERENCED( hWndParent ) ;
  436. APIERR err ;
  437. /* Now, for any UNC connections still connected, disconnect each one
  438. */
  439. HANDLE hEnum;
  440. DWORD dwErr = WNetOpenEnum( RESOURCE_CONNECTED,
  441. RESOURCETYPE_ANY,
  442. 0, // ignored
  443. NULL,
  444. &hEnum ) ;
  445. switch (dwErr)
  446. {
  447. case WN_SUCCESS:
  448. {
  449. DWORD dwEnumErr;
  450. BUFFER buf( 4096 );
  451. dwEnumErr = buf.QueryError() ;
  452. while ( dwEnumErr == NERR_Success )
  453. {
  454. DWORD dwCount = 0xffffffff; // Return as many as possible
  455. DWORD dwBuffSize = buf.QuerySize() ;
  456. dwEnumErr = WNetEnumResource( hEnum,
  457. &dwCount,
  458. buf.QueryPtr(),
  459. &dwBuffSize );
  460. switch ( dwEnumErr )
  461. {
  462. case WN_SUCCESS:
  463. {
  464. NETRESOURCE * pnetres;
  465. pnetres = (NETRESOURCE * )buf.QueryPtr();
  466. for (INT i = 0; dwCount ; dwCount--, i++ )
  467. {
  468. //
  469. // Ignore these errors. Delete device there is one
  470. // else delete UNC.
  471. //
  472. if ((pnetres+i)->lpLocalName &&
  473. (pnetres+i)->lpLocalName[0])
  474. {
  475. dwEnumErr = (APIERR)
  476. WNetCancelConnection2(
  477. (pnetres+i)->lpLocalName,
  478. 0,
  479. TRUE ) ;
  480. }
  481. else
  482. {
  483. dwEnumErr = (APIERR)
  484. WNetCancelConnection2(
  485. (pnetres+i)->lpRemoteName,
  486. 0,
  487. TRUE ) ;
  488. }
  489. }
  490. }
  491. break ;
  492. /* The buffer wasn't big enough for even one entry
  493. * resize it and try again.
  494. */
  495. case WN_MORE_DATA:
  496. {
  497. if (dwEnumErr = buf.Resize( buf.QuerySize()*2 ))
  498. break ;
  499. }
  500. /* Continue looping
  501. */
  502. dwEnumErr = WN_SUCCESS ;
  503. break ;
  504. case WN_NO_MORE_ENTRIES:
  505. // Success code, fall out of loop and map below
  506. case WN_EXTENDED_ERROR:
  507. case WN_NO_NETWORK:
  508. break ;
  509. case WN_BAD_HANDLE:
  510. default:
  511. break;
  512. } //switch
  513. } //while
  514. WNetCloseEnum( hEnum );
  515. err = (dwEnumErr==WN_NO_MORE_ENTRIES ) ? NERR_Success : dwEnumErr ;
  516. }
  517. break;
  518. case WN_NO_NETWORK:
  519. case WN_EXTENDED_ERROR:
  520. err = dwErr ;
  521. break ;
  522. case WN_NOT_CONTAINER:
  523. case WN_BAD_VALUE:
  524. default:
  525. //
  526. // Unknown return code.
  527. //
  528. DBGEOL( SZ("MPRUI_WNetClearConnections - Unexpected return code - ") << (ULONG)dwErr );
  529. err = ERROR_GEN_FAILURE ;
  530. break;
  531. }
  532. return (DWORD) err ;
  533. }
  534. /*******************************************************************
  535. NAME: MPRUI_DoPasswordDialog
  536. SYNOPSIS: Displays a dialog to get the password for a resource
  537. ENTRY: hwndOwner - owner window.
  538. pchResource - pointer to the name of resource to be connected.
  539. pchUserName - pointer to the user's net logon name.
  540. pchPasswordReturnBuffer - buffer in which password returned.
  541. cbPasswordReturnBuffer - size of buffer (in bytes).
  542. pfDidCancel - TRUE if user cancelled, FALSE if user pressed OK.
  543. EXIT: FALSE if dialog could not be processed
  544. NOTES:
  545. HISTORY:
  546. jonn 02-Apr-1992 Templated from mprconn.cxx
  547. congpay 28-Jan-1993 Modified it.
  548. jschwart 24-Sep-1998 Rewritten using Win32 and C-S help
  549. ********************************************************************/
  550. DWORD
  551. MPRUI_DoPasswordDialog(
  552. HWND hwndOwner,
  553. LPWSTR wszResource,
  554. LPWSTR wszUserName,
  555. LPWSTR wszPasswordReturnBuffer,
  556. ULONG cbPasswordReturnBuffer,
  557. BOOL * pfDidCancel,
  558. DWORD dwError
  559. )
  560. {
  561. ASSERT(wszResource != NULL);
  562. ASSERT(wszPasswordReturnBuffer != NULL);
  563. ASSERT(cbPasswordReturnBuffer >= sizeof(WCHAR) * (PWLEN + 1));
  564. ASSERT(pfDidCancel != NULL);
  565. CREDUI_INFO uiInfo = { sizeof(uiInfo), hwndOwner, NULL, NULL, NULL };
  566. WCHAR wszText[MAX_PATH + 71]; // Space for the path and the error text itself
  567. DWORD dwCredErr;
  568. DWORD dwCredUIFlags = CREDUI_FLAGS_DO_NOT_PERSIST |
  569. CREDUI_FLAGS_GENERIC_CREDENTIALS;
  570. if (LoadString(GetModuleHandle(L"mprui.dll"),
  571. (dwError == ERROR_ACCOUNT_DISABLED) ? IDS_ACCOUNT_DISABLED : IDS_PASSWORD,
  572. wszText,
  573. 70) != 0)
  574. {
  575. wcsncat(wszText, wszResource, MAX_PATH);
  576. wszText[MAX_PATH + 70] = L'\0';
  577. uiInfo.pszMessageText = wszText;
  578. }
  579. dwCredErr = CredUIPromptForCredentials(&uiInfo,
  580. wszResource,
  581. NULL,
  582. dwError,
  583. wszUserName,
  584. CRED_MAX_USERNAME_LENGTH,
  585. wszPasswordReturnBuffer,
  586. cbPasswordReturnBuffer / sizeof(WCHAR) - 1,
  587. NULL,
  588. dwCredUIFlags);
  589. if ( dwCredErr == ERROR_CANCELLED ) {
  590. *pfDidCancel = TRUE;
  591. dwCredErr = NO_ERROR;
  592. } else {
  593. *pfDidCancel = FALSE;
  594. }
  595. return dwCredErr;
  596. }
  597. /*******************************************************************
  598. NAME: ERROR_DIALOG class
  599. SYNOPSIS: Used by ErrorDialog function.
  600. PARENT: DIALOG_WINDOW.
  601. Public: ERROR_DIALOG constructor
  602. Entry: hwndParent Parent window.
  603. fAllowCancel Boolean variable that let you choose one
  604. of the two dialogs.
  605. pchText1 Point to the text string in the first line.
  606. pchText2 Point to the text string in the second line.
  607. pchText3 Point to the text string in the third line
  608. pfDisconnect TRUE if the checkbox is checked.
  609. pfHideErrors TRUE if the checkbox is checked.
  610. NOTES:
  611. HISTORY:
  612. congpay 14-Oct-1992 Created.
  613. ********************************************************************/
  614. ERROR_DIALOG::ERROR_DIALOG (HWND hwndParent,
  615. const TCHAR *pchText1,
  616. const TCHAR *pchText2,
  617. const TCHAR *pchText3,
  618. BOOL *pfDisconnect,
  619. BOOL fAllowCancel,
  620. BOOL *pfHideErrors)
  621. : DIALOG_WINDOW (MAKEINTRESOURCE(fAllowCancel ? IDD_ERRORWITHCANCEL_DLG
  622. : IDD_ERROR_DLG),
  623. hwndParent),
  624. _sltText1 (this, IDD_TEXT1),
  625. _sltText2 (this, IDD_TEXT2),
  626. _sltText3 (this, IDD_TEXT3),
  627. _chkCancelConnection (this, IDD_CHKCANCELCONNECTION),
  628. _pchkHideErrors (NULL),
  629. _pfDisconnect (pfDisconnect),
  630. _pfHideErrors (pfHideErrors),
  631. _fAllowCancel (fAllowCancel)
  632. {
  633. if (fAllowCancel)
  634. _pchkHideErrors = new CHECKBOX(this, IDD_CHKHIDEERRORS);
  635. _sltText1.SetText (pchText1);
  636. _sltText2.SetText (pchText2);
  637. _sltText3.SetText (pchText3);
  638. ::SetFocus(GetDlgItem(QueryHwnd(), IDOK));
  639. return;
  640. }
  641. ERROR_DIALOG::~ERROR_DIALOG()
  642. {
  643. delete _pchkHideErrors;
  644. }
  645. BOOL ERROR_DIALOG::OnCancel()
  646. {
  647. *_pfDisconnect = _chkCancelConnection.QueryCheck();
  648. Dismiss (!_fAllowCancel);
  649. return (TRUE);
  650. }
  651. BOOL ERROR_DIALOG::OnOK()
  652. {
  653. *_pfDisconnect = _chkCancelConnection.QueryCheck();
  654. if (_pchkHideErrors != NULL)
  655. *_pfHideErrors = _pchkHideErrors->QueryCheck();
  656. Dismiss (TRUE);
  657. return (TRUE);
  658. }
  659. ULONG ERROR_DIALOG::QueryHelpContext()
  660. {
  661. return HC_RECONNECTDIALOG_ERROR;
  662. }
  663. /*******************************************************************
  664. NAME: ErrorDialog
  665. SYNOPSIS: Displays a dialog to show the error. The dialog has a
  666. check box to delete the connection.
  667. ENTRY: HWND hwndParent - Parent Window.
  668. DWORD dwResource - dialog ID.
  669. const TCHAR *pchText1 - pointer to the string to be printed out.
  670. const TCHAR *pchText2 - pointer to the string to be printed out.
  671. const TCHAR *pchText3 - pointer to the string to be printed out.
  672. BOOL *pfDisconnect - point to TRUE if the checkbox is checked.
  673. BOOL *pfContinue - point to TRUE if OK or Yes button is pressed.
  674. And to FALSE IF No button is pressed.
  675. BOOL *pfHideErrors - point to TRUE iff user asks to
  676. hide further errors
  677. EXIT: non zero if OK is pressed.
  678. 0 if CANCEL IS pressed.
  679. NOTES: Used by RECONNECT_INFO_WINDOW class.
  680. HISTORY:
  681. congpay 14-Oct-1992 Created.
  682. ********************************************************************/
  683. APIERR ErrorDialog(HWND hwndParent,
  684. const TCHAR *pchText1,
  685. const TCHAR *pchText2,
  686. const TCHAR *pchText3,
  687. BOOL fAllowCancel,
  688. BOOL *pfDisconnect,
  689. BOOL *pfContinue,
  690. BOOL *pfHideErrors)
  691. {
  692. ERROR_DIALOG *ppdlg = new
  693. ERROR_DIALOG (hwndParent,
  694. pchText1,
  695. pchText2,
  696. pchText3,
  697. pfDisconnect,
  698. fAllowCancel,
  699. pfHideErrors);
  700. APIERR err = (ppdlg == NULL)?
  701. ERROR_NOT_ENOUGH_MEMORY : ppdlg -> QueryError();
  702. if (err == NERR_Success)
  703. err = ppdlg->Process(pfContinue);
  704. delete ppdlg;
  705. return (err);
  706. }
  707. /*******************************************************************
  708. NAME: RECONNECT_INFO_WINDOW class
  709. SYNOPSIS: Used by MPRUI_ShowReconnectDialog function.
  710. PARENT: DIALOG_WINDOW.
  711. Public: RECONNECT_INFO_WINDOW - constructor
  712. Entry: hwndParent - Parent window.
  713. pszResource - pointer of the dialog resource file.
  714. cidTarget - the id of LTEXT where the connection is going
  715. to be shown.
  716. pfCancel - point to TRUE if Cancel button is pressed.
  717. NOTES:
  718. HISTORY:
  719. congpay 14-Oct-1992 Created.
  720. ********************************************************************/
  721. RECONNECT_INFO_WINDOW::RECONNECT_INFO_WINDOW (HWND hwndParent,
  722. const TCHAR *pszResource,
  723. CID cidTarget,
  724. BOOL * pfCancel)
  725. : DIALOG_WINDOW (pszResource, hwndParent),
  726. _sltTarget (this, cidTarget),
  727. _pfCancel (pfCancel)
  728. {
  729. // Hide this dialog - the UI should be removed ASAP, but JSchwart estimated there isn't time for Whistler
  730. SetPos(XYPOINT(10000,10000), NULL);
  731. *_pfCancel = FALSE;
  732. return;
  733. }
  734. VOID RECONNECT_INFO_WINDOW::SetText (TCHAR *pszResource)
  735. {
  736. _sltTarget.SetText (pszResource);
  737. }
  738. BOOL RECONNECT_INFO_WINDOW::OnCancel()
  739. {
  740. *_pfCancel = TRUE;
  741. Dismiss (FALSE);
  742. return (TRUE);
  743. }
  744. BOOL RECONNECT_INFO_WINDOW::OnUserMessage(const EVENT &event)
  745. {
  746. switch (event.QueryMessage())
  747. {
  748. case SHOW_CONNECTION:
  749. SetText ((TCHAR *) event.QueryWParam());
  750. break;
  751. case DO_PASSWORD_DIALOG:
  752. {
  753. PARAMETERS *Params = (PARAMETERS *) event.QueryWParam();
  754. Params->status = MPRUI_DoPasswordDialog (QueryHwnd(),
  755. Params->pchResource,
  756. Params->pchUserName,
  757. Params->passwordBuffer,
  758. sizeof (Params->passwordBuffer),
  759. &(Params->fDidCancel),
  760. Params->dwError);
  761. SetEvent (Params->hDonePassword);
  762. }
  763. break;
  764. case DO_ERROR_DIALOG:
  765. {
  766. APIERR err = NERR_Success;
  767. ERRORDLGPARAMETERS *ErrParams = (ERRORDLGPARAMETERS *) event.QueryWParam();
  768. err = ShowErrorDialog(QueryHwnd(),
  769. ErrParams->pchDevice,
  770. ErrParams->pchResource,
  771. ErrParams->pchProvider,
  772. ErrParams->dwError,
  773. TRUE,
  774. &(ErrParams->fDisconnect),
  775. &(ErrParams->fContinue),
  776. &(ErrParams->fHideErrors),
  777. ErrParams->dwExtError,
  778. ErrParams->pchErrorText,
  779. ErrParams->pchErrorProvider);
  780. ErrParams->dwError = err;
  781. SetEvent (ErrParams->hDoneErrorDlg);
  782. }
  783. break;
  784. default:
  785. break;
  786. }
  787. return (TRUE);
  788. }
  789. /*******************************************************************
  790. NAME: MPRUI_ShowReconnectDialog
  791. SYNOPSIS: Displays a dialog to show the connection it's trying to
  792. restore.
  793. ENTRY: PARAMETERS Params
  794. EXIT: FALSE if dialog could not be processed
  795. NOTES:
  796. HISTORY:
  797. congpay 14-Oct-1992 Created.
  798. ********************************************************************/
  799. DWORD
  800. MPRUI_ShowReconnectDialog(
  801. HWND hwndParent,
  802. PARAMETERS *Params
  803. )
  804. {
  805. BOOL fCancel = FALSE; // record the cancel button in the Info window.
  806. RECONNECT_INFO_WINDOW *ppdlg = new
  807. RECONNECT_INFO_WINDOW (hwndParent,
  808. MAKEINTRESOURCE(IDD_RECONNECT_DLG),
  809. IDD_TEXT,
  810. &fCancel);
  811. APIERR err = (ppdlg == NULL)?
  812. ERROR_NOT_ENOUGH_MEMORY : ppdlg -> QueryError();
  813. if (err == NERR_Success)
  814. {
  815. Params->hDlg = ppdlg -> QueryHwnd();
  816. SetEvent (Params->hDlgCreated);
  817. err = ppdlg->Process();
  818. if (err == NERR_Success && fCancel == TRUE)
  819. {
  820. Params->status = WN_CANCEL;
  821. }
  822. }
  823. else
  824. {
  825. SetEvent (Params->hDlgFailed);
  826. }
  827. delete ppdlg;
  828. if (err != NERR_Success)
  829. {
  830. MsgPopup (hwndParent, (MSGID) err);
  831. }
  832. return (err);
  833. }
  834. /*******************************************************************
  835. NAME: MPRUI_DoProfileErrorDialog
  836. SYNOPSIS: Displays a dialog to get the password for a resource
  837. ENTRY: hwndOwner - owner window
  838. pchDevice - name of device which could not be reconnected
  839. pchResource - name of resource which could not be reconnected
  840. pchProvider - name of provider which registered an error
  841. dwError - error number (could be WN_EXTENDED_ERROR)
  842. fAllowCancel - Should user be allowed to stop reconnecting?
  843. pfDidCancel - TRUE if user cancelled, FALSE if user pressed OK
  844. pfDisconnect - TRUE if user asked to stop reconnecting this
  845. device on logon
  846. pfHideErrors - TRUE if user asked to stop displaying reconnect
  847. errors for this logon
  848. EXIT: FALSE if dialog could not be processed
  849. NOTES:
  850. HISTORY:
  851. jonn 08-Apr-1992 Templated from mprconn.cxx
  852. CongpaY 25-Oct-1992 Modified. More work on Internationalization.
  853. ********************************************************************/
  854. DWORD
  855. MPRUI_DoProfileErrorDialog(
  856. HWND hwndParent,
  857. const TCHAR * pchDevice,
  858. const TCHAR * pchResource,
  859. const TCHAR * pchProvider,
  860. DWORD dwError,
  861. BOOL fAllowCancel,
  862. BOOL * pfDidCancel,
  863. BOOL * pfDisconnect,
  864. BOOL * pfHideErrors
  865. )
  866. {
  867. ASSERT( pchResource != NULL );
  868. ASSERT( pchProvider != NULL );
  869. ASSERT( !fAllowCancel || pfDidCancel != NULL );
  870. ASSERT( !fAllowCancel || pfHideErrors != NULL );
  871. APIERR err = NERR_Success;
  872. TCHAR chNull = TCH('\0');
  873. if (pchDevice == NULL)
  874. pchDevice = &chNull;
  875. if (pchResource == NULL)
  876. pchResource = &chNull;
  877. if (pchProvider == NULL)
  878. pchProvider = &chNull;
  879. // if dwError is extended error. we have to pass the actual error to
  880. // the second thread.
  881. DWORD dwActualError;
  882. BUFFER bufErrorText (256*sizeof(TCHAR));
  883. BUFFER bufProvider (256*sizeof(TCHAR));
  884. if (dwError == WN_EXTENDED_ERROR)
  885. {
  886. if (((err = bufErrorText.QueryError()) == NERR_Success) &&
  887. ((err = bufProvider.QueryError()) == NERR_Success))
  888. {
  889. err = ::WNetGetLastError (&dwActualError,
  890. (LPTSTR)bufErrorText.QueryPtr(),
  891. 256,
  892. (LPTSTR)bufProvider.QueryPtr(),
  893. 256);
  894. }
  895. if (err != NERR_Success)
  896. {
  897. SetLastError (err);
  898. return (err);
  899. }
  900. }
  901. if (fAllowCancel) // Runs in the second thread. Called by DoRestoreConnection.
  902. {
  903. ERRORDLGPARAMETERS ErrParams;
  904. if ((ErrParams.hDoneErrorDlg = CreateEvent (NULL, FALSE, FALSE, NULL)) == NULL)
  905. {
  906. err = GetLastError();
  907. SetLastError (err);
  908. return (err);
  909. }
  910. ErrParams.pchDevice = pchDevice;
  911. ErrParams.pchResource = pchResource;
  912. ErrParams.pchProvider = pchProvider;
  913. ErrParams.dwError = dwError;
  914. if (dwError == WN_EXTENDED_ERROR)
  915. {
  916. ErrParams.dwExtError = dwActualError;
  917. ErrParams.pchErrorText = (const TCHAR *) bufErrorText.QueryPtr();
  918. ErrParams.pchErrorProvider = (const TCHAR *) bufProvider.QueryPtr();
  919. }
  920. else
  921. {
  922. ErrParams.dwExtError = 0;
  923. ErrParams.pchErrorText = NULL;
  924. ErrParams.pchErrorProvider = NULL;
  925. }
  926. PostMessage (hwndParent, DO_ERROR_DIALOG, (WPARAM) &ErrParams, 0);
  927. HANDLE lpHandle = ErrParams.hDoneErrorDlg;
  928. WaitForSingleObject (lpHandle, INFINITE);
  929. // set the value of pfDisconnect, and pfDidCancel.
  930. if (ErrParams.dwError == NO_ERROR) //ErrorDialog succeed.
  931. {
  932. *pfDisconnect = ErrParams.fDisconnect;
  933. *pfDidCancel = (ErrParams.fContinue == FALSE);
  934. *pfHideErrors = (ErrParams.fHideErrors != FALSE);
  935. }
  936. }
  937. else //Runs in the main thread.
  938. {
  939. if (dwError == WN_EXTENDED_ERROR)
  940. {
  941. err = ShowErrorDialog (hwndParent,
  942. pchDevice,
  943. pchResource,
  944. pchProvider,
  945. dwError,
  946. FALSE,
  947. pfDisconnect,
  948. NULL,
  949. pfHideErrors,
  950. dwActualError,
  951. (const TCHAR *)bufErrorText.QueryPtr(),
  952. (const TCHAR *)bufProvider.QueryPtr());
  953. }
  954. else
  955. {
  956. err = ShowErrorDialog (hwndParent,
  957. pchDevice,
  958. pchResource,
  959. pchProvider,
  960. dwError,
  961. FALSE,
  962. pfDisconnect,
  963. NULL,
  964. pfHideErrors,
  965. 0,
  966. NULL,
  967. NULL);
  968. }
  969. }
  970. return (err);
  971. }
  972. /*******************************************************************
  973. NAME: InvokeWinHelp
  974. SYNOPSIS: Helper function to invoke WinHelp.
  975. ENTRY: message - WM_CONTEXTMENU or WM_HELP
  976. wParam - depends on [message]
  977. wszHelpFileName - filename with or without path
  978. aulControlIdToHelpIdMap - see WinHelp API
  979. HISTORY: 25-Sep-1998 jschwart Created
  980. ********************************************************************/
  981. VOID
  982. InvokeWinHelp(
  983. UINT message,
  984. WPARAM wParam,
  985. LPARAM lParam,
  986. LPCWSTR wszHelpFileName,
  987. ULONG aulControlIdToHelpIdMap[]
  988. )
  989. {
  990. ASSERT(wszHelpFileName != NULL);
  991. ASSERT(aulControlIdToHelpIdMap != NULL);
  992. switch (message)
  993. {
  994. case WM_CONTEXTMENU: // "What's This" context menu
  995. WinHelp((HWND) wParam,
  996. wszHelpFileName,
  997. HELP_CONTEXTMENU,
  998. (DWORD_PTR) aulControlIdToHelpIdMap);
  999. break;
  1000. case WM_HELP: // Help from the "?" dialog
  1001. {
  1002. const LPHELPINFO pHelpInfo = (LPHELPINFO) lParam;
  1003. if (pHelpInfo && pHelpInfo->iContextType == HELPINFO_WINDOW)
  1004. {
  1005. WinHelp((HWND) pHelpInfo->hItemHandle,
  1006. wszHelpFileName,
  1007. HELP_WM_HELP,
  1008. (DWORD_PTR) aulControlIdToHelpIdMap);
  1009. }
  1010. break;
  1011. }
  1012. }
  1013. }