/ CTreeViewDlg message handlers // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // º¯Êý¹|ÄÜ: ³õʼ »¯ // @@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@Bool ctreeviewdlg :: OnIndialog () {cdialog :: oninitdialog ();
// set the icon for this dialog. The framework does this automatic or //en the application's main window is not a dialog seticon (m_hicon, true); // set big icon seticon (m_hicon, false); // set small icon / / TODO: Add extra initialization here m_ImageList.Create (32,32, ILC_COLOR32,10,30); m_list.SetImageList (& m_ImageList, LVSIL_NORMAL); DWORD dwStyle = GetWindowLong (m_tree.m_hWnd, GWL_STYLE); dwStyle | = TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT; SetWindowLong (m_tree.m_hWnd, GWL_STYLE, dwStyle); m_hRoot = m_tree.InsertItem ( "ÎÒμÄμçÄÔ"); GetLogicalDrives (m_hRoot); GetDriveDir (m_hRoot); m_tree.Expand (m_hRoot, TVE_EXPAND); return TRUE; // return TRUE UnsS you set the focus to a control}
// If you add a minimize button to your dialog, you will need the code below // to draw the icon For MFC applications using the document / view model, // this is automatically done for you by the framework.void CTreeViewDlg.: : Onpaint () {if (isiconic ()) {cpaintdc DC (this); // device context for Painting
SendMessage (WM_ICONERASEBKGND, (WPARAM) dc.getsafehdc (), 0);
// Center icon in client rectangle int cxIcon = GetSystemMetrics (SM_CXICON); int cyIcon = GetSystemMetrics (SM_CYICON); CRect rect; GetClientRect (& rect); int x = (rect.Width () - cxIcon 1) / 2; int y = (Rect.height () - Cyicon 1) / 2;
// Draw the icon dc.drawicon (x, y, m_hicon);} else {cdialog :: onpaint ();}}
// the system calls this to obtain the cursor to display while the user dress // the minimized window.hcursor ctreeViewdlg :: ONQUERYDRAGICON () {Return (hcursor) m_hicon @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@ // o ¯ê¹ ¹|Äü: »ñè¡ Çý¶¯Æ ÷ // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@8 = new char [szAllDriveStrings sizeof (_T ( ""))]; GetLogicalDriveStrings (szAllDriveStrings, pDriveStrings); size_t szDriveString = strlen (pDriveStrings); while (szDriveString> 0) {m_tree.InsertItem (pDriveStrings, hParent); pDriveStrings = szDriveString 1; szDriveString = strlen (pDriveStrings);}} // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// º¯Êý¹|ÄÜ: Ìí¼Ó × ÓÏî // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@8
void CTreeViewDlg :: GetDriveDir (HTREEITEM hParent) {HTREEITEM hChild = m_tree.GetChildItem (hParent); while (hChild) {CString strText = m_tree.GetItemText (hChild); if (! strText.Right (1) = "//") Strtext = _T ("//"); strText = "*. *"; cfilefind file; bool bcontinue = file.FindFile (strText); while (bcontinue) {bcontinue = file.findnextFile (); if (file.) Isdirectory () &&! File.isdots ()) m_tree.insertitem (file.getfilename (), hchild);} getDrivedir (hchild = m_tree.getnextitem (hchild, tvgn_next);} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ¯¹|Äü: õ¹õ¹ ªÊ¼þº¯Êý // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@ void CTreeViewDlg :: OnItemexpandedTree (NMHDR * pNMHDR, LRESULT * pResult) {NM_TREEVIEW * pNMTreeView = (NM_TREEVIEW *) pNMHDR; // TODO: Add your control notification handler code here TVITEM item = pNMTreeView-> itemNew; if (item.hItem == m_hRoot) return; HTREEITEM hChild = m_tree.GetChildItem (item.hItem); while (hChild) {AddSubDir (hChild Hchild =
m_tree.GetNextItem (hChild, TVGN_NEXT);} * pResult = 0;} // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // º¯Êý¹|ÄÜ: »ñÈ¡ Ê ÷ ïîä¿ È «¸ú¾¶ // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@ CString CTreeViewDlg :: GetFullPath (HTREEITEM hCurrent) {CString strTemp; CString strReturn = ""; while (hCurrent! = m_hRoot) {strTemp = m_tree.GetItemText (hCurrent); if (strTemp.Right (1)! = "//") strTemp = "//"; strReturn = strTemp strReturn; hCurrent = m_tree.GetParentItem (hCurrent) ;} return strReturn;} // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@8 ¼ // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@
@@@@@@void ctreeviewdlg :: addsubdir (htreeItem hparent) {cstring strpath = getFullPath (hparent); if (strpath.right (1)! = "//" StrPath = "// "; Strpath =" *. * "; Cfilefind file; bool bcontinue = file.FindFile (strpath); while (bcontinue) {bcontinue = file.FindNextFile (); if (file.Indirectory () &&! File.isdots )) m_tree.InsertItem (file.GetFileName (), hParent);}} // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // º¯Êý¹|ÄÜ: Ñ¡ ÖÐʼþ // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ void CTreeViewDlg :: OnSelchangedTree (NMHDR * pNMHDR, LRESULT * pResult) {m_list.DeleteAllItems (); NM_TREEVIEW * pNMTreeView = (NM_TREEVIEW *) pNMHDR; TVitem item = pnmtreeview-> itemnew; if (item.hitem == m_hroot) return; cstract str = getFullPath (item.hitem); if (str.right (1)! = "//") STR = "// "; STR =" *. * "; Cfilefind file; bool bcontinue = file.findfile (str); while (bcontinue) {bcontinue = file.FindNextFile (); if (! File.Indirectory () &&! File.isdots ()) {SHFILEINFO INFO;
CString Temp = Str; INT INDEX = Temp.Find ("*. *"); Temp.delete (INDEX, 3); SHGETFILEINFO (Temp File.GetFileName (), 0, & info, sizeof (& info), SHGFI_DISPLAYNAME | SHGFI_ICON ); int i = m_ImageList.Add (info.hIcon); m_list.InsertItem (i, info.szDisplayName, i);}} * pResult = 0;} void CTreeViewDlg :: OnSelchangingTree (NMHDR * pNMHDR, LRESULT * pResult) {
* PRESULT = 0;}
Void ctreeviewdlg :: OnClickTree (nmHDR * pnmhdr, lresult * pRESULT) {// Todo: add your control notification handler code here
* PRESULT = 0;}