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.

369 lines
9.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. dlg.cxx
  7. It contains the WNetConnectionDialog source.
  8. FILE HISTORY:
  9. kevinl 31-Dec-91 Created
  10. terryk 03-Jan-92 capitalize the manifest
  11. Johnl 10-Jan-1992 Cleaned up
  12. BruceFo 23-May-1995 Add WNetConnectionDialog1 support
  13. */
  14. #define INCL_NETCONS
  15. #define INCL_NETCONFIG
  16. #define INCL_NETSERVICE
  17. #define INCL_NETLIB
  18. #define INCL_WINDOWS
  19. #define INCL_NETERRORS
  20. #define INCL_DOSERRORS
  21. #include <lmui.hxx>
  22. #define INCL_BLT_CONTROL
  23. #define INCL_BLT_CLIENT
  24. #define INCL_BLT_MSGPOPUP
  25. #include <blt.hxx>
  26. #include <dbgstr.hxx>
  27. #include <mprconn.h>
  28. #include <mprmisc.hxx>
  29. #include <mprbrows.hxx>
  30. #include <shellapi.h>
  31. #include <shlapip.h>
  32. extern "C"
  33. {
  34. #include <uigenhlp.h>
  35. }
  36. #include <wfext.h>
  37. #include <fmx.hxx>
  38. #define THIS_DLL_NAME SZ("mprui.dll")
  39. APIERR
  40. InitBrowsing(
  41. VOID
  42. );
  43. /*******************************************************************
  44. NAME: InitBrowsing
  45. SYNOPSIS: Internal API for initializing browsing
  46. ENTRY:
  47. EXIT:
  48. RETURNS:
  49. NOTES: The MprBrowseDialog and MprConnectionDialog has
  50. a second worker thread. In order to prevent
  51. the dll from unloading itself while the worker
  52. thread is still active, we need to do a loadlibrary
  53. on the current dll.
  54. HISTORY:
  55. YiHsins 21-Mar-1993 Created
  56. ********************************************************************/
  57. APIERR InitBrowsing( VOID )
  58. {
  59. static BOOL fLoadedCurrentDll = FALSE;
  60. if ( !fLoadedCurrentDll )
  61. {
  62. HANDLE handle = ::LoadLibraryEx( THIS_DLL_NAME,
  63. NULL,
  64. LOAD_WITH_ALTERED_SEARCH_PATH );
  65. if ( handle == NULL )
  66. return ::GetLastError();
  67. fLoadedCurrentDll = TRUE;
  68. }
  69. return NERR_Success;
  70. }
  71. /*******************************************************************
  72. NAME: MPRUI_WNetDisconnectDialog
  73. SYNOPSIS: Private API for the file manager disconnect dialog
  74. ENTRY: hwnd - Parent window handle suitable for hosting a dialog
  75. dwType - one of RESOURCETYPE_DISK or RESOURCETYPE_PRINT
  76. lpHelpFile - helpfile to use on Help Button
  77. nHelpContext - to pass to WinHelp on Help button
  78. EXIT:
  79. RETURNS:
  80. NOTES:
  81. HISTORY:
  82. Johnl 22-Jan-1992 Commented, fixed
  83. beng 31-Mar-1992 Unicode mumble
  84. ********************************************************************/
  85. DWORD
  86. MPRUI_WNetDisconnectDialog(
  87. HWND hwnd,
  88. DWORD dwType
  89. )
  90. {
  91. AUTO_CURSOR cursHourGlass ;
  92. DEVICE_TYPE devType ;
  93. switch ( dwType )
  94. {
  95. case RESOURCETYPE_DISK:
  96. devType = DEV_TYPE_DISK ;
  97. break ;
  98. // Allow Disk only
  99. case RESOURCETYPE_PRINT:
  100. default:
  101. return WN_BAD_VALUE ;
  102. }
  103. //
  104. // Call into netplwiz for the real dialog
  105. //
  106. return SHDisconnectNetDrives(hwnd);
  107. }
  108. /*******************************************************************
  109. NAME: WNetBrowsePrinterDialog
  110. SYNOPSIS:
  111. ENTRY: hwnd - Parent window handle suitable for hosting a dialog
  112. lpszName - place to store the name chosen
  113. nNameLength - number of characters in the buffer lpszName
  114. lpszHelpFile - helpfile to use on Help Button
  115. nHelpContext - to pass to WinHelp on Help button
  116. pfuncValidation - callback function to validate the name chosen
  117. by the user
  118. EXIT:
  119. RETURNS:
  120. NOTES:
  121. HISTORY:
  122. Yi-HsinS 12-Nov-1992 Created
  123. ********************************************************************/
  124. DWORD WNetBrowsePrinterDialog( HWND hwnd,
  125. WCHAR *lpszName,
  126. DWORD nNameLength,
  127. WCHAR *lpszHelpFile,
  128. DWORD nHelpContext,
  129. PFUNC_VALIDATION_CALLBACK pfuncValidation )
  130. {
  131. return WNetBrowseDialog( hwnd,
  132. RESOURCETYPE_PRINT,
  133. lpszName,
  134. nNameLength,
  135. lpszHelpFile,
  136. nHelpContext,
  137. pfuncValidation );
  138. }
  139. /*******************************************************************
  140. NAME: WNetBrowseDialog
  141. SYNOPSIS:
  142. ENTRY: hwnd - Parent window handle suitable for hosting a dialog
  143. dwType - one of RESOURCETYPE_DISK or RESOURCETYPE_PRINT
  144. lpszName - place to store the name chosen
  145. nNameLength - number of characters in the buffer lpszName
  146. lpszHelpFile - helpfile to use on Help Button
  147. nHelpContext - to pass to WinHelp on Help button
  148. pfuncValidation - callback function to validate the name chosen
  149. by the user
  150. EXIT:
  151. RETURNS:
  152. NOTES:
  153. HISTORY:
  154. Yi-HsinS 12-Nov-1992 Created
  155. ********************************************************************/
  156. DWORD WNetBrowseDialog( HWND hwnd,
  157. DWORD dwType,
  158. WCHAR *lpszName,
  159. DWORD nNameLength,
  160. WCHAR *lpszHelpFile,
  161. DWORD nHelpContext,
  162. PFUNC_VALIDATION_CALLBACK pfuncValidation )
  163. {
  164. if ( lpszName == NULL || lpszHelpFile == NULL || nNameLength <= 0 )
  165. return WN_BAD_VALUE;
  166. *lpszName = 0;
  167. *(lpszName + (nNameLength - 1)) = 0;
  168. AUTO_CURSOR cursHourGlass ;
  169. DEVICE_TYPE devType ;
  170. switch ( dwType )
  171. {
  172. case RESOURCETYPE_DISK:
  173. devType = DEV_TYPE_DISK;
  174. break ;
  175. case RESOURCETYPE_PRINT:
  176. devType = DEV_TYPE_PRINT;
  177. break;
  178. default:
  179. return WN_BAD_VALUE ;
  180. }
  181. NLS_STR nlsName;
  182. APIERR err = nlsName.QueryError();
  183. if ( err != NERR_Success )
  184. return err;
  185. err = InitBrowsing();
  186. if ( err != NERR_Success )
  187. return err;
  188. MPR_BROWSE_DIALOG * pbrowsedlg = new MPR_BROWSE_DIALOG( hwnd,
  189. devType,
  190. lpszHelpFile,
  191. nHelpContext,
  192. &nlsName,
  193. pfuncValidation ) ;
  194. BOOL fOK ;
  195. err = (pbrowsedlg==NULL) ? WN_OUT_OF_MEMORY : pbrowsedlg->Process( &fOK ) ;
  196. if ( err )
  197. {
  198. DBGEOL( "WNetBrowseDialog - Error code "
  199. << (ULONG) err << " returned from process." ) ;
  200. switch ( err )
  201. {
  202. case WN_EXTENDED_ERROR:
  203. MsgExtendedError( hwnd ) ;
  204. break ;
  205. default:
  206. MsgPopup( hwnd, (MSGID) err ) ;
  207. break ;
  208. }
  209. }
  210. delete pbrowsedlg;
  211. if ( nlsName.QueryTextLength() + 1 > nNameLength )
  212. err = ERROR_INSUFFICIENT_BUFFER;
  213. else
  214. ::strcpyf( lpszName, nlsName );
  215. return err ? err : ( !fOK ? 0xffffffff : WN_SUCCESS );
  216. }
  217. #define DEFAULT_NETWORK_HELP_FILE SZ("network.hlp")
  218. BOOL DummyIsValidFunction (LPWSTR psz) ;
  219. /*******************************************************************
  220. NAME: BrowseDialogA0
  221. SYNOPSIS: a special browse dialog for WFW to thunk to
  222. ENTRY:
  223. EXIT:
  224. RETURNS:
  225. NOTES:
  226. HISTORY:
  227. chuckc 26-Mar-1993 created
  228. ********************************************************************/
  229. DWORD BrowseDialogA0( HWND hwnd,
  230. DWORD nType,
  231. CHAR *pszName,
  232. DWORD cchBufSize)
  233. {
  234. APIERR err ;
  235. NLS_STR nlsPath ;
  236. TCHAR szPath[MAX_PATH] ;
  237. ::memsetf(pszName,0,cchBufSize) ;
  238. if ( (err = nlsPath.QueryError()) != NERR_Success)
  239. return err ;
  240. err = WNetBrowseDialog( hwnd,
  241. nType,
  242. szPath,
  243. MAX_PATH,
  244. DEFAULT_NETWORK_HELP_FILE,
  245. HC_GENHELP_BROWSE,
  246. DummyIsValidFunction ) ;
  247. if (err)
  248. return err ;
  249. //
  250. // make use of NLS_STR's handy U to A conversion rotines
  251. //
  252. err = nlsPath.CopyFrom(szPath) ;
  253. if (!err)
  254. err = nlsPath.MapCopyTo(pszName,cchBufSize) ;
  255. return err ;
  256. }
  257. /*******************************************************************
  258. NAME: DummyIsValidFunction
  259. SYNOPSIS: no validation for WFW, always return TRUE
  260. ENTRY:
  261. EXIT:
  262. RETURNS:
  263. NOTES:
  264. HISTORY:
  265. chuckc 26-Mar-1993 created
  266. ********************************************************************/
  267. BOOL DummyIsValidFunction (LPWSTR psz)
  268. {
  269. UNREFERENCED(psz) ;
  270. return TRUE ;
  271. }