www.pudn.com > News Search3.01.rar > CategoryBar.cpp
// CategoryBar.cpp : implementation file
//
#include "stdafx.h"
#include "NewSearch.h"
#include "CategoryBar.h"
#include "MainFrm.h"
#include "SearchMsgBox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCategoryBar dialog
CCategoryBar::CCategoryBar()
{
}
CCategoryBar::~CCategoryBar()
{
}
void CCategoryBar::DoDataExchange(CDataExchange* pDX)
{
CDialogBar::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCategoryBar)
DDX_Control(pDX, IDC_EDIT_ENGINEKEY, m_engine);
DDX_Control(pDX, IDC_STATIC_SEARCHKEY, m_stEngineKey);
DDX_Control(pDX, IDC_STATIC_ENGINE, m_stEngine);
DDX_Control(pDX, IDC_CHECK_OUT, m_chkOut);
DDX_Control(pDX, IDC_CHECK_IN, m_chkIn);
DDX_Control(pDX, IDC_TAB_CATEGORY, m_category);
DDX_Control(pDX, IDC_STATIC_TIME, m_stTime);
DDX_Control(pDX, IDC_STATIC_KEY, m_stKey);
DDX_Control(pDX, IDC_EDIT_KEY, m_key);
DDX_Control(pDX, IDC_DATETIMEPICKER, m_date);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCategoryBar, CDialogBar)
//{{AFX_MSG_MAP(CCategoryBar)
ON_WM_SIZE()
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_CATEGORY, OnSelchangeTabCategory)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_INITDIALOGBAR,InitDialogBarHandler)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCategoryBar message handlers
void CCategoryBar::InitDialogBarHandler(WORD wParam, DWORD lParam)
{
UpdateData(FALSE);
OnInitDialogBar();
}
void CCategoryBar::OnInitDialogBar()
{
CBitmap m_bmp;
m_bmp.LoadBitmap(IDB_CATEGORY_LIST);
m_img.Create(16,16,ILC_COLOR24 | ILC_MASK,11,0);
m_img.Add(&m_bmp,RGB(255,0,255));
m_category.SetImageList(&m_img);
CString strCate;
for(int i = 0; i < CATEGORY_NUM; i++)
{
strCate.LoadString(IDS_CATEGORY_COL0 + i);
m_category.InsertItem(i,strCate,i);
}
CRect rc;
GetWindowRect(rc);
AdjustCtrlPos(rc.Width(), rc.Height());
int m_iCategoryItem = AfxGetApp()->GetProfileInt(_T("Base"),_T("NewsClass"),0);
m_bCurrencyView = m_iCategoryItem == CATEGORY_CURRENCY ? TRUE : FALSE;
m_category.SetCurSel(m_iCategoryItem);
ChangeView(m_iCategoryItem, TRUE);
BOOL m_in = AfxGetApp()->GetProfileInt(_T("Base"),_T("EngineIn"),1);
BOOL m_out = AfxGetApp()->GetProfileInt(_T("Base"),_T("EngineOut"),0);
m_chkIn.SetCheck(m_in);
m_chkOut.SetCheck(m_out);
CString strKey;
strKey = AfxGetApp()->GetProfileString(_T("Base"),_T("SearchKey"));
if(!strKey.IsEmpty())
m_engine.SetWindowText(strKey);
AdjustCategoryItem();
}
void CCategoryBar::AdjustCtrlPos(int cx, int cy)
{
CRect rc;
rc.SetRect(6,4,cx - 6,cy - 6);
m_category.MoveWindow(rc);
rc.SetRect(15,34,230,50);
m_stKey.MoveWindow(rc);
rc.SetRect(230,30,cx - 205,50);
m_key.MoveWindow(rc);
rc.SetRect(15,34,145,50);
m_stEngineKey.MoveWindow(rc);
rc.SetRect(145,30,cx - 205,50);
m_engine.MoveWindow(rc);
rc.SetRect(cx - 197,34,cx - 130,50);
m_stTime.MoveWindow(rc);
rc.SetRect(cx - 126,30,cx - 16,50);
m_date.MoveWindow(rc);
rc.SetRect(cx - 197,34,cx - 104,50);
m_stEngine.MoveWindow(rc);
rc.SetRect(cx - 104,32,cx - 60,50);
m_chkIn.MoveWindow(rc);
rc.SetRect(cx - 57,32,cx - 16,50);
m_chkOut.MoveWindow(rc);
Invalidate();
}
void CCategoryBar::OnSize(UINT nType, int cx, int cy)
{
CDialogBar::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(m_category.GetSafeHwnd() != NULL)
AdjustCtrlPos(cx,cy);
}
void CCategoryBar::OnSelchangeTabCategory(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int iCategory = m_category.GetCurSel();
ChangeView(iCategory);
*pResult = 0;
}
void CCategoryBar::ChangeView(int iCategory, BOOL bInit/* = FALSE*/)
{
CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
ASSERT(pFrame);
pFrame->OnCategoryChanged(iCategory,bInit);
}
void CCategoryBar::AdjustCategoryItem()
{
if(!m_bCurrencyView)
{
m_stEngineKey.ShowWindow(SW_HIDE);
m_engine.ShowWindow(SW_HIDE);
m_stEngine.ShowWindow(SW_HIDE);
m_chkIn.ShowWindow(SW_HIDE);
m_chkOut.ShowWindow(SW_HIDE);
m_stKey.ShowWindow(SW_SHOW);
m_key.ShowWindow(SW_SHOW);
m_stTime.ShowWindow(SW_SHOW);
m_date.ShowWindow(SW_SHOW);
}
else
{
m_stKey.ShowWindow(SW_HIDE);
m_key.ShowWindow(SW_HIDE);
m_stTime.ShowWindow(SW_HIDE);
m_date.ShowWindow(SW_HIDE);
m_stEngineKey.ShowWindow(SW_SHOW);
m_engine.ShowWindow(SW_SHOW);
m_stEngine.ShowWindow(SW_SHOW);
m_chkIn.ShowWindow(SW_SHOW);
m_chkOut.ShowWindow(SW_SHOW);
m_engine.SetSel(0,-1);
m_engine.SetFocus();
}
}
void CCategoryBar::BeforeSearch()
{
m_key.EnableWindow(FALSE);
m_date.EnableWindow(FALSE);
m_chkIn.EnableWindow(FALSE);
m_chkOut.EnableWindow(FALSE);
}
void CCategoryBar::AfterStop()
{
m_key.EnableWindow();
m_date.EnableWindow();
m_chkIn.EnableWindow();
m_chkOut.EnableWindow();
}
int CCategoryBar::GetCategoryItem()
{
int m_iCategoryItem = m_category.GetCurSel();
return m_iCategoryItem;
}
BOOL CCategoryBar::GetSearchNewsSet(CString &strKey, CTime &tDate)
{
CString tip,m_editval,m_strNewsItem,str;
CTime m_timeval,m_today;
m_date.GetTime(m_timeval);
m_today = CTime::GetCurrentTime();
if(m_timeval - m_today > CTimeSpan(1,0,0,0) ||
m_timeval < m_today - CTimeSpan(3650,0,0,0))
{
m_timeval = m_today;
tip = _T("你选择的时间超出了程序可以接受的范围:\n\n");
tip += _T("程序将时间调整到“") +
m_timeval.Format(_T("%Y年%#m月%#d日")) + "”。\n";
if(AfxMessageBox(tip + _T("\n你要继续搜索吗?"),
MB_YESNO + MB_ICONQUESTION) == IDYES)
m_date.SetTime(&m_today);
else
return FALSE;
}
int m_iNewsItem = m_category.GetCurSel();
m_key.GetWindowText(m_editval);
if(m_editval == _T(""))
{
m_strNewsItem.LoadString(IDS_CATEGORY_COL0 + m_iNewsItem);
tip = _T("你没有输入任何关键字:程序将搜索所有“")
+ m_timeval.Format(_T("%Y年%#m月%#d日")) + _T("”属于“")
+ m_strNewsItem
+ _T("”类的新闻。\n");
BOOL m_bShowTip = AfxGetApp()->GetProfileInt(_T("Base"),_T("ShowSearchTip"),1);
if(m_bShowTip)
{
str.Format(_T("注意:\n\n%s\n你想继续搜索吗?"),tip);
CSearchMsgBox box(str,BTN_YES_NO,ICON_QUESTION);
int OkOrCancel = box.DoModal();
if(OkOrCancel == IDCANCEL) return FALSE;
}
}
strKey = m_editval;
tDate = m_timeval;
return TRUE;
}
BOOL CCategoryBar::GetSearchData(int &m_engineclass, CString &m_strKey)
{
int m_enginein,m_engineout;
m_enginein = m_chkIn.GetCheck();
m_engineout = m_chkOut.GetCheck();
if(m_enginein && m_engineout)
m_engineclass = 3;
else if(m_enginein) m_engineclass = 1;
else if(m_engineout) m_engineclass = 2;
else
{
AfxMessageBox(_T("在进行搜索之前,请选择搜索引擎:"),MB_ICONINFORMATION);
return FALSE;
}
m_engine.GetWindowText(m_strKey);
if(m_strKey.IsEmpty())
{
AfxMessageBox(_T("在进行搜索之前,请输入搜索的关键字"),
MB_ICONINFORMATION);
return FALSE;
}
return TRUE;
}
void CCategoryBar::SaveEngineSet()
{
int m_in = m_chkIn.GetCheck();
int m_out = m_chkOut.GetCheck();
AfxGetApp()->WriteProfileInt(_T("Base"),_T("EngineIn"),m_in);
AfxGetApp()->WriteProfileInt(_T("Base"),_T("EngineOut"),m_out);
CString strKey;
m_engine.GetWindowText(strKey);
AfxGetApp()->WriteProfileString(_T("Base"),_T("SearchKey"),strKey);
}