I have the code below. When I select an item, the item
does not really get selected until the next time I select
something (that could be something else). What is wrong?
BOOL CMyOwnBrowseDialog::OnInitDialog()
{
CDialog::OnInitDialog();
_chdrive(3);
if (chdir("C:\\") != 0)
MessageBox("FEL", "FEL", MB_OK |
MB_ICONERROR);
m_StaticDir.SetWindowText("C:");
currentDirName = "C:";
HTREEITEM rootC = m_TreeDirectories.InsertItem
("C:");
if (m_TreeDirectories.Select(rootC,
TVGN_DROPHILITE) == 0)
AfxMessageBox("Fel", MB_OK);
fillChild(rootC);
m_TreeDirectories.Expand(rootC, TVE_EXPAND);
m_TreeDirectories.SetFocus();
return FALSE; // return TRUE unless you set the
focus to a control
// EXCEPTION: OCX Property Pages
should return FALSE
}
void CMyOwnBrowseDialog::fillChild(HTREEITEM hParent)
{
if (m_TreeDirectories.ItemHasChildren(hParent))
return;
if (m_TreeDirectories.GetRootItem() != hParent)
{
if (chdir(m_TreeDirectories.GetItemText
(m_TreeDirectories.GetSelectedItem())) == -1)
AfxMessageBox("APA", MB_OK);
}
else
{
if (chdir("C:\\") == -1)
AfxMessageBox("APA2", MB_OK);
else
AfxMessageBox("KAHFADJKFHK",
MB_OK);
}
CFileFind fileFind;
BOOL bWorking = fileFind.FindFile("*.*");
while (bWorking)
{
bWorking = fileFind.FindNextFile();
if (fileFind.IsDirectory() &&
fileFind.GetFileName() != ".")
m_TreeDirectories.InsertItem
(fileFind.GetFileName(), hParent);
}
}
void CMyOwnBrowseDialog::OnClickTreeDirectories(NMHDR*
pNMHDR, LRESULT* pResult)
{
HTREEITEM treeItem =
m_TreeDirectories.GetSelectedItem();
CString prevDirName = currentDirName;
currentDirName = m_TreeDirectories.GetItemText
(treeItem);
fillChild(treeItem);AfxMessageBox(currentDirName,
MB_OK);
CString prevDir;
CString newDir = "";
m_StaticDir.GetWindowText(prevDir);
if (currentDirName == "..")
{
int lastDir = prevDir.ReverseFind('\\');
for (int i = 0; i < lastDir - 2; ++i)
newDir += prevDir.GetAt(i);
}
else if (currentDirName != prevDirName)
newDir = prevDir + "\\" + currentDirName;
else
newDir = prevDir;
m_TreeDirectories.Expand(treeItem, TVE_TOGGLE);
m_StaticDir.SetWindowText(newDir);
*pResult = 0;
}