📄 userpathdlg.cpp
字号:
///////////////////////////////////////////////////////////////
//UserPathDlg.cpp
//儐乕僓僷僗偺搊榐曇廤
///////////////////////////////////////////////////////////////
//INCLUDE
#include "GSFinder.h"
#include "UserPathDlg.h"
///////////////////////////////////////////////////////////////
//PROTOTYPE
LRESULT CALLBACK UserPathDlgProc(HWND,UINT,WPARAM,LPARAM);
///////////////////////////////////////////////////////////////
//僌儘乕僶儖曄悢
CUserPathDlg *pusrDlg;
///////////////////////////////////////////////////////////////
CUserPathDlg::CUserPathDlg(HWND hWnd, HINSTANCE hInst)
{
pusrDlg = this;
//僷儔儊乕僞偺曐懚
m_hparWnd = hWnd;
m_hInst = hInst;
//僐儞僩儘乕儖偺弶婜壔
InitCommonControls();
//儊儞僶曄悢偺弶婜壔
m_bEditing = FALSE;
}
///////////////////////////////////////////////////////////////
CUserPathDlg::~CUserPathDlg()
{
}
///////////////////////////////////////////////////////////////
void CUserPathDlg::Open()
{
#ifdef __POCKET_PC
//SIP僆乕僾儞
BOOL bSetSip = FALSE;
SIPINFO si;
memset(&si, 0, sizeof(SIPINFO));
si.cbSize = sizeof(SIPINFO);
SipGetInfo(&si);
if ((si.fdwFlags&SIPF_ON)!=SIPF_ON)
{
SipShowIM(SIPF_ON);
bSetSip = TRUE;
}
#endif
//僂傿儞僪僂嶌惉
DialogBox(m_hInst,
(LPCTSTR)IDD_USERPATH_DLG,
m_hparWnd,
(DLGPROC)UserPathDlgProc);
#ifdef __POCKET_PC
//SIP僋儘乕僘
if (bSetSip)
SipShowIM(SIPF_OFF);
#endif
return;
}
///////////////////////////////////////////////////////////////
void CUserPathDlg::OnInit()
{
#ifdef __POCKET_PC
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIZEDLGFULLSCREEN;
shidi.hDlg = m_hWnd;
SHInitDialog(&shidi);
#endif
//僂傿儞僪僂僞僀僩儖
SetWindowText(m_hWnd, IDS_TITLE_USERPATHDLG);
//僇儔儉僿僢僟偺嶌惉
RECT rc;
GetClientRect(m_hList, &rc);
LVCOLUMN lvclm;
lvclm.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
lvclm.fmt = LVCFMT_LEFT;
lvclm.cx = rc.right - rc.left;
lvclm.pszText = IDS_COLUMN_USERPATH;
lvclm.cchTextMax = 0;
lvclm.iSubItem = 0;
ListView_InsertColumn(m_hList, 0, &lvclm);
//慜夞搊榐偟偨僷僗傪捛壛偡傞
for(int i=0; i<g_MainWnd.m_ListView.m_nOpenPthInfoCount; i++)
{
//傾僀僥儉偺捛壛
LVITEM lvitem;
lvitem.mask = LVIF_TEXT;
lvitem.iItem = i;
lvitem.iSubItem = 0;
lvitem.pszText = g_MainWnd.m_ListView.m_lpOpenPthInfo[i]->lpszPath;
ListView_InsertItem(m_hList, &lvitem);
} //End of for
//儃僞儞偺弶婜愝掕
SetButton();
//僼僅乕僇僗傪儕僗僩傊愝掕
SetFocus(m_hList);
}
///////////////////////////////////////////////////////////////
void CUserPathDlg::SetButton()
{
//捛壛儃僞儞
if(g_MainWnd.m_ListView.m_nOpenPthInfoCount >= MAX_OPENAPP)
{
SetWindowLong(GetDlgItem(m_hWnd, IDADD), GWL_STYLE,
GetWindowLong(GetDlgItem(m_hWnd, IDADD), GWL_STYLE)|WS_DISABLED);
}
else
{
SetWindowLong(GetDlgItem(m_hWnd, IDADD), GWL_STYLE,
GetWindowLong(GetDlgItem(m_hWnd, IDADD), GWL_STYLE)&~WS_DISABLED);
}
//嶍彍儃僞儞
if(g_MainWnd.m_ListView.m_nOpenPthInfoCount <= 0)
{
SetWindowLong(GetDlgItem(m_hWnd, IDDELETE), GWL_STYLE,
GetWindowLong(GetDlgItem(m_hWnd, IDDELETE), GWL_STYLE)|WS_DISABLED);
SetWindowLong(GetDlgItem(m_hWnd, IDEDIT), GWL_STYLE,
GetWindowLong(GetDlgItem(m_hWnd, IDEDIT), GWL_STYLE)|WS_DISABLED);
}
else
{
SetWindowLong(GetDlgItem(m_hWnd, IDDELETE), GWL_STYLE,
GetWindowLong(GetDlgItem(m_hWnd, IDDELETE), GWL_STYLE)&~WS_DISABLED);
SetWindowLong(GetDlgItem(m_hWnd, IDEDIT), GWL_STYLE,
GetWindowLong(GetDlgItem(m_hWnd, IDEDIT), GWL_STYLE)&~WS_DISABLED);
}
//儃僞儞嵞昤夋
InvalidateRect(GetDlgItem(m_hWnd, IDADD), NULL, TRUE);
UpdateWindow(GetDlgItem(m_hWnd, IDADD));
InvalidateRect(GetDlgItem(m_hWnd, IDDELETE), NULL, TRUE);
UpdateWindow(GetDlgItem(m_hWnd, IDDELETE));
InvalidateRect(GetDlgItem(m_hWnd, IDEDIT), NULL, TRUE);
UpdateWindow(GetDlgItem(m_hWnd, IDEDIT));
}
///////////////////////////////////////////////////////////////
void CUserPathDlg::OnAdd()
{
TCHAR szPath[MAX_PATH];
wcscpy(szPath, g_MainWnd.m_ListView.m_szCurrentFolder);
if((!wcslen(szPath)) || (wcscmp(SEARCH_FOLDER_NAME, szPath)==0))
wcscpy(szPath, GetRootName());
//傾僀僥儉偺捛壛
LVITEM lvitem;
lvitem.mask = LVIF_TEXT;
lvitem.iItem = g_MainWnd.m_ListView.m_nOpenPthInfoCount;
lvitem.iSubItem = 0;
lvitem.pszText = szPath;
ListView_InsertItem(m_hList, &lvitem);
//僥乕僽儖傊僷僗傪捛壛
AddPath(lvitem.iItem, lvitem.pszText);
//傾僀僥儉傪曇廤忬懺偵偡傞
SetFocus(m_hList);
ListView_EditLabel(m_hList, lvitem.iItem);
//儃僞儞偺愝掕
SetButton();
}
///////////////////////////////////////////////////////////////
void CUserPathDlg::OnDelete()
{
//慖戰傾僀僥儉傪専嶕
int nItem = ListView_GetNextItem(m_hList, -1, LVNI_ALL | LVNI_SELECTED);
if(nItem == -1)
return;
//傾僀僥儉嶍彍
SetFocus(m_hList);
ListView_DeleteItem(m_hList, nItem);
//僥乕僽儖偺僷僗傪嶍彍
DelPath(nItem);
//儃僞儞偺愝掕
SetButton();
}
///////////////////////////////////////////////////////////////
void CUserPathDlg::OnEdit()
{
//慖戰傾僀僥儉傪専嶕
int nItem = ListView_GetNextItem(m_hList, -1, LVNI_ALL | LVNI_SELECTED);
if(nItem == -1)
return;
//傾僀僥儉傪曇廤忬懺偵偡傞
SetFocus(m_hList);
ListView_EditLabel(m_hList, nItem);
}
///////////////////////////////////////////////////////////////
BOOL CUserPathDlg::OnEndLabelEdit(LV_DISPINFO* pdi)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pdi;
int nIndex = pDispInfo->item.iItem;
if (!pDispInfo->item.pszText) return FALSE;
//僄儔乕僠僃僢僋
if (wcschr(pDispInfo->item.pszText, _T('/'))!=NULL || wcschr(pDispInfo->item.pszText, _T(':'))!=NULL || wcschr(pDispInfo->item.pszText, _T(','))!=NULL || wcschr(pDispInfo->item.pszText, _T(';'))!=NULL || wcschr(pDispInfo->item.pszText, _T('*'))!=NULL || wcschr(pDispInfo->item.pszText, _T('?'))!=NULL || wcschr(pDispInfo->item.pszText, _T('<'))!=NULL || wcschr(pDispInfo->item.pszText, _T('>'))!=NULL || wcschr(pDispInfo->item.pszText, _T('|'))!=NULL)
{
//僄儔乕偺応崌
MessageBox(g_MainWnd.m_hWnd, IDS_MSG_CANNOTUSECHAR, NULL, MB_OK|MB_ICONSTOP);
SetFocus(m_hList);
ListView_EditLabel(m_hList, nIndex);
return FALSE;
}
else
{
TCHAR szPath[MAX_PATH];
wcscpy(szPath, pDispInfo->item.pszText);
if(!wcslen(szPath))
wcscpy(szPath, GetRootName());
//懚嵼偡傞偐偺妋擣
DWORD dwAttr = GetFileAttributes(szPath);
if (dwAttr == 0xFFFFFFFF || !(dwAttr & FILE_ATTRIBUTE_DIRECTORY)) {
MessageBox(g_MainWnd.m_hWnd, IDS_MSG_NOTFOUND_PATH, NULL, MB_OK|MB_ICONSTOP);
SetFocus(m_hList);
ListView_EditLabel(m_hList, nIndex);
return FALSE;
}
//惓忢偺応崌
ListView_SetItemText(m_hList, pDispInfo->item.iItem, 0, szPath);
ModPath(pDispInfo->item.iItem, szPath);
}
return TRUE;
}
///////////////////////////////////////////////////////////////
BOOL CUserPathDlg::AddPath(int nIndex, LPTSTR lpszPath)
{
//僨乕僞偺嶌惉
OPENAPPINFO *pup = new OPENAPPINFO;
pup->lpszPath = new TCHAR[wcslen(lpszPath)+1];
wcscpy(pup->lpszPath, lpszPath);
g_MainWnd.m_ListView.m_lpOpenPthInfo[nIndex] = pup;
g_MainWnd.m_ListView.m_nOpenPthInfoCount++;
return TRUE;
}
///////////////////////////////////////////////////////////////
BOOL CUserPathDlg::ModPath(int nIndex, LPTSTR lpszPath)
{
//僨乕僞偺嶍彍
OPENAPPINFO* pup= g_MainWnd.m_ListView.m_lpOpenPthInfo[nIndex];
if (pup)
{
delete pup->lpszPath;
delete pup;
}
//僨乕僞偺嵞嶌惉
pup = new OPENAPPINFO;
pup->lpszPath = new TCHAR[wcslen(lpszPath)+1];
wcscpy(pup->lpszPath, lpszPath);
g_MainWnd.m_ListView.m_lpOpenPthInfo[nIndex] = pup;
return TRUE;
}
///////////////////////////////////////////////////////////////
BOOL CUserPathDlg::DelPath(int nIndex)
{
//僨乕僞偺嶍彍
OPENAPPINFO* pup= g_MainWnd.m_ListView.m_lpOpenPthInfo[nIndex];
if (pup)
{
delete pup->lpszPath;
delete pup;
g_MainWnd.m_ListView.m_lpOpenPthInfo[nIndex] = NULL;
}
//屻懕僨乕僞傪慜曽傊堏摦
for(int i=nIndex; i<g_MainWnd.m_ListView.m_nOpenPthInfoCount; i++)
{
g_MainWnd.m_ListView.m_lpOpenPthInfo[i] =
g_MainWnd.m_ListView.m_lpOpenPthInfo[i+1];
g_MainWnd.m_ListView.m_lpOpenPthInfo[i+1] = NULL;
} // End of for
g_MainWnd.m_ListView.m_nOpenPthInfoCount--;
return TRUE;
}
///////////////////////////////////////////////////////////////
LRESULT CALLBACK UserPathDlgProc(
HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
pusrDlg->m_hWnd = hDlg;
pusrDlg->m_hList = GetDlgItem(hDlg, IDC_LIST_PATH);
pusrDlg->OnInit();
break;
}
case WM_NOTIFY:
{
LPNMHDR pNMHDR = (LPNMHDR)lParam;
switch (pNMHDR->code)
{
//柤慜偺曄峏奐巒
case LVN_BEGINLABELEDIT:
{
pusrDlg->m_bEditing = TRUE;
break;
}
//柤慜偺曄峏廔椆
case LVN_ENDLABELEDIT:
{
LV_DISPINFO* pdi = (LV_DISPINFO*) lParam;
pusrDlg->m_bEditing = FALSE;
return pusrDlg->OnEndLabelEdit(pdi);
}
}
break;
}
case WM_COMMAND:
{
if(pusrDlg->m_bEditing) break;
int wmId = LOWORD(wParam);
int wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDADD:
{
pusrDlg->OnAdd();
break;
}
case IDDELETE:
{
pusrDlg->OnDelete();
break;
}
case IDEDIT:
{
pusrDlg->OnEdit();
break;
}
case IDOK:
case IDCANCEL:
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
}
break;
}
#ifdef __POCKET_PC
case WM_CTLCOLORSTATIC:
return DefDlgCtlColorStaticProc(hDlg, wParam, lParam);
#endif
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -