⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 organizeurldlg.cpp

📁 一个多窗口的浏览器的程序benbrowse
💻 CPP
字号:
// OrganizeURLDlg.cpp : implementation file
//

#include "stdafx.h"
#include "benbenbrowser.h"
#include "OrganizeURLDlg.h"
#include "generaldata.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// COrganizeURLDlg dialog


COrganizeURLDlg::COrganizeURLDlg(CWnd* pParent /*=NULL*/)
	: CDialog(COrganizeURLDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(COrganizeURLDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_action=-1;
}


void COrganizeURLDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COrganizeURLDlg)
	DDX_Control(pDX, IDC_EDIT_URL, m_edit_url);
	DDX_Control(pDX, IDC_EDIT_TITLE, m_edit_title);
	DDX_Control(pDX, IDC_LIST_URL_TITLE, m_list_url);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(COrganizeURLDlg, CDialog)
	//{{AFX_MSG_MAP(COrganizeURLDlg)
	ON_BN_CLICKED(IDC_BUTTON_INSERT, OnButtonInsert)
	ON_BN_CLICKED(IDC_BUTTON_UPDATE, OnButtonUpdate)
	ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
	ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnButtonCancel)
	ON_BN_CLICKED(IDC_BUTTON_ACTION, OnButtonAction)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COrganizeURLDlg message handlers

BOOL COrganizeURLDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	GetWindowRect(m_rectExpn);
	CWnd *wnd=GetDlgItem(IDC_STATIC_EXPN);
	wnd->GetWindowRect(m_rectColp);
	m_rectColp.bottom=m_rectExpn.bottom;
	ExpandDialog(FALSE);

	m_list_url.InsertColumn(0,"",LVCFMT_LEFT,80);
	m_list_url.InsertColumn(1,"",LVCFMT_LEFT,250);
	CString url;
	for(int i=0;i<m_urllist.GetCount();i++)
	{
		url=m_urllist.GetAt(m_urllist.FindIndex(i));
		m_list_url.InsertItem(i,url.Left(url.Find('=')));
		m_list_url.SetItem(i,1,LVIF_TEXT,url.Mid(url.Find('=')+1),0,0,0,0);
	}
	SetLanguage();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void COrganizeURLDlg::ExpandDialog(bool expn)
{
	CRect rect;
	GetWindowRect(rect);
	if(expn)
	{
		if(rect.Height()<m_rectExpn.Height())
		{
			rect.right=rect.left+m_rectExpn.Width();
			rect.bottom=rect.top+m_rectExpn.Height();
			MoveWindow(rect);
		}
	}
	else
	{
		if(rect.Height()>m_rectColp.Height())
		{
			rect.bottom=rect.bottom-m_rectColp.Height();
			MoveWindow(rect);
		}
	}
}

void COrganizeURLDlg::OnButtonInsert() 
{
	// TODO: Add your control notification handler code here
	ExpandDialog(TRUE);
	CString btntitle;
	GetDlgItemText(IDC_BUTTON_INSERT,btntitle);
	SetDlgItemText(IDC_BUTTON_ACTION,btntitle);
	m_edit_title.SetWindowText("");
	m_edit_url.SetWindowText("");
	m_action=1;
}

void COrganizeURLDlg::OnButtonUpdate() 
{
	// TODO: Add your control notification handler code here
	ExpandDialog(TRUE);
	CString btntitle;
	GetDlgItemText(IDC_BUTTON_UPDATE,btntitle);
	SetDlgItemText(IDC_BUTTON_ACTION,btntitle);

	POSITION pos = m_list_url.GetFirstSelectedItemPosition();
	if(!pos)
		return;
	int index=m_list_url.GetNextSelectedItem(pos);
	m_edit_title.SetWindowText(m_list_url.GetItemText(index,0));
	m_edit_url.SetWindowText(m_list_url.GetItemText(index,1));
	m_action=3;
}

void COrganizeURLDlg::OnButtonDelete() 
{
	// TODO: Add your control notification handler code here
	POSITION pos = m_list_url.GetFirstSelectedItemPosition();
	if(!pos)
		return;
	int index=m_list_url.GetNextSelectedItem(pos);
	m_list_url.DeleteItem(index);

}

void COrganizeURLDlg::OnButtonCancel() 
{
	// TODO: Add your control notification handler code here
	ExpandDialog(FALSE);
}

void COrganizeURLDlg::OnButtonAction() 
{
	// TODO: Add your control notification handler code here
	CString title,url;
	m_edit_title.GetWindowText(title);
	m_edit_url.GetWindowText(url);
	if(title.GetLength()<=0||url.GetLength()<=0)
		return;
	if(m_action==1)//insert
	{
		m_list_url.InsertItem(m_list_url.GetItemCount(),title);
		m_list_url.SetItem(m_list_url.GetItemCount()-1,1,LVIF_TEXT,url,0,0,0,0);
	}
	else if(m_action==3)//update
	{
		POSITION pos = m_list_url.GetFirstSelectedItemPosition();
		if(!pos)
			return;
		int index=m_list_url.GetNextSelectedItem(pos);
		m_list_url.SetItem(index,0,LVIF_TEXT,title,0,0,0,0);
		m_list_url.SetItem(index,1,LVIF_TEXT,url,0,0,0,0);
	}
}

void COrganizeURLDlg::SetUrlListData(CStringList *Url)
{
	for(int i=0;i<Url->GetCount();i++)
	{
		m_urllist.AddTail(Url->GetAt(Url->FindIndex(i)));
	}
}

void COrganizeURLDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	m_urllist.RemoveAll();
	CDialog::OnClose();
}

void COrganizeURLDlg::SetLanguage()
{
	CString wintextsrc;
	CString wintextnew;
	
	if(this)
	{
		this->GetWindowText(wintextsrc);
		GetText(wintextsrc,wintextnew,global_item_text);
		this->SetWindowText(wintextnew);
	}

	CWnd *wnd=GetDlgItem(IDOK);
	if(wnd)
	{
		wnd->GetWindowText(wintextsrc);
		GetText(wintextsrc,wintextnew,global_item_text);
		wnd->SetWindowText(wintextnew);
	}
	
	wnd=GetDlgItem(IDCANCEL);
	if(wnd)
	{
		wnd->GetWindowText(wintextsrc);
		GetText(wintextsrc,wintextnew,global_item_text);
		wnd->SetWindowText(wintextnew);
	}
	
	wnd=GetDlgItem(IDC_BUTTON_INSERT);
	if(wnd)
	{
		wnd->GetWindowText(wintextsrc);
		GetText(wintextsrc,wintextnew,global_item_text);
		wnd->SetWindowText(wintextnew);
	}
	
	wnd=GetDlgItem(IDC_BUTTON_UPDATE);
	if(wnd)
	{
		wnd->GetWindowText(wintextsrc);
		GetText(wintextsrc,wintextnew,global_item_text);
		wnd->SetWindowText(wintextnew);
	}
	
	wnd=GetDlgItem(IDC_BUTTON_DELETE);
	if(wnd)
	{
		wnd->GetWindowText(wintextsrc);
		GetText(wintextsrc,wintextnew,global_item_text);
		wnd->SetWindowText(wintextnew);
	}
	
	wnd=GetDlgItem(IDC_STATIC_TITLE);
	if(wnd)
	{
		wnd->GetWindowText(wintextsrc);
		GetText(wintextsrc,wintextnew,global_item_text);
		wnd->SetWindowText(wintextnew);
	}
	
	wnd=GetDlgItem(IDC_STATIC_URL);
	if(wnd)
	{
		wnd->GetWindowText(wintextsrc);
		GetText(wintextsrc,wintextnew,global_item_text);
		wnd->SetWindowText(wintextnew);
	}
	
	wnd=GetDlgItem(IDC_BUTTON_CANCEL);
	if(wnd)
	{
		wnd->GetWindowText(wintextsrc);
		GetText(wintextsrc,wintextnew,global_item_text);
		wnd->SetWindowText(wintextnew);
	}
	
}

void COrganizeURLDlg::OnOK() 
{
	// TODO: Add extra validation here
	CString wholeurl;
	m_urllist.RemoveAll();
	for(int i=0;i<m_list_url.GetItemCount();i++)
	{
		wholeurl=m_list_url.GetItemText(i,0)+"=";
		wholeurl+=m_list_url.GetItemText(i,1);
		m_urllist.AddTail(wholeurl);
	}
	CDialog::OnOK();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -