📄 explorefolders.cpp
字号:
folder = previousPath.c_str();
break;
}
if (token != "") {
previousPath += TEXT("\\");
previousPath += token;
}
}
// set ppc header
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
HFONT hFont = (HFONT) GetStockObject(SYSTEM_FONT);
GetObject(hFont, sizeof lf, &lf);
lf.lfWeight = FW_BOLD;
lf.lfHeight +=FONT_HEIGHT_OFFSET;
VERIFY(fontBold.CreateFontIndirect(&lf));
if(isNotes){
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_EXPLORE_TITLE_NOTES);
}
else{
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_EXPLORE_TITLE_BRIEFCASE);
}
SetDlgItemText(IDC_HEADER_STATIC, s1);
GetDlgItem(IDC_HEADER_STATIC)->SetFont(&fontBold);
SendMessage(WM_SETFOCUS, (WPARAM)hwndTV, NULL);// not necessary
#endif
// fix for wrong title problem, we get & set the title for the main window
wchar_t title[256];
AfxGetMainWnd()->GetWindowText(title,256);
AfxGetMainWnd()->SetWindowText(title);
return FALSE;
}
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CExploreFolders::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
// TODO: not needed
/*DRA::RelayoutDialog(
AfxGetInstanceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA::Portrait ?
MAKEINTRESOURCE(IDD_EXPLORE_DIALOG_WIDE) :
MAKEINTRESOURCE(IDD_EXPLORE_DIALOG));
*/
}
#endif
#if defined(WIN32_PLATFORM_PSPC)
void CExploreFolders::OnTvnItemExpanded(NMHDR * pNotifyStruct, LRESULT * result ){
LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW) pNotifyStruct;
if (pnmtv->action == TVE_COLLAPSE)
{
// remove the child items from this directory
hti = TreeView_GetChild(pNotifyStruct->hwndFrom, pnmtv->itemNew.hItem);
while (hti){
htiNext = TreeView_GetNextSibling(pNotifyStruct->hwndFrom, hti);
TreeView_DeleteItem(pNotifyStruct->hwndFrom, hti);
hti = htiNext;
}
}
*result = 0;
}
void CExploreFolders::OnTvnItemExpanding(NMHDR * pNotifyStruct, LRESULT * result ){
LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW) pNotifyStruct;
if (pnmtv->action == TVE_COLLAPSE){
// Retrieve the image from the current item
pnmtv->itemNew.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
TreeView_GetItem(pNotifyStruct->hwndFrom, &(pnmtv->itemNew));
// Set the item's image to the closed folder
pnmtv->itemNew.iImage = IMAGE_CLOSED;
pnmtv->itemNew.iSelectedImage = IMAGE_CLOSED;
TreeView_SetItem(pNotifyStruct->hwndFrom, &(pnmtv->itemNew));
}
else
{
// Retrieve the image from the current item
pnmtv->itemNew.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
TreeView_GetItem(pNotifyStruct->hwndFrom, &(pnmtv->itemNew));
// Set the item's image to the closed folder
pnmtv->itemNew.iImage = IMAGE_OPEN;
pnmtv->itemNew.iSelectedImage = IMAGE_OPEN;
TreeView_SetItem(pNotifyStruct->hwndFrom, &(pnmtv->itemNew));
// We need to fill in the subdirectory just expanded
BuildDirectory(pnmtv->hdr.hwndFrom, pnmtv->itemNew, szDir);
GetDirectoryContents(pnmtv->hdr.hwndFrom, szDir,(HTREEITEM)pnmtv->itemNew.hItem);
}
*result = 0;
}
void CExploreFolders::OnTvnDblClk(NMHDR * pNotifyStruct, LRESULT * result ){
DWORD dwPos;
TV_HITTESTINFO tvhti;
POINT point;
HWND hwndTV; GetDlgItem(IDC_TREEVIEW, &hwndTV);
TV_ITEM tvi;
TCHAR szbufW[MAX_PATH];
TCHAR sztempW[MAX_PATH];
szbufW[0] = '\0';
sztempW[0] = '\0';
// Find out where the cursor was
dwPos = GetMessagePos();
point.x = LOWORD(dwPos);
point.y = HIWORD(dwPos);
::ScreenToClient(hwndTV, &point);
tvhti.pt = point;
tvi.hItem = TreeView_HitTest(hwndTV, &tvhti);
tvi.pszText = szbufW;
tvi.cchTextMax = MAX_PATH;
tvi.mask = TVIF_IMAGE | TVIF_HANDLE | TVIF_TEXT;
TreeView_GetItem(hwndTV, &tvi);
HTREEITEM htv;
htv = tvi.hItem;
_tcsrev(szbufW);
_tcscat(szbufW, _T("\\"));
while (htv = TreeView_GetParent(hwndTV, htv)){
//Construct path
tvi.hItem = htv;
tvi.pszText = sztempW;
tvi.cchTextMax = MAX_PATH;
tvi.mask = TVIF_TEXT;
TreeView_GetItem(hwndTV, &tvi);
_tcsrev(sztempW);
if (_tcscmp(sztempW, _T("\\")) != 0) _tcscat(szbufW, sztempW);
if (szbufW[lstrlen(szbufW)-1] != '\\') _tcscat(szbufW, _T("\\"));
};
_tcsrev(szbufW);
*result =0;
folder = szbufW;
if(folder == _T("\\\\"))
folder = _T("\\");
EndDialog(IDCHOOSE); // the user has chosen
}
void CExploreFolders::OnTvnSelChanged(NMHDR * pNotifyStruct, LRESULT * result ){
LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW) pNotifyStruct;
BuildDirectory(pnmtv->hdr.hwndFrom, pnmtv->itemNew, szDir);
folder = szDir;
folder.Replace(_T("\\*.*"),_T(""));
if(folder == _T("")){
folder = _T("\\");
}
TreeView_SelectDropTarget(pnmtv->hdr.hwndFrom, pnmtv->itemNew.hItem);
}
HBRUSH CExploreFolders::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) {
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// set ppc header text color
if(pWnd->GetDlgCtrlID() == IDC_HEADER_STATIC) {
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(PPC_HEADER_TEXT_COLOR);
}
return hbr;
}
#endif
/// end PPC
void CExploreFolders::OnOK()
{
#if defined(WIN32_PLATFORM_WFSP)
BrowseFolder();
#endif
#if defined(WIN32_PLATFORM_PSPC)
EndDialog(IDCHOOSE); // the user has chosen
#endif
}
#if defined(WIN32_PLATFORM_WFSP)
void CExploreFolders::OnChoose(){
CString s1,s2;
BuildDirectory(path, s1);
lstFiles.GetText(lstFiles.GetCurSel(), s2);
if(wcscmp(s2,_T("..")) != 0){
s1+=s2;
}
if(wcscmp(s1,_T("\\\\")) == 0){
s1="\\";
}
folder = s1;
EndDialog(IDCHOOSE); // the user has chosen
}
void CExploreFolders::BrowseFolder()
{
CString s1,s2;
lstFiles.GetText(lstFiles.GetCurSel(), s1);
lstFiles.ResetContent();
if(s1 == ".."){
if(!isRoot){
path.pop_back();
}
if(path.size()==0){
isRoot = true;
s2=_T("My device");
lstFiles.ResetContent();
lstFiles.AddString(_T("\\"));
SetDlgItemText(IDC_EXPLORE_FOLDER, s2);
lstFiles.SetCurSel(0);
goto finally;
}
else{
isRoot = false;
}
}
else{
if(s1 != "\\"){
s1 += "\\";
path.push_back(s1);
isRoot=false;
};
}
if(!isRoot){
BuildDirectory(path,s1);
SetDlgItemText(IDC_EXPLORE_FOLDER, s1);
s1+="*";
GetDirectoryContents(&lstFiles, s1.GetBuffer(s1.GetLength()));
}
else{
if(path.size()==0){
path.push_back(_T("\\"));
}
s2=_T("\\");
SetDlgItemText(IDC_EXPLORE_FOLDER, s2);
s1=_T("\\*");
GetDirectoryContents(&lstFiles, s1.GetBuffer(s1.GetLength()));
isRoot = false;
}
finally:
lstFiles.SetFocus(); lstFiles.SetCurSel(0);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -