📄 proppagesharelocation.cpp
字号:
// DlgShare.cpp : implementation file//#include "stdafx.h"#include <Shlobj.h>#include "warmmcsnapin.h"#include "PropPageShareLocation.h"#include "WarUtf8.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CPropPageShareLocation dialogCPropPageShareLocation::CPropPageShareLocation() : CPropertyPage(CPropPageShareLocation::IDD){ //{{AFX_DATA_INIT(CPropPageShareLocation) m_MountMoint = _T("/pub/new"); m_Type = _T("file"); m_Path = _T(""); m_Host = _T(""); m_UserName = _T(""); m_Password = _T(""); //}}AFX_DATA_INIT}CPropPageShareLocation::~CPropPageShareLocation(){}void CPropPageShareLocation::DoDataExchange(CDataExchange* pDX){ CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPropPageShareLocation) DDX_Control(pDX, IDC_URL, m_ctlUrl); DDX_Text(pDX, IDC_MOUNT_POINT, m_MountMoint); DDX_CBString(pDX, IDC_TYPE, m_Type); DDX_Text(pDX, IDC_PATH, m_Path); DDX_Text(pDX, IDC_HOST, m_Host); DDX_Text(pDX, IDC_USER_NAME, m_UserName); DDX_Text(pDX, IDC_PASSWORD, m_Password); //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CPropPageShareLocation, CPropertyPage) //{{AFX_MSG_MAP(CPropPageShareLocation) ON_EN_CHANGE(IDC_MOUNT_POINT, OnChangeMountPoint) ON_CBN_SELCHANGE(IDC_TYPE, OnSelchangeType) ON_EN_CHANGE(IDC_PATH, OnChangePath) ON_EN_CHANGE(IDC_HOST, OnChangeHost) ON_EN_CHANGE(IDC_USER_NAME, OnChangeUserName) ON_EN_CHANGE(IDC_PASSWORD, OnChangePassword) ON_BN_CLICKED(IDC_BROWSE, OnBrowse) ON_CBN_KILLFOCUS(IDC_TYPE, OnKillfocusType) //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CPropPageShareLocation message handlersBOOL CPropPageShareLocation::OnInitDialog() { CPropertyPage::OnInitDialog(); if (mPath.GetUrl().GetUrlPath().empty()) { try { WarSvrPath::path_t alias = "/pub/new"; mPath = WarSvrPath(alias, WarUrl("file:///"), 0); } catch(WarException) { } } else { m_MountMoint = WarUtf8(mPath.GetAlias().GetPath()).GetSysStr().c_str(); } UpdateUrl(mPath.GetUrl().GetUrl(false).c_str()); return TRUE; }void CPropPageShareLocation::OnChangeMountPoint() { UpdateUrlItem();}void CPropPageShareLocation::OnSelchangeType() { UpdateUrlItem();}void CPropPageShareLocation::OnKillfocusType() { UpdateUrlItem();}void CPropPageShareLocation::OnChangePath() { UpdateUrlItem();}void CPropPageShareLocation::OnChangeHost() { UpdateUrlItem();}void CPropPageShareLocation::OnChangeUserName() { UpdateUrlItem();}void CPropPageShareLocation::OnChangePassword() { UpdateUrlItem();}void CPropPageShareLocation::OnBrowse() { BROWSEINFO bi; memset(&bi, 0, sizeof(bi)); TCHAR pszDisplayName[MAX_PATH]; *pszDisplayName = 0; bi.hwndOwner = m_hWnd; bi.pszDisplayName = pszDisplayName; bi.lpszTitle = _T("Select a folder"); bi.ulFlags = BIF_NEWDIALOGSTYLE; LPITEMIDLIST pbi = NULL; try { pbi = SHBrowseForFolder(&bi); } catch(...) { AfxMessageBox(_T("Caught an unexpected exception from the network browser.")); return; } if (NULL != pbi) { TCHAR my_path[MAX_PATH]; if (SHGetPathFromIDList(pbi, my_path)) { std::basic_string<TCHAR> host_name, path_name; if ((my_path[0] == '\\') && (my_path[1] == '\\') && _istalpha(my_path[2])) { // Deparse hostname LPCTSTR p = my_path; p += 2; while(*p && (*p != '\\')) host_name += *p++; if (*p == '\\') ++p; path_name = p; } else path_name = my_path; SetDlgItemText(IDC_PATH,path_name.c_str()); SetDlgItemText(IDC_HOST, host_name.empty() ? _T("") : host_name.c_str()); } LPMALLOC mp; if (SUCCEEDED(SHGetMalloc(&mp))) mp->Free(pbi); UpdateUrlItem(); } }void CPropPageShareLocation::RebuildUrl() throw(WarException){ WarCollector<char> type_name, path_name, host_name, user_name, password; WarSvrPath::path_t alias; UpdateData(); type_name = m_Type; path_name = m_Path; host_name = m_Host; user_name = m_UserName; password = m_Password; alias = m_MountMoint; WarUrl my_url; my_url.Create(WarUrlType(type_name.GetValue().c_str()), user_name.GetValue().c_str(), password.GetValue().c_str(), 0, // port host_name.GetValue().c_str(), path_name.GetValue().c_str()); mPath = WarSvrPath(alias, my_url, 0);}void CPropPageShareLocation::UpdateUrlItem(){ try { RebuildUrl(); UpdateUrl(mPath.GetUrl().GetUrl(false).c_str()); } catch(WarException& e) { WarCollector<TCHAR> err_msg = e.Explain(); CString msg; msg.Format(_T("Failed to build a valid URL from input data.\n%s"), err_msg.GetValue().c_str()); AfxMessageBox(msg); }}void CPropPageShareLocation::UpdateUrl(LPCSTR str) throw(WarException){ // Use a tmp buffer to prevent making url from self std::string str_buffer = str; WarUrl my_url; WarSvrPath::path_t alias = m_MountMoint; try { my_url = str_buffer.c_str(); typedef WarCollector<TCHAR> conv_t;#define CONV(func) conv_t(my_url.func(), WarCollector<TCHAR>::SM_ERASE).GetValue().c_str() m_ctlUrl.SetWindowText(CONV(GetUrl)); m_Type = CONV(GetDriverName); m_Path = CONV(GetUrlPath); m_Host= CONV(GetHostName); m_UserName = CONV(GetUserName); m_Password = CONV(GetPassword); } catch(WarException) { m_Type = _T("file"); m_Path = _T(""); m_Host = _T(""); m_UserName = _T(""); m_Password = _T(""); m_ctlUrl.SetWindowText(_T("")); } mPath = WarSvrPath(alias, my_url, 0); UpdateData(FALSE);}void CPropPageShareLocation::OnOK() { UpdateData(); CPropertyPage::OnOK();}BOOL CPropPageShareLocation::OnApply() { if (m_MountMoint.IsEmpty()) { AfxMessageBox(IDS_NO_MOUNT_POINT); return FALSE; } if (mPath.GetUrl().GetUrlPath().empty()) { AfxMessageBox(IDS_NO_PATH); return FALSE; } return TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -