📄 mainfrm.cpp
字号:
str.LoadString(IDS_SEARCH_BEGIN);
m_wndToolBar.SetButtonInfo(10,ID_SEARCH_BEGIN,TBSTYLE_BUTTON,7);
m_wndToolBar.SetButtonText(10,str);
str.LoadString(IDS_SEARCH_STOP);
m_wndToolBar.SetButtonInfo(11,ID_SEARCH_STOP,TBSTYLE_BUTTON,8);
m_wndToolBar.SetButtonText(11,str);
m_wndToolBar.SetButtonInfo(12,0,TBSTYLE_SEP,0);
str.LoadString(IDS_VIEW_PROPERTY);
m_wndToolBar.SetButtonInfo(13,ID_VIEW_PROPERTY,TBSTYLE_BUTTON,9);
m_wndToolBar.SetButtonText(13,str);
str.LoadString(IDS_HELP_MAILTO);
m_wndToolBar.SetButtonInfo(14,ID_HELP_MAILTO,TBSTYLE_BUTTON,10);
m_wndToolBar.SetButtonText(14,str);
str.LoadString(IDS_HELP_HOME);
m_wndToolBar.SetButtonInfo(15,ID_HELP_HOME,TBSTYLE_BUTTON,11);
m_wndToolBar.SetButtonText(15,str);
m_wndToolBar.GetItemRect(0, &m_rBigBtn);
CRect rectToolBar;
// set up toolbar button sizes
m_wndToolBar.GetItemRect(0, &rectToolBar);
m_wndToolBar.SetSizes(rectToolBar.Size(), m_sizeButton);
m_wndToolBar.ModifyStyle(0,CCS_ADJUSTABLE);
m_wndToolBar.SetSizes(m_rSmallBtn.Size(), m_sizeButton);
return TRUE;
}
void CMainFrame::OnViewFullscreen()
{
// TODO: Add your command handler code here
if (m_bFullScreen)
FullScreenOff ();
else
FullScreenOn ();
}
void CMainFrame::FullScreenOn()
{
m_bStatusBarWasVisible = m_wndStatusBar.IsWindowVisible () != FALSE;
if (m_bStatusBarWasVisible) m_wndStatusBar.ShowWindow (SW_HIDE);
m_wndReBar.ShowWindow(SW_HIDE);
// Create the new toolbar
m_pwndFullBar = new CFullScreenBar;
m_pwndFullBar->Create(this,ID_VIEW_FULLSCREEN,IDS_FULL_TITLE,
IDS_CLOSE_FULL,CSize(16,15),
IDB_COLD_FULL,IDB_HOT_FULL);
EnableDocking(CBRS_ALIGN_ANY);
m_pwndFullBar->EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
// place the full-screen off button somewhere:
int screenx = GetSystemMetrics(SM_CXSCREEN);
int screeny = GetSystemMetrics(SM_CYSCREEN);
FloatControlBar(m_pwndFullBar, CPoint(screenx-120,5));
// remove the caption of the mainWnd:
LONG style = ::GetWindowLong (m_hWnd, GWL_STYLE);
m_bMax = style & WS_MAXIMIZE ? TRUE : FALSE;
if (m_bMax) ShowWindow (SW_RESTORE);
// now save the old positions of the main and child windows
GetWindowRect (&m_mainRect);
style &= ~(WS_CAPTION|WS_MAXIMIZE);
::SetWindowLong (m_hWnd, GWL_STYLE, style);
// resize:
SetWindowPos (NULL, -4, -4, screenx + 8, screeny + 8, SWP_NOZORDER);
style = ::GetWindowLong (m_hWnd, GWL_STYLE);
RecalcLayout ();
m_bFullScreen = TRUE;
}
void CMainFrame::FullScreenOff()
{
// You can use SaveBarState() in OnClose(),
// so remove the newly added toolbar entirely
// in order SaveBarState() not to save its state.
// That is why I used dynamic allocation
delete m_pwndFullBar;
LONG style = ::GetWindowLong (m_hWnd, GWL_STYLE);
style |= WS_CAPTION;
::SetWindowLong(m_hWnd, GWL_STYLE, style);
if (m_bStatusBarWasVisible) m_wndStatusBar.ShowWindow (SW_SHOW);
m_wndReBar.ShowWindow(SW_SHOW);
MoveWindow(&m_mainRect);
RecalcLayout();
if(m_bMax) ShowWindow(SW_SHOWMAXIMIZED);
m_bFullScreen = FALSE;
}
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// TODO: Add your message handler code here and/or call default
lpMMI->ptMinTrackSize.x = GetSystemMetrics(SM_CXSCREEN)*7/8;
CFrameWnd::OnGetMinMaxInfo(lpMMI);
}
void CMainFrame::SetBarBackImage(LPCTSTR lpszBmpName/* = NULL*/)
{
HBITMAP m_hBmp = NULL;
if(lpszBmpName != NULL)
{
m_hBmp = (HBITMAP)::LoadImage(NULL, lpszBmpName,
IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
}
CCJReBarCtrl& rc = m_wndReBar.GetReBarCtrl();
int i, iBandCount;
iBandCount = rc.GetBandCount();
for (i = 0; i < iBandCount; i++)
{
REBARBANDINFO info;
memset (&info, 0, sizeof (REBARBANDINFO));
info.cbSize = sizeof (info);
info.fMask = RBBIM_CHILD;
rc.GetBandInfo (i, &info);
if (info.hwndChild != NULL && info.hwndChild != m_wndAnimate.m_hWnd)
{
info.fMask = RBBIM_BACKGROUND;
info.hbmBack = m_hBmp;
rc.SetBandInfo (i, &info);
CRect rectBand;
rc.GetRect (i, rectBand);
rc.InvalidateRect (rectBand);
rc.UpdateWindow ();
::InvalidateRect (info.hwndChild, NULL, TRUE);
::UpdateWindow (info.hwndChild);
}
}
}
void CMainFrame::OnViewBack()
{
// TODO: Add your command handler code here
CBackSetDlg m_BackSetDlg;
if(m_BackSetDlg.DoModal() == IDOK)
{
if(m_bRebarImg && !m_strRebarImg.IsEmpty())
SetBarBackImage(m_strRebarImg);
else SetBarBackImage();
}
}
void CMainFrame::LoadProfileSet()
{
// Reg Set
m_bHasPost = AfxGetApp()->GetProfileInt(_T("Base"),_T("HasPost"),0);
// Tip Set
m_bShowTip = AfxGetApp()->GetProfileInt(_T("Base"),_T("StartUp"),1);
// Connect Set
m_TimeOut = AfxGetApp()->GetProfileInt(_T("Settings"),
_T("TimeOut"),SEARCH_TIME_DEF);
m_MaxThreadCount = AfxGetApp()->GetProfileInt(_T("Settings"),
_T("ThreadNum"),MAX_WAIT_THREAD);
m_IngoreLegth = AfxGetApp()->GetProfileInt(_T("Settings"),
_T("FileLength"),DEF_INGORE_NUM);
m_IsIngoreLong = AfxGetApp()->GetProfileInt(_T("Settings"),
_T("IgnoreLength"),0);
m_UseProxy = AfxGetApp()->GetProfileInt(_T("Settings"),
_T("UseProxy"),0);
m_Proxy = AfxGetApp()->GetProfileString(_T("Settings"),
_T("m_Proxy"));
m_Port = AfxGetApp()->GetProfileString(_T("Settings"),
_T("m_Port"));
}
void CMainFrame::SaveProfileSet()
{
// Reg Set
AfxGetApp()->WriteProfileInt(_T("Base"),_T("HasPost"),m_bHasPost);
// Set Splasp Wnd And Tip
AfxGetApp()->WriteProfileInt(_T("Base"),_T("ShowSplash"),m_bShowSplash);
AfxGetApp()->WriteProfileInt(_T("Base"),_T("StartUp"),m_bShowTip);
// Connect Set
AfxGetApp()->WriteProfileInt(_T("Settings"),_T("TimeOut"),m_TimeOut);
AfxGetApp()->WriteProfileInt(_T("Settings"),_T("ThreadNum"),m_MaxThreadCount);
AfxGetApp()->WriteProfileInt(_T("Settings"),_T("FileLength"),m_IngoreLegth);
AfxGetApp()->WriteProfileInt(_T("Settings"),_T("IgnoreLength"),m_IsIngoreLong);
AfxGetApp()->WriteProfileInt(_T("Settings"),_T("UseProxy"),m_UseProxy);
AfxGetApp()->WriteProfileString(_T("Settings"),_T("m_Proxy"),m_Proxy);
AfxGetApp()->WriteProfileString(_T("Settings"),_T("m_Port"),m_Port);
// Save bar back
AfxGetApp()->WriteProfileInt(_T("Base"),_T("UseBarBack"),m_bRebarImg);
AfxGetApp()->WriteProfileString(_T("Base"),_T("BarBackImage"),m_strRebarImg);
// Save Category bar states
int m_SmallIcon = m_wndCategoryBar.IsSmallIconView();
AfxGetApp()->WriteProfileInt(_T("BarStatus"),_T("SmallIconView"),m_SmallIcon);
int m_CurSelFolder = m_wndCategoryBar.GetSelFolder();
AfxGetApp()->WriteProfileInt(_T("BarStatus"),_T("CurSelFolder"),m_CurSelFolder);
CString strPos;
strPos.Format(_T("%s;%s;%s"),strFolderPosOne,strFolderPosTwo,strFolderPosThree);
AfxGetApp()->WriteProfileString(_T("BarStatus"),_T("CategoryPosition"),strPos);
AfxGetApp()->WriteProfileInt(_T("BarStatus"),_T("CategoryBar"),m_bCategoryBar);
AfxGetApp()->WriteProfileInt(_T("BarStatus"),_T("CurSubCategory"),m_iCurSel);
int m_CateBarLength,cxMin;
m_wndSplitter.GetColumnInfo(0,m_CateBarLength,cxMin);
AfxGetApp()->WriteProfileInt(_T("BarStatus"),_T("CateBarLength"),m_CateBarLength);
// Save the bar and window states.
WINDOWPLACEMENT WndStatus;
WndStatus.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(&WndStatus);
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("Flag"),WndStatus.flags);
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("ShowCmd"),WndStatus.showCmd);
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("Left"), WndStatus.rcNormalPosition.left);
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("Top"), WndStatus.rcNormalPosition.top);
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("Right"), WndStatus.rcNormalPosition.right);
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("Bottom"), WndStatus.rcNormalPosition.bottom);
}
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
if(m_IsThreadRunning)
{
if(AfxMessageBox(IDS_THREAD_RUNNING,MB_YESNO +
MB_ICONINFORMATION) == IDYES)
{
KillThreads();
AfterStop(TRUE);
}
else return;
}
if(m_StockDb.IsOpen()) m_StockDb.Close();
SaveProfileSet();
CFrameWnd::OnClose();
}
long CMainFrame::OnCategorybarNotify(WPARAM wParam, LPARAM lParam)
{
int i,iImage[7],iCurSelFolder;
HICON hIcon;
iCurSelFolder = m_wndCategoryBar.GetSelFolder();
switch (wParam)
{
case NM_OB_ITEMCLICK:
m_iCurSel = (int)lParam;
iCurSel = m_wndCategoryBar.GetItemImage(m_iCurSel);
hIcon = m_SmallFinance.ExtractIcon(m_wndCategoryBar.GetItemImage(m_iCurSel));
if(!GetContainView()->OnCateogryChanged(
m_wndCategoryBar.GetItemText(m_iCurSel),hIcon))
AfxMessageBox(IDS_PROGRAM_ERROR,MB_ICONSTOP);
else
GetStockReferView()->UpdateInfoContent();
break;
case NM_OB_DRAGITEM:
switch(iCurSelFolder)
{
case 0:
for(i=0;i<3;i++)
iImage[i] = m_wndCategoryBar.GetItemImage(i);
strFolderPosOne.Format(_T("%d,%d,%d"),iImage[0],iImage[1],iImage[2]);
break;
case 1:
for(i=0;i<6;i++)
iImage[i] = m_wndCategoryBar.GetItemImage(i);
strFolderPosTwo.Format(_T("%d,%d,%d,%d,%d,%d"),
iImage[0],iImage[1],iImage[2],iImage[3],iImage[4],iImage[5]);
break;
case 2:
for(i=0;i<7;i++)
iImage[i] = m_wndCategoryBar.GetItemImage(i);
strFolderPosThree.Format(_T("%d,%d,%d,%d,%d,%d,%d"),
iImage[0],iImage[1],iImage[2],iImage[3],iImage[4],iImage[5],iImage[6]);
break;
}
return 1;
}
return 0;
}
void CMainFrame::BeforeSearch()
{
m_IsThreadRunning = TRUE;
m_wndAnimate.Play(0,-1,-1);
m_wndStatusBar.SetPaneText (1, _T("准备接收资讯..."), TRUE);
m_wndStatusBar.SetPaneText (2, _T("已接收资讯 0 条"), TRUE);
}
void CMainFrame::OnViewCategory()
{
// TODO: Add your command handler code here
m_bCategoryBar = !m_bCategoryBar;
if(m_bCategoryBar)
m_wndSplitter.ShowColumn();
else
m_wndSplitter.HideColumn(0);
}
void CMainFrame::OnUpdateViewCategory(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bCategoryBar);
}
CContainView* CMainFrame::GetContainView()
{
CWnd *pWnd;
if(m_bCategoryBar)
pWnd = m_wndSplitter.GetPane(0,1);
else
pWnd = m_wndSplitter.GetPane(0,0);
return (CContainView*)pWnd;
}
CStockReferView* CMainFrame::GetStockReferView()
{
return GetContainView()->GetStockReferView();
}
void CMainFrame::OnHelpHome()
{
// TODO: Add your command handler code here
ShellExecute(NULL, _T("open"), NEWSEARCH_HOME, NULL, NULL, SW_SHOW);
}
BOOL CMainFrame::CanExport()
{
BOOL m_bEnable;
if(m_IsThreadRunning) return FALSE;
m_bEnable = GetContainView()->CanExport();
return m_bEnable;
}
void CMainFrame::SetPaneText(int iPane, LPCTSTR lpszStr)
{
m_wndStatusBar.SetPaneText(iPane,lpszStr,TRUE);
}
void CMainFrame::OnViewList()
{
// TODO: Add your command handler code here
GetContainView()->ShowCaptButton();
}
void CMainFrame::OnUpdateViewList(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(GetContainView()->m_bViewList);
}
void CMainFrame::OnFileExport()
{
// TODO: Add your command handler code here
GetStockReferView()->ExportToFile();
}
void CMainFrame::OnEditProperty()
{
// TODO: Add your command handler code here
GetStockReferView()->FontChanged();
}
void CMainFrame::OnViewProperty()
{
// TODO: Add your command handler code here
COptionSheet m_OptionSheet(IDS_OPTION_SHEET);
m_OptionSheet.DoModal();
}
void CMainFrame::OnHelpReg()
{
// TODO: Add your command handler code here
CRegDlg m_RegDlg;
m_RegDlg.DoModal();
}
void CMainFrame::OnUpdateFileExport(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!m_IsThreadRunning);
}
void CMainFrame::OnUpdateEditDelete(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
BOOL m_bEnable = !m_IsThreadRunning;
if(m_bEnable)
m_bEnable = GetContainView()->CanDeleteOption();
pCmdUI->Enable(m_bEnable);
}
void CMainFrame::OnUpdateViewProperty(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!m_IsThreadRunning);
}
void CMainFrame::OnUpdateHelpReg(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!m_IsThreadRunning);
}
void CMainFrame::OnEditDelete()
{
// TODO: Add your command handler code here
GetContainView()->DeleteOption();
}
void CMainFrame::OnUpdateFilePrint(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(CanExport());
}
void CMainFrame::OnUpdateFilePrintPreview(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(CanExport());
}
void CMainFrame::OnSearchBegin()
{
// TODO: Add your command handler code here
if(!m_StockDb.IsOpen() && !OpenStockdatDb())
{
AfxMessageBox(IDS_OPENDB_ERROR,MB_ICONSTOP);
return;
}
int iCurImage = m_wndCategoryBar.GetItemImage(m_iCurSel);
CString strTitle = m_wndCategoryBar.GetItemText(m_iCurSel);
CDlgSearch m_DlgSearch(strTitle,iCurImage);
if(m_DlgSearch.DoModal() == IDOK)
{
if(BeginStockSearch()) BeforeSearch();
}
}
void CMainFrame::OnUpdateSearchBegin(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!m_IsThreadRunning);
}
void CMainFrame::OnSearchStop()
{
// TODO: Add your command handler code here
if(AfxMessageBox(_T("你真的要停止本次搜索吗?"),MB_YESNO |
MB_ICONINFORMATION | MB_DEFBUTTON2) == IDYES)
{
KillThreads();
CString getnews;
getnews.Format(_T("共搜索到资讯 %d 条。"),m_NewsCount);
m_wndStatusBar.SetPaneText (1, _T("搜索过程被中断。"), TRUE);
m_wndStatusBar.SetPaneText (2, getnews, TRUE);
AfterStop();
}
}
void CMainFrame::OnUpdateSearchStop(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_IsThreadRunning);
}
void CMainFrame::OnUpdateEditCopys(CCmdUI* pCmdUI)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -