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.

950 lines
22 KiB

  1. // Commenting #define out - causing compiler error - not sure if needed, compiles
  2. // okay without it.
  3. //#define WINVER 0x0400
  4. #include "precomp.h"
  5. #include "afxtempl.h"
  6. #include "resource.h"
  7. #include "wbemidl.h"
  8. #include <comdef.h>
  9. //smart pointer
  10. _COM_SMARTPTR_TYPEDEF(IWbemServices, IID_IWbemServices);
  11. _COM_SMARTPTR_TYPEDEF(IEnumWbemClassObject, IID_IEnumWbemClassObject);
  12. //_COM_SMARTPTR_TYPEDEF(IWbemContext, IID_IWbemContext );
  13. _COM_SMARTPTR_TYPEDEF(IWbemLocator, IID_IWbemLocator);
  14. #include "drdbdr.h"
  15. #include "winnetwk.h"
  16. #define NET_API_STATUS DWORD
  17. #define NET_API_FUNCTION __stdcall
  18. #include "lmwksta.h"
  19. #include "Browse.h"
  20. #include "dlgcback.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. CNetResourceList :: CNetResourceList(NETRESOURCE & nr, BOOL fNULL)
  27. {
  28. //Initialize
  29. fUseGlobe = FALSE;
  30. fIsNULL = fNULL;
  31. pNext = NULL;
  32. lpLocalName = NULL;
  33. lpRemoteName = NULL;
  34. lpComment = NULL;
  35. lpProvider = NULL;
  36. //If it is not NULL
  37. if (!fIsNULL)
  38. {
  39. dwScope = nr.dwScope;
  40. dwType = nr.dwType;
  41. dwDisplayType = nr.dwDisplayType;
  42. dwUsage = nr.dwUsage;
  43. if (nr.lpLocalName)
  44. {
  45. lpLocalName = new char [strlen(nr.lpLocalName) + 1];
  46. lpLocalName[0] = 0;
  47. strcpy(lpLocalName, nr.lpLocalName);
  48. }
  49. if (nr.lpRemoteName)
  50. {
  51. lpRemoteName = new char [strlen(nr.lpRemoteName) + 1];
  52. lpRemoteName[0] = 0;
  53. strcpy(lpRemoteName, nr.lpRemoteName);
  54. }
  55. if (nr.lpComment)
  56. {
  57. lpComment = new char [strlen(nr.lpComment) + 1];
  58. lpComment[0] = 0;
  59. strcpy(lpComment, nr.lpComment);
  60. }
  61. if (nr.lpProvider)
  62. {
  63. lpProvider = new char [strlen(nr.lpProvider) + 1];
  64. lpProvider[0] = 0;
  65. strcpy(lpProvider, nr.lpProvider);
  66. }
  67. }
  68. }
  69. CNetResourceList :: ~CNetResourceList()
  70. {
  71. //Tidy Up
  72. // if (pNext)
  73. // delete pNext;
  74. if (!fIsNULL)
  75. {
  76. delete lpLocalName;
  77. delete lpRemoteName;
  78. delete lpComment;
  79. delete lpProvider;
  80. }
  81. }
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CBrowseDialog dialog
  84. CBrowseDialog::CBrowseDialog(CWnd* pParent /*=NULL*/)
  85. : CDialog(CBrowseDialog::IDD, pParent)
  86. {
  87. //{{AFX_DATA_INIT(CBrowseDialog)
  88. //}}AFX_DATA_INIT
  89. }
  90. CBrowseDialog :: ~CBrowseDialog()
  91. {
  92. //Tidy Up
  93. // delete pPrevList;
  94. // delete pCurrentSelectionList;
  95. if (pPrevList)
  96. {
  97. CNetResourceList* theNext = NULL;
  98. do
  99. {
  100. theNext = pPrevList->pNext;
  101. delete pPrevList;
  102. pPrevList = theNext;
  103. } while (pPrevList);
  104. }
  105. if (pCurrentSelectionList)
  106. {
  107. CNetResourceList* theNext = NULL;
  108. do
  109. {
  110. theNext = pCurrentSelectionList->pNext;
  111. delete pCurrentSelectionList;
  112. pCurrentSelectionList = theNext;
  113. } while (pCurrentSelectionList);
  114. }
  115. }
  116. void CBrowseDialog::DoDataExchange(CDataExchange* pDX)
  117. {
  118. CDialog::DoDataExchange(pDX);
  119. //{{AFX_DATA_MAP(CBrowseDialog)
  120. //}}AFX_DATA_MAP
  121. }
  122. BEGIN_MESSAGE_MAP(CBrowseDialog, CDialog)
  123. //{{AFX_MSG_MAP(CBrowseDialog)
  124. ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
  125. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemchangedList3)
  126. ON_NOTIFY(LVN_KEYDOWN, IDC_LIST1, OnKeyDown)
  127. ON_BN_CLICKED(IDC_BACKBUTTON, OnBackbutton)
  128. ON_BN_CLICKED(IDC_LISTBUTTON, OnListbutton)
  129. ON_BN_CLICKED(IDC_DETAILBUTTON, OnDetailbutton)
  130. ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnNeedText)
  131. ON_WM_NCDESTROY()
  132. //}}AFX_MSG_MAP
  133. END_MESSAGE_MAP()
  134. /////////////////////////////////////////////////////////////////////////////
  135. // CBrowseDialog message handlers
  136. //This is used to mimick the stucture in NETAPI32.LIB
  137. typedef struct _WkstaInfo100
  138. {
  139. DWORD wki100_platform_id;
  140. LPSTR wki100_computername;
  141. LPSTR wki100_langroup;
  142. DWORD wki100_ver_major;
  143. DWORD wki100_ver_minor;
  144. } WkstaInfo100, *PWkstaInfo100, *LPWkstaInfo100;
  145. typedef NET_API_STATUS (CALLBACK *ULPRET)(LPSTR servername,
  146. DWORD level,
  147. LPBYTE* bufptr);
  148. BOOL CBrowseDialog::OnInitDialog()
  149. {
  150. CDialog::OnInitDialog();
  151. // subclass the window to circumvent a bug (?) in mfc
  152. WNDPROC oldWindowProc = (WNDPROC):: SetWindowLong (m_hWnd, GWL_WNDPROC, (DWORD) MySubClassProc);
  153. CWindowInfo *pwindowInfo = new CWindowInfo (m_hWnd, oldWindowProc);
  154. windowMap.SetAt ((SHORT)((DWORD)m_hWnd & 0xffff), pwindowInfo);
  155. // hook up controls
  156. m_cancelButton.Attach (::GetDlgItem (m_hWnd, IDCANCEL));
  157. m_okButton.Attach (::GetDlgItem (m_hWnd, IDOK));
  158. m_list.Attach(::GetDlgItem (m_hWnd, IDC_LIST1));
  159. // TODO: Add extra initialization here
  160. pPrevList = NULL;
  161. pCurrentSelectionList = NULL;
  162. pCurrentItem = NULL;
  163. lpServerName[0] = 0;
  164. iSelectedItem = 0;
  165. //Setup image list with icons
  166. m_imageList.Create (16, 16, TRUE, 25, 0);
  167. //The first icon (HMM_ICON_SERVER) is used to represent SERVERS
  168. hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON1));
  169. m_imageList.Add (hIcon);
  170. //The second icon (HMM_ICON_GLOBE) is used to represent the entire network
  171. hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON2));
  172. m_imageList.Add (hIcon);
  173. //The third icon (HMM_ICON_OTHER) is used to represent any other network resource
  174. hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON3));
  175. m_imageList.Add (hIcon);
  176. //The forth icon (HMM_ICON_NETWORK) is used to represent a link to the entire network
  177. hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON4));
  178. m_imageList.Add (hIcon);
  179. //Setup Bitmap pushbuttons
  180. m_backBitmapButton.AutoLoad(IDC_BACKBUTTON, this);
  181. m_listBitmapButton.AutoLoad(IDC_LISTBUTTON, this);
  182. m_listBitmapButton.EnableWindow(FALSE);
  183. m_detailBitmapButton.AutoLoad(IDC_DETAILBUTTON, this);
  184. //Enable tool tips for this dialog
  185. EnableToolTips(TRUE);
  186. //Setup column for report view
  187. LV_COLUMN lvCol;
  188. lvCol.mask = LVCF_FMT | LVCF_WIDTH;
  189. lvCol.fmt = LVCFMT_LEFT;
  190. lvCol.cx = MAX_SERVER_NAME_LENGTH;
  191. m_list.InsertColumn(1, &lvCol);
  192. m_list.SetImageList (&m_imageList, LVSIL_SMALL);
  193. oldStyle = :: GetWindowLong(m_list.m_hWnd, GWL_STYLE);
  194. :: SetWindowLong (m_list.m_hWnd,
  195. GWL_STYLE, oldStyle | LVS_LIST | LVS_SINGLESEL);
  196. char buff [500 + 1];
  197. buff[0] = 0;
  198. //check if this is a Windows 95 machine
  199. //This is a Windows 95 machine
  200. //by getting the info from the registry
  201. fIsWin95 = TRUE;
  202. HKEY keyHandle = (HKEY)1;
  203. long fStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  204. "System\\CurrentControlSet\\Services\\VxD\\VNETSUP", 0, KEY_READ, &keyHandle);
  205. if (fStatus == ERROR_SUCCESS)
  206. {
  207. DWORD sizebuff = 500;
  208. DWORD typeValue;
  209. fStatus = RegQueryValueEx(keyHandle, "Workgroup", NULL,
  210. &typeValue, (LPBYTE)buff, &sizebuff);
  211. }
  212. if ( (fStatus != ERROR_SUCCESS) )
  213. {
  214. fIsWin95 = FALSE;
  215. buff[0] = 0;
  216. //Check if you can call NetWkstaGetInfo in the NETAPI32.DLL
  217. ULPRET pProcAddr = NULL;
  218. HINSTANCE hNetApi = LoadLibrary("NETAPI32.DLL");
  219. if (hNetApi)
  220. {
  221. pProcAddr = (ULPRET) GetProcAddress(hNetApi, "NetWkstaGetInfo");
  222. }
  223. if (hNetApi && pProcAddr)
  224. {
  225. //Use NetAPI32
  226. LPBYTE buffer;
  227. ((*pProcAddr)(NULL, 100, &buffer));
  228. LPWkstaInfo100 lpFred = (LPWkstaInfo100) buffer;
  229. wsprintf (buff, "%ws", lpFred->wki100_langroup);
  230. }
  231. //Tidy up
  232. if (hNetApi)
  233. FreeLibrary(hNetApi);
  234. }
  235. buff[500] = 0;
  236. NETRESOURCE nr;
  237. nr.dwScope = RESOURCE_GLOBALNET;
  238. nr.dwType = RESOURCETYPE_ANY;
  239. nr.dwDisplayType = RESOURCEDISPLAYTYPE_DOMAIN;
  240. nr.dwUsage = RESOURCEUSAGE_CONTAINER;
  241. nr.lpLocalName = NULL;
  242. nr.lpRemoteName = buff;
  243. nr.lpComment = "";
  244. //New stuff to get provider name
  245. DWORD buffSize = 500;
  246. char provName [500];
  247. DWORD dwResult = WNetGetProviderName(WNNC_NET_MSNET, provName, &buffSize);
  248. if (dwResult != WN_SUCCESS)
  249. {
  250. dwResult = WNetGetProviderName(WNNC_NET_LANMAN, provName, &buffSize);
  251. }
  252. if (dwResult != WN_SUCCESS)
  253. {
  254. ODBCTRACE ("\nWBEM ODBC Driver : Failed to get provider name\n");
  255. }
  256. else
  257. {
  258. ODBCTRACE ("\nWBEM ODBC Driver : Provider name = ");
  259. ODBCTRACE (provName);
  260. ODBCTRACE ("\n");
  261. }
  262. nr.lpProvider = provName;
  263. //Add first entry in callback list (i.e. previous list)
  264. pPrevList = new CNetResourceList(nr, FALSE);
  265. pPrevList->fUseGlobe = TRUE;
  266. count = 0;
  267. EnumerateServers(&nr, pPrevList->fUseGlobe);
  268. //Give Cancel pushbutton focus
  269. m_cancelButton.SetFocus();
  270. return TRUE; // return TRUE unless you set the focus to a control
  271. // EXCEPTION: OCX Property Pages should return FALSE
  272. }
  273. void CBrowseDialog :: EnumerateServers(LPNETRESOURCE lpnr, BOOL fUseGlobe)
  274. {
  275. //Disable controls before enumeration
  276. BeginWaitCursor();
  277. m_okButton.EnableWindow(FALSE);
  278. m_backBitmapButton.EnableWindow(FALSE);
  279. HANDLE hEnum = NULL;
  280. DWORD dwResult = 0;
  281. //check if this is Windows 95 asking for the Entire Network
  282. NETRESOURCE nr95;
  283. if (fIsWin95 && !lpnr)
  284. {
  285. nr95.dwScope = RESOURCE_GLOBALNET;
  286. nr95.dwType = RESOURCETYPE_ANY;
  287. nr95.dwDisplayType = RESOURCEDISPLAYTYPE_NETWORK;
  288. nr95.dwUsage = RESOURCEUSAGE_CONTAINER;
  289. nr95.lpLocalName = NULL;
  290. nr95.lpRemoteName = NULL;
  291. nr95.lpComment = HMM_STR_MN;
  292. nr95.lpProvider = HMM_STR_MN;
  293. dwResult = WNetOpenEnum(RESOURCE_GLOBALNET,
  294. RESOURCETYPE_ANY, 0, &nr95, &hEnum);
  295. }
  296. else
  297. {
  298. dwResult = WNetOpenEnum(RESOURCE_GLOBALNET,
  299. RESOURCETYPE_ANY, 0, lpnr, &hEnum);
  300. }
  301. //Only disable cancel button after enumeration returned
  302. m_cancelButton.EnableWindow(FALSE);
  303. BOOL fUseBackArrow = FALSE; //can we go back to previous screen ?
  304. if ( dwResult != NO_ERROR )
  305. {
  306. EndWaitCursor();
  307. m_cancelButton.EnableWindow(TRUE);
  308. m_backBitmapButton.EnableWindow(!fUseGlobe);
  309. return;
  310. }
  311. DWORD dwResultEnum = 0;
  312. DWORD cbBuffer = 16384; //16k is a reasonable size
  313. DWORD cEntries = 0xFFFFFFFF; //get all entries
  314. LPNETRESOURCE lpnrLocal = NULL;
  315. //Check if you need to add a back arrow or globe
  316. if ( fUseGlobe )
  317. {
  318. //Add Globe
  319. LV_ITEM tempItem1;
  320. tempItem1.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  321. tempItem1.iItem = count++;
  322. tempItem1.iSubItem = 0;
  323. tempItem1.pszText = HMM_STR_ENTIRE_NWORK;
  324. tempItem1.state = 0;
  325. tempItem1.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  326. tempItem1.iImage = HMM_ICON_GLOBE;
  327. tempItem1.lParam = (DWORD) NULL;
  328. m_list.InsertItem(&tempItem1);
  329. //Disable the back arrow
  330. fUseBackArrow = FALSE;
  331. }
  332. else
  333. {
  334. //Add Back Arrow
  335. //Enable the back arrow
  336. fUseBackArrow = TRUE;
  337. if (lpnr)
  338. {
  339. //Add to head of current selection list for speedy clean up
  340. pCurrentSelectionList = new CNetResourceList(*lpnr, FALSE);
  341. pCurrentItem = pCurrentSelectionList;
  342. }
  343. }
  344. do
  345. {
  346. //Allocate memory for NETRESOURCE structures
  347. //to retrieve from enumeration
  348. lpnrLocal = (LPNETRESOURCE) GlobalAlloc (GPTR, cbBuffer);
  349. if (lpnrLocal)
  350. {
  351. dwResultEnum = WNetEnumResource (hEnum, &cEntries,
  352. lpnrLocal, &cbBuffer);
  353. if ( (dwResultEnum == NO_ERROR))
  354. {
  355. for (DWORD i = 0; i < cEntries; i++)
  356. {
  357. //Display NETRESOURCE structure
  358. NETRESOURCE fred = lpnrLocal[i];
  359. if (fred.lpRemoteName)
  360. {
  361. //Insert into List View Control
  362. LV_ITEM tempItem;
  363. tempItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  364. tempItem.iItem = count++;
  365. tempItem.iSubItem = 0;
  366. tempItem.pszText = fred.lpRemoteName;
  367. tempItem.state = 0;
  368. tempItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  369. //Work out which icon to use
  370. if (lpnrLocal[i].dwDisplayType == RESOURCEDISPLAYTYPE_SERVER)
  371. tempItem.iImage = HMM_ICON_SERVER;
  372. else if (lpnrLocal[i].dwDisplayType == RESOURCEDISPLAYTYPE_NETWORK)
  373. tempItem.iImage = HMM_ICON_NETWORK;
  374. else if (lpnrLocal[i].dwDisplayType == RESOURCEDISPLAYTYPE_GENERIC)
  375. tempItem.iImage = HMM_ICON_NETWORK;
  376. else
  377. tempItem.iImage = HMM_ICON_OTHER;
  378. //Add to end of current selection list for speedy clean up
  379. CNetResourceList* pt = new CNetResourceList(fred, FALSE);
  380. if (pCurrentSelectionList)
  381. {
  382. pCurrentItem->pNext = pt;
  383. pCurrentItem = pt;
  384. }
  385. else
  386. {
  387. pCurrentSelectionList = pt;
  388. pCurrentItem = pt;
  389. }
  390. tempItem.lParam = (DWORD) pt;
  391. m_list.InsertItem(&tempItem);
  392. }
  393. }
  394. }
  395. //Tidy up
  396. GlobalFree( (HGLOBAL) lpnrLocal);
  397. }
  398. else
  399. break;
  400. } while (dwResultEnum != ERROR_NO_MORE_ITEMS);
  401. WNetCloseEnum(hEnum);
  402. //Re-enable pushbuttons
  403. m_backBitmapButton.EnableWindow(fUseBackArrow);
  404. m_cancelButton.EnableWindow(TRUE);
  405. EndWaitCursor();
  406. // if (m_list.GetSelectedCount())
  407. // m_okButton.EnableWindow(TRUE);
  408. }
  409. void CBrowseDialog::OnDblclkList2(int index)
  410. {
  411. if ((index != -1))
  412. {
  413. LV_ITEM tempItem;
  414. tempItem.mask = LVIF_IMAGE | LVIF_PARAM;
  415. tempItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  416. tempItem.iSubItem = 0;
  417. tempItem.iItem = index;
  418. if ( m_list.GetItem(&tempItem) )
  419. {
  420. //Check if you clicked on globe or arrow
  421. if (tempItem.iImage == HMM_ICON_GLOBE)
  422. {
  423. //Remove current items in list view control
  424. CleanUpListCtrl();
  425. m_list.DeleteAllItems();
  426. //Get Microsoft Network Info
  427. count = 0;
  428. //Add to start of previous list
  429. CNetResourceList* pt = pPrevList;
  430. pPrevList = new CNetResourceList(dummy, TRUE);
  431. if (pt)
  432. pPrevList->pNext = pt;
  433. EnumerateServers(NULL, pPrevList->fUseGlobe);
  434. //Give Cancel pushbutton focus
  435. m_cancelButton.SetFocus();
  436. }
  437. else
  438. {
  439. CNetResourceList* pNR = (CNetResourceList*)tempItem.lParam;
  440. if (pNR && pNR->dwDisplayType != RESOURCEDISPLAYTYPE_SERVER)
  441. {
  442. //Setup information for new enumeration
  443. NETRESOURCE nr2;
  444. nr2.lpLocalName = NULL;
  445. nr2.lpRemoteName = NULL;
  446. nr2.lpComment = NULL;
  447. nr2.lpProvider = NULL;
  448. BOOL fNULL = pNR->fIsNULL;
  449. if (!fNULL)
  450. {
  451. Clone(nr2, pNR->dwScope, pNR->dwType, pNR->dwDisplayType, pNR->dwUsage,
  452. pNR->lpLocalName, pNR->lpRemoteName, pNR->lpComment, pNR->lpProvider);
  453. }
  454. //Add item to front of list
  455. CNetResourceList* pt = pPrevList;
  456. pPrevList = new CNetResourceList(nr2, fNULL);
  457. if (pt)
  458. pPrevList->pNext = pt;
  459. //Remove current items in list view control
  460. CleanUpListCtrl();
  461. m_list.DeleteAllItems();
  462. count = 0;
  463. if (fNULL)
  464. EnumerateServers(NULL, pPrevList->fUseGlobe);
  465. else
  466. EnumerateServers(&nr2, pPrevList->fUseGlobe);
  467. //Give Cancel pushbutton focus
  468. m_cancelButton.SetFocus();
  469. //Tidy up
  470. delete nr2.lpLocalName;
  471. delete nr2.lpRemoteName;
  472. delete nr2.lpComment;
  473. delete nr2.lpProvider;
  474. }
  475. else
  476. {
  477. m_okButton.EnableWindow(TRUE);
  478. }
  479. }
  480. }
  481. }
  482. }
  483. void CBrowseDialog::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
  484. {
  485. // TODO: Add your control notification handler code here
  486. *pResult = 0;
  487. //Get current position of mouse cursor and perform
  488. //a hit test on the tree control
  489. POINT cursorPos;
  490. cursorPos.x = 0;
  491. cursorPos.y = 0;
  492. BOOL state = GetCursorPos(&cursorPos);
  493. m_list.ScreenToClient(&cursorPos);
  494. UINT fFlags = 0;
  495. int index = m_list.HitTest(cursorPos, &fFlags);
  496. if (fFlags & LVHT_ONITEM)
  497. {
  498. OnDblclkList2(index);
  499. }
  500. }
  501. void CBrowseDialog :: CleanUpListCtrl()
  502. {
  503. //Disable back button (if applicable)
  504. m_backBitmapButton.EnableWindow(FALSE);
  505. if (pCurrentSelectionList)
  506. {
  507. CNetResourceList* theNext = NULL;
  508. do
  509. {
  510. theNext = pCurrentSelectionList->pNext;
  511. delete pCurrentSelectionList;
  512. pCurrentSelectionList = theNext;
  513. } while (pCurrentSelectionList);
  514. }
  515. pCurrentSelectionList = NULL;
  516. pCurrentItem = NULL;
  517. }
  518. void CBrowseDialog::OnBackbutton()
  519. {
  520. // TODO: Add your control notification handler code here
  521. //Remove current items in list view control
  522. CleanUpListCtrl();
  523. m_list.DeleteAllItems();
  524. //Remove item from front of list
  525. CNetResourceList* pt = pPrevList->pNext;
  526. pPrevList->pNext = NULL;
  527. delete pPrevList;
  528. pPrevList = pt;
  529. //Go back and get previous enumeration
  530. NETRESOURCE temp;
  531. temp.lpLocalName = NULL;
  532. temp.lpRemoteName = NULL;
  533. temp.lpComment = NULL;
  534. temp.lpProvider = NULL;
  535. BOOL fGlobe = pPrevList->fUseGlobe;
  536. BOOL fNULL = pPrevList->fIsNULL;
  537. if ( ! fNULL)
  538. {
  539. Clone(temp, pPrevList->dwScope, pPrevList->dwType, pPrevList->dwDisplayType, pPrevList->dwUsage,
  540. pPrevList->lpLocalName, pPrevList->lpRemoteName, pPrevList->lpComment, pPrevList->lpProvider);
  541. }
  542. count = 0;
  543. if (fNULL)
  544. EnumerateServers(NULL, fGlobe);
  545. else
  546. EnumerateServers(&temp, fGlobe);
  547. //Give Cancel pushbutton focus
  548. m_cancelButton.SetFocus();
  549. //Tidy Up
  550. delete temp.lpLocalName;
  551. delete temp.lpRemoteName;
  552. delete temp.lpComment;
  553. delete temp.lpProvider;
  554. }
  555. void CBrowseDialog::OnListbutton()
  556. {
  557. // TODO: Add your control notification handler code here
  558. m_listBitmapButton.EnableWindow(FALSE);
  559. m_detailBitmapButton.EnableWindow(TRUE);
  560. int cCount = m_list.GetItemCount();
  561. :: SetWindowLong (m_list.m_hWnd,
  562. GWL_STYLE, oldStyle | LVS_LIST | LVS_SINGLESEL);
  563. m_list.RedrawItems(0, cCount - 1);
  564. UpdateWindow();
  565. }
  566. void CBrowseDialog::OnDetailbutton()
  567. {
  568. // TODO: Add your control notification handler code here
  569. m_detailBitmapButton.EnableWindow(FALSE);
  570. m_listBitmapButton.EnableWindow(TRUE);
  571. int cCount = m_list.GetItemCount();
  572. :: SetWindowLong (m_list.m_hWnd,
  573. GWL_STYLE, oldStyle | LVS_NOCOLUMNHEADER | LVS_ICON | LVS_REPORT | LVS_SINGLESEL);
  574. m_list.RedrawItems(0, cCount - 1);
  575. UpdateWindow();
  576. }
  577. BOOL CBrowseDialog::OnNeedText(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
  578. {
  579. TOOLTIPTEXT* pTTT = (TOOLTIPTEXT*)pNMHDR;
  580. UINT nID = pNMHDR->idFrom;
  581. if (pTTT->uFlags & TTF_IDISHWND)
  582. {
  583. //idFrom is actually the HWND of the tool
  584. nID= :: GetDlgCtrlID((HWND)nID);
  585. switch (nID)
  586. {
  587. case IDC_BACKBUTTON:
  588. {
  589. pTTT->lpszText = MAKEINTRESOURCE(STR_PREVIOUS);
  590. pTTT->hinst = AfxGetResourceHandle();
  591. return (TRUE);
  592. }
  593. break;
  594. case IDC_LISTBUTTON:
  595. {
  596. pTTT->lpszText = MAKEINTRESOURCE(STR_LIST_VIEW);
  597. pTTT->hinst = AfxGetResourceHandle();
  598. return (TRUE);
  599. }
  600. break;
  601. case IDC_DETAILBUTTON:
  602. {
  603. pTTT->lpszText = MAKEINTRESOURCE(STR_REPORT_VIEW);
  604. pTTT->hinst = AfxGetResourceHandle();
  605. return (TRUE);
  606. }
  607. break;
  608. default:
  609. break;
  610. }
  611. }
  612. return (FALSE);
  613. }
  614. void CBrowseDialog :: OnNcDestroy ()
  615. {
  616. CWindowInfo *pwindowInfo = NULL;
  617. BOOL found = windowMap.Lookup ((SHORT) ((DWORD)m_hWnd & 0xffff), pwindowInfo);
  618. ASSERT (found);
  619. if (found)
  620. {
  621. :: SetWindowLong (m_hWnd, GWL_WNDPROC, (DWORD) pwindowInfo->m_oldWindowProc);
  622. windowMap.RemoveKey ((SHORT) ((DWORD)m_hWnd & 0xffff));
  623. delete pwindowInfo;
  624. }
  625. m_cancelButton.Detach ();
  626. m_okButton.Detach ();
  627. m_list.Detach ();
  628. CDialog :: OnNcDestroy ();
  629. }
  630. void CBrowseDialog::OnOK()
  631. {
  632. //Get name of selected item using selected item index
  633. LV_ITEM tempItem;
  634. tempItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  635. tempItem.iItem = iSelectedItem;
  636. tempItem.iSubItem = 0;
  637. tempItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  638. tempItem.pszText = lpServerName;
  639. tempItem.cchTextMax = MAX_SERVER_NAME_LENGTH;
  640. if ( m_list.GetItem(&tempItem) )
  641. {
  642. //Copy name of network resource
  643. // lpServerName[0] = 0;
  644. // if (tempItem.pszText)
  645. // {
  646. // strncpy(lpServerName, tempItem.pszText, MAX_SERVER_NAME_LENGTH);
  647. // lpServerName[MAX_SERVER_NAME_LENGTH] = 0;
  648. // }
  649. }
  650. CDialog::OnOK();
  651. }
  652. //Populates a NETRESOURCE structure with the input parameters
  653. void CBrowseDialog :: Clone(NETRESOURCE &nrClone, DWORD nrScope, DWORD nrType, DWORD nrDisplayType, DWORD nrUsage,
  654. LPSTR lpLocalName, LPSTR lpRemoteName, LPSTR lpComment, LPSTR lpProvider)
  655. {
  656. nrClone.lpLocalName = NULL;
  657. nrClone.lpRemoteName = NULL;
  658. nrClone.lpComment = NULL;
  659. nrClone.lpProvider = NULL;
  660. nrClone.dwScope = nrScope;
  661. nrClone.dwType = nrType;
  662. nrClone.dwDisplayType = nrDisplayType;
  663. nrClone.dwUsage = nrUsage;
  664. if (lpLocalName)
  665. {
  666. nrClone.lpLocalName = new char [strlen(lpLocalName) + 1];
  667. nrClone.lpLocalName[0] = 0;
  668. strcpy(nrClone.lpLocalName, lpLocalName);
  669. }
  670. if (lpRemoteName)
  671. {
  672. nrClone.lpRemoteName = new char [strlen(lpRemoteName) + 1];
  673. nrClone.lpRemoteName[0] = 0;
  674. strcpy(nrClone.lpRemoteName, lpRemoteName);
  675. }
  676. if (lpComment)
  677. {
  678. nrClone.lpComment = new char [strlen(lpComment) + 1];
  679. nrClone.lpComment[0] = 0;
  680. strcpy(nrClone.lpComment, lpComment);
  681. }
  682. if (lpProvider)
  683. {
  684. nrClone.lpProvider = new char [strlen(lpProvider) + 1];
  685. nrClone.lpProvider[0] = 0;
  686. strcpy(nrClone.lpProvider, lpProvider);
  687. }
  688. }
  689. // -1 if no selected index
  690. int CBrowseDialog::GetSelectedIndex(DWORD &dwDisplayType)
  691. {
  692. //Check if one item is selected
  693. int selecCount = m_list.GetSelectedCount();
  694. int itemCount = m_list.GetItemCount();
  695. if ( selecCount == 1 )
  696. {
  697. int mySelIndex = m_list.GetNextItem ( -1 , LVNI_ALL | LVNI_SELECTED ) ;
  698. if (mySelIndex != -1)
  699. {
  700. LV_ITEM myItem;
  701. myItem.mask = LVIF_STATE | LVIF_IMAGE | LVIF_PARAM;
  702. myItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  703. myItem.iItem = mySelIndex;
  704. myItem.iSubItem = 0;
  705. //Find index to this item
  706. if ( m_list.GetItem(&myItem) )
  707. {
  708. CNetResourceList* pNR = (CNetResourceList*)myItem.lParam;
  709. if (pNR)
  710. dwDisplayType = pNR->dwDisplayType;
  711. return mySelIndex; //break out now
  712. }
  713. }
  714. }
  715. //No selected item found
  716. return -1;
  717. }
  718. void CBrowseDialog::OnItemchangedList3(NMHDR* pNMHDR, LRESULT* pResult)
  719. {
  720. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  721. // TODO: Add your control notification handler code here
  722. *pResult = 0;
  723. ODBCTRACE ("\nCBrowseDialog::OnItemchangedList3\n");
  724. DWORD dwDisplayType = 0;
  725. int mySelectedIndex = GetSelectedIndex(dwDisplayType);
  726. if ( mySelectedIndex != -1 )
  727. {
  728. iSelectedItem = mySelectedIndex;
  729. //check if selected item is a server
  730. if (dwDisplayType == RESOURCEDISPLAYTYPE_SERVER)
  731. m_okButton.EnableWindow(TRUE);
  732. else
  733. m_okButton.EnableWindow(FALSE);
  734. }
  735. }
  736. void CBrowseDialog::OnKeyDown(NMHDR* pNMHDR, LRESULT* pResult)
  737. {
  738. ODBCTRACE ("\nCBrowseDialog::OnKeyDown\n");
  739. TV_KEYDOWN* lParam = (TV_KEYDOWN*)pNMHDR;
  740. // TODO: Add your control notification handler code here
  741. *pResult = 0;
  742. //Check if SPACE BAR is pressed (to expand node)
  743. if ( lParam->wVKey == VK_SPACE )
  744. {
  745. DWORD dwDisplayType = 0;
  746. int mySelectedIndex = GetSelectedIndex(dwDisplayType);
  747. OnDblclkList2(mySelectedIndex);
  748. }
  749. else if (lParam->wVKey == VK_BACK)
  750. {
  751. //BACKSPACE PRESSED (for Up One Level)
  752. if ( m_backBitmapButton.IsWindowEnabled() )
  753. {
  754. OnBackbutton();
  755. }
  756. }
  757. else if (lParam->wVKey == 'L')
  758. {
  759. //L PRESSED (for List View)
  760. OnListbutton();
  761. }
  762. else if (lParam->wVKey == 'D')
  763. {
  764. //D PRESSED (for Details View)
  765. OnDetailbutton();
  766. }
  767. }