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.

266 lines
8.7 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. GETFOCUS.CXX
  7. Popup a dialog box and ask for the domain or server name
  8. FILE HISTORY:
  9. terryk 18-Nov-1991 Created
  10. terryk 26-Nov-1991 Code review changes. reviewed by jonn
  11. johnl
  12. Yi-HsinS31-Dec-1991 Unicode work - change strlen() to
  13. QueryTextSize()
  14. */
  15. #define INCL_WINDOWS_GDI
  16. #define INCL_WINDOWS
  17. #define INCL_DOSERRORS
  18. #define INCL_NETCONS
  19. #define INCL_NETERRORS
  20. #define INCL_NETLIB
  21. #define INCL_ICANON
  22. #define INCL_NETSERVER
  23. #include <lmui.hxx>
  24. #if defined(DEBUG)
  25. static const CHAR szFileName[] = __FILE__;
  26. #define _FILENAME_DEFINED_ONCE szFileName
  27. #endif
  28. #include <uiassert.hxx>
  29. #define INCL_BLT_DIALOG
  30. #define INCL_BLT_CONTROL
  31. #define INCL_BLT_MSGPOPUP
  32. #define INCL_BLT_CLIENT
  33. #define INCL_BLT_APP
  34. #define INCL_BLT_TIMER
  35. #include <blt.hxx>
  36. #include <string.hxx>
  37. #include <uitrace.hxx>
  38. #include <focusdlg.hxx>
  39. #include <wnetdev.hxx>
  40. extern "C"
  41. {
  42. #include <uiexport.h>
  43. #include <wnet16.h>
  44. #include <uigenhlp.h>
  45. }
  46. #define THIS_DLL_NAME SZ("ntlanman.dll")
  47. #define DEFAULT_NETWORK_HELP_FILE SZ("network.hlp")
  48. /*******************************************************************
  49. NAME: I_SystemFocusDialog
  50. SYNOPSIS: Popup a dialog box and get the domain or server name
  51. ENTRY: hwndOwner - owner window handle
  52. nSelectionType - Determines what items the user can select
  53. pszName - the string buffer which contains the
  54. return value. It can be either domain name or server
  55. name. ( server name will start with "\\" )
  56. cchBuffSize - the max buf size of pszName
  57. pfOK - TRUE if user hits OK button. FALSE if user
  58. hits a CANCEL button.
  59. EXIT: LPWSTR pszName - if user hits okay button, it will
  60. return either a domain name or a server name. (
  61. server name always starts with "\\" ). It will be
  62. undefined if the user hits Cancel button.
  63. BOOL *pfOK - TRUE if user hits ok button. FALSE
  64. otherwise.
  65. RETURNS: UINT - (APIERR) - NERR_Success if the operation is succeed.
  66. NERR_BufTooSmall, the string buffer is too
  67. small. It will not set the string if the
  68. buffer is too small.
  69. NOTES: The reason the return type is UINT and not APIERR is because
  70. APIERR is not a public definition, and this API is exported
  71. for public use.
  72. HISTORY:
  73. terryk 18-Nov-1991 Created
  74. terryk 19-Nov-1991 Name changed
  75. JohnL 22-Apr-1992 Allowed inclusion specification
  76. ********************************************************************/
  77. UINT I_SystemFocusDialog( HWND hwndOwner,
  78. UINT nSelectionType,
  79. LPWSTR pszName,
  80. UINT cchBuffSize,
  81. BOOL * pfOK,
  82. LPWSTR pszHelpFile,
  83. DWORD nHelpContext )
  84. {
  85. static BOOL fLoadedCurrentDll = FALSE;
  86. APIERR err ;
  87. if ( err = InitShellUI() )
  88. {
  89. return err ;
  90. }
  91. //
  92. // Because select computer dialog has a second thread,
  93. // we need to do a loadlibrary again to prevent
  94. // the dll from unloading itself while the second thread
  95. // is still active.
  96. //
  97. // JonN 01/28/00 PREFIX bug 444915
  98. // Because STANDALONE_SET_FOCUS_DLG is liable to launch a second thread
  99. // which will survive DIALOG::Process(), we increment the library
  100. // refcount. We can't decrement it because we don't know when
  101. // this thread will complete, so the library remains loaded
  102. // for the life of the process.
  103. //
  104. // This is not an ideal solution. The thread should take care of
  105. // its own refcounting needs. However, this is downlevel code
  106. // used only by the oldest clients, and I don't feel comfortable
  107. // making this kind of change which could cause unpredictable problems.
  108. // I think the wisest course is to leave this alone, and continue to
  109. // migrate clients towards Object Picker.
  110. if ( !fLoadedCurrentDll )
  111. {
  112. HANDLE handle = ::LoadLibraryEx( THIS_DLL_NAME,
  113. NULL,
  114. LOAD_WITH_ALTERED_SEARCH_PATH );
  115. if ( handle == NULL )
  116. return ::GetLastError();
  117. fLoadedCurrentDll = TRUE;
  118. }
  119. UINT nSel = nSelectionType & 0x0000FFFF;
  120. ULONG maskDomainSources = nSelectionType >> 16;
  121. if ( maskDomainSources == 0 )
  122. maskDomainSources = BROWSE_LM2X_DOMAINS;
  123. enum SELECTION_TYPE seltype ;
  124. switch ( nSel )
  125. {
  126. case FOCUSDLG_DOMAINS_ONLY:
  127. seltype = SEL_DOM_ONLY ;
  128. break ;
  129. case FOCUSDLG_SERVERS_ONLY:
  130. seltype = SEL_SRV_ONLY ;
  131. break ;
  132. case FOCUSDLG_SERVERS_AND_DOMAINS:
  133. seltype = SEL_SRV_AND_DOM ;
  134. break ;
  135. default:
  136. return ERROR_INVALID_PARAMETER ;
  137. }
  138. // Create a standalone set focus dialog box and get the input
  139. // form the user
  140. NLS_STR nlsName;
  141. STANDALONE_SET_FOCUS_DLG ssfdlg( hwndOwner,
  142. &nlsName,
  143. nHelpContext,
  144. seltype,
  145. maskDomainSources,
  146. NULL,
  147. pszHelpFile );
  148. err = ssfdlg.Process( pfOK );
  149. if ( err != NERR_Success )
  150. {
  151. ::MsgPopup( hwndOwner, err );
  152. *pfOK = FALSE;
  153. return err;
  154. }
  155. if ( *pfOK == TRUE )
  156. {
  157. if (( nlsName.QueryTextLength() + 1 ) > cchBuffSize )
  158. {
  159. *pfOK = FALSE;
  160. return NERR_BufTooSmall;
  161. }
  162. ::strcpyf( pszName, nlsName.QueryPch() );
  163. }
  164. return NERR_Success;
  165. } // GetSystemFocusDialog END
  166. /*******************************************************************
  167. NAME: ServerBrowseDialogA0
  168. SYNOPSIS: dialog box to browse for servers
  169. ENTRY: hwndOwner - owner window handle
  170. pszName - the string buffer which contains the
  171. return value. It can be either domain name or server
  172. name. ( server name will start with "\\" )
  173. cchBuffSize - the max buf size of pszName
  174. EXIT: LPWSTR pszName - if user hits okay button, it will
  175. return either a domain name or a server name. (
  176. server name always starts with "\\" ). It will be
  177. undefined if the user hits Cancel button.
  178. RETURNS: UINT - (APIERR) - NERR_Success if the operation is succeed.
  179. WN_CANCEL - The user cancelled the dialog box.
  180. NERR_BufTooSmall, the string buffer is too
  181. small. It will not set the string if the
  182. buffer is too small.
  183. NOTES:
  184. HISTORY:
  185. ChuckC 28-Mar-1993 Created
  186. AnirudhS 03-Oct-1995 Handle WN_CANCEL case
  187. ********************************************************************/
  188. DWORD ServerBrowseDialogA0(HWND hwnd,
  189. CHAR *pchBuffer,
  190. DWORD cchBufSize)
  191. {
  192. NLS_STR nlsServer ;
  193. TCHAR szServer[MAX_PATH] ;
  194. BOOL fOK ;
  195. UINT err ;
  196. ::memsetf(pchBuffer,0,cchBufSize) ;
  197. if (err = (UINT) nlsServer.QueryError())
  198. return err ;
  199. err = I_SystemFocusDialog ( hwnd,
  200. FOCUSDLG_SERVERS_ONLY,
  201. szServer,
  202. MAX_PATH,
  203. &fOK,
  204. DEFAULT_NETWORK_HELP_FILE,
  205. HC_GENHELP_BROWSESERVERS ) ;
  206. if (err == NERR_Success && !fOK)
  207. {
  208. err = WN_CANCEL;
  209. }
  210. if (err != NERR_Success)
  211. return err ;
  212. err = (UINT) nlsServer.CopyFrom(szServer) ;
  213. if (err == NERR_Success)
  214. {
  215. err = (UINT) nlsServer.MapCopyTo(pchBuffer, cchBufSize) ;
  216. }
  217. return err ;
  218. }