home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 December / PCWKCD1296.iso / vjplusb / activex / inetsdk / samples / wininet / asyncftp / comctl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-04  |  6.4 KB  |  236 lines

  1.  
  2. #include <windows.h>
  3. #include <wininet.h>
  4. #include <commctrl.h>
  5. #include "comctlhd.h"
  6. #include "clist.h"
  7. #include "resource.h"
  8.  
  9.  
  10. TVNODEINFO gTVNodeInfo;
  11. CCommonCtrl::CCommonCtrl(HINSTANCE hInst, HWND hwndParent)
  12. {
  13.     m_hInst = hInst;
  14.     m_hWndParent = hwndParent;
  15.     m_icount = 0;
  16.     for (int i = 0; i < 10; i++)
  17.         m_prootlvl[i]= NULL;
  18.     return;
  19. }
  20.  
  21. CCommonCtrl::~CCommonCtrl()
  22. {
  23.     node *pnode;
  24.     int i;
  25.  
  26.     for (i = 0; i < m_icount; i++)
  27.     {
  28.         if (NULL != m_prootlvl[i])
  29.         {
  30.             pnode = ((m_prootlvl[i])->getfirstnode());
  31.             //close cached handle
  32.             InternetCloseHandle(pnode->data.hConnect);
  33.             m_prootlvl[i]->remove();
  34.             delete m_prootlvl[i];
  35.         }
  36.     }
  37.     for (i = 0; i < 2; i++)
  38.         DeleteObject(m_hb[i]);
  39.     ImageList_Destroy(m_himg);
  40.  
  41.     return;
  42. }
  43.  
  44. //**********************************************************************
  45. // CCommonCtrl::ImageListInit
  46. //
  47. // Purpose: Initialize ImageList and its images
  48. // Parameters: None.
  49. // Return Value:  
  50. //    BOOL - TRUE if initialization succeeded, FALSE otherwise.
  51. //
  52. //********************************************************************
  53.  
  54. BOOL CCommonCtrl::ImageListInit()
  55. {
  56.  
  57.     m_himg = ImageList_Create(13,13, ILC_COLOR16, 3, 0);
  58.     if (NULL == m_himg)
  59.         return FALSE;
  60.     m_hb[0] = LoadBitmap(m_hInst, MAKEINTRESOURCE(IDB_LEAF)); 
  61.     ImageList_Add(m_himg, m_hb[0], NULL); 
  62.     m_hb[1] = LoadBitmap(m_hInst, MAKEINTRESOURCE(IDB_OPEN)); 
  63.     ImageList_Add(m_himg, m_hb[1], NULL); 
  64.     m_hb[2] = LoadBitmap(m_hInst, MAKEINTRESOURCE(IDB_CLOSED)); 
  65.     ImageList_Add(m_himg, m_hb[2], NULL); 
  66.  
  67.     return TRUE;
  68.  
  69. }
  70.  
  71.  
  72.  
  73. //**********************************************************************
  74. // CCommonCtrl::TreeViewAdd
  75. //
  76. // Purpose: Wrapper for calling TreeView_Add macro
  77. // Parameters: 
  78. //    LPTSTR  pszText -  TreeView item text
  79. //    LPTVDTA ptvdta  -  TreeView item (TV_ITEM) values 
  80. //    LPTVNODEINFO lptvnodei - Structure containing data associated
  81. //    with a TreeView item whose pointer is stored in TV_ITEM.lParam 
  82. //    LPDWORD dwContext - context value which represents a pointer 
  83. //    to a TVNODEINFO structure to be used in asynchronous calls 
  84. // Return Value:  
  85. //    HTREEITEM - handle to the TreeView item created
  86. //
  87. //********************************************************************
  88.  
  89. HTREEITEM CCommonCtrl::TreeViewAdd(TCHAR *pszText, LPTVDATA ptvdta, LPTVNODEINFO ptvnodei, LPDWORD pdwContext)
  90. {
  91.     HTREEITEM htvitem;
  92.     TV_INSERTSTRUCT tvins;
  93.     TV_ITEM tvi;
  94.     LPTVNODEINFO ptv;
  95.     int i, index = 0;
  96.     BOOL finditem = FALSE;
  97.  
  98.     //set TV_ITEM values
  99.     tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM;
  100.     tvi.pszText = pszText;
  101.     tvi.cchTextMax = lstrlen(pszText);
  102.     tvi.iImage = ptvdta->imgIndex;
  103.     tvi.iSelectedImage = ptvdta->imgIndexSelected;
  104.  
  105.     //root level node
  106.     if (!ptvnodei->dwAttributes)
  107.     {
  108.         //since root level nodes are just stored in an array and
  109.         //an element may have been deleted, check for an vacated element
  110.         for (i = 0; i < m_icount; i++)
  111.         {
  112.             if (NULL == m_prootlvl[i])
  113.             {
  114.                 //vacated element found
  115.                 index = i;
  116.                 break;
  117.             }
  118.         }
  119.         if (!index)
  120.         {
  121.             //all elements are full, create new entry for root level data
  122.             m_prootlvl[m_icount] = new Clist();
  123.             //tvi.lParam = (LPARAM)m_prootlvl[m_icount];
  124.             ptv = m_prootlvl[m_icount]->insertatend(ptvnodei);
  125.             finditem = TRUE;
  126.             //tvi.lParam = (LPARAM)ptv;
  127.             index = m_icount;
  128.             m_icount++;
  129.         }
  130.         else
  131.         {
  132.             //vacated element found
  133.             m_prootlvl[index] = new Clist();
  134.             //tvi.lParam = (LPARAM)m_prootlvl[index];
  135.             ptv = m_prootlvl[index]->insertatend(ptvnodei);
  136.             finditem = TRUE;
  137.             //tvi.lParam = (LPARAM)ptv;
  138.  
  139.         }
  140.  
  141.     }
  142.     else
  143.     {
  144.         for (i = 0; i < m_icount; i++)
  145.         {
  146.             if (NULL != m_prootlvl[i])
  147.             {
  148.                 if (!lstrcmp((m_prootlvl[i]->getfirstnode())->data.pszSite, ptvnodei->pszSite))
  149.                 {
  150.                     ptv = m_prootlvl[i]->insertatend(ptvnodei);
  151.                     finditem = TRUE;
  152.                     index = i;
  153.                     //tvi.lParam = (LPARAM)ptv;
  154.                     break;
  155.                 }
  156.             }
  157.         }
  158.     }
  159.     //we should ASSERT here on finditem
  160.     ASSERT(finditem);
  161.  
  162.     //set index value which provides a pointer from the TreeView item
  163.     //to its root level Ftp site node
  164.     ptv->index = index;
  165.  
  166.     //store the TVNODEINFO in the 32-bit lParam of the TV_ITEM
  167.     tvi.lParam = (LPARAM)ptv;
  168.  
  169.     //set dwContext value to be used in asynchrounous calls
  170.     *pdwContext = (DWORD)(tvi.lParam);
  171.  
  172.     //set the TV_INSERTSTRUCT values
  173.     tvins.hParent = ptvdta->hParent;
  174.     tvins.hInsertAfter = TVI_LAST;
  175.     tvins.item = tvi;
  176.  
  177.     //add new treeview item and make visible
  178.     htvitem = TreeView_InsertItem(m_hWndTV, &tvins);
  179.     TreeView_EnsureVisible(m_hWndTV, htvitem);
  180.  
  181.  
  182.     return htvitem;
  183. }
  184.  
  185. //**********************************************************************
  186. // CCommonCtrl::TreeViewAdd
  187. //
  188. // Purpose: Wrapper for calling TreeView_GetParent and TreeView_GetItem
  189. //          macros to get parent data
  190. // Parameters: 
  191. //    HTREEITEM ptvitem  -  handle to TreeView item to get parent for
  192. //    LPTV_ITEM ptviParent  -  OUT parameter of parent item (TV_ITEM) values 
  193. //    UINT mask - mask for specifying items of parent to get 
  194. //    LPTSTR curdir - buffer used to get TV_ITEM.pszText 
  195. // Return Value:  
  196. //    HTREEITEM - handle to the TreeView parent item
  197. //
  198. //********************************************************************
  199.  
  200. HTREEITEM CCommonCtrl::TreeViewParent(HTREEITEM ptvitem, LPTV_ITEM ptviParent, UINT mask, LPTSTR curdir)
  201. {
  202.     HTREEITEM hParent;
  203.     BOOL ret;
  204.     hParent = TreeView_GetParent(m_hWndTV, ptvitem);
  205.     ptviParent->hItem = hParent;
  206.     ptviParent->mask = mask;
  207.     ptviParent->pszText = curdir;
  208.     ptviParent->cchTextMax = MAX_PATH;
  209.     ret = TreeView_GetItem(m_hWndTV, ptviParent);
  210.     return hParent;
  211. }
  212.  
  213. //**********************************************************************
  214. // CCommonCtrl::TreeViewAdd
  215. //
  216. // Purpose: Wrapper for calling TreeView_GetItem macro
  217. // Parameters: 
  218. //    HTREEITEM phtvitem  -  handle to TreeView item 
  219. //    LPTV_ITEM ptvi  -  OUT parameter of item (TV_ITEM) values 
  220. //    UINT mask - mask for specifying items of parent to get 
  221. //    LPTSTR buf - buffer used to get TV_ITEM.pszText 
  222. // Return Value:  
  223. //    BOOL - TRUE if initialization succeeded, FALSE otherwise.
  224. //
  225. //********************************************************************
  226.  
  227. BOOL CCommonCtrl::TreeViewItem(HTREEITEM phtvitem, LPTV_ITEM ptvi, UINT mask, LPTSTR buf)
  228. {
  229.     BOOL ret;
  230.     ptvi->hItem = phtvitem;
  231.     ptvi->pszText = buf;
  232.     ptvi->cchTextMax = 80;
  233.     ptvi->mask = mask;
  234.     ret  = TreeView_GetItem(m_hWndTV, ptvi);
  235.     return ret;
  236. }