📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "StockRefer.h"
#include "MainFrm.h"
#include "TitleView.h"
#include "StockReferView.h"
#include "BackSetDlg.h"
#include "Splash.h"
#include "DlgSearch.h"
#include "OptionSheet.h"
#include "SerialNum.h"
#include "RegDlg.h"
#include "Newsdat.h"
#include "NewsNouse.h"
#include "HttpDown.h"
#include "htmlhelp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
HANDLE hConnection;
long lThreadCount = 0;
long lURLCount = 0;
#define UNREG_SEARCH_NEWS 20
static int iCategoryIndex[17] = {0,1,2,3,4,5,12,15,16,6,7,8,9,10,13,14,11};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_VIEW_FULLSCREEN, OnViewFullscreen)
ON_WM_GETMINMAXINFO()
ON_COMMAND(ID_VIEW_BACK, OnViewBack)
ON_WM_CLOSE()
ON_COMMAND(ID_VIEW_CATEGORY, OnViewCategory)
ON_UPDATE_COMMAND_UI(ID_VIEW_CATEGORY, OnUpdateViewCategory)
ON_COMMAND(ID_HELP_HOME, OnHelpHome)
ON_COMMAND(ID_VIEW_LIST, OnViewList)
ON_UPDATE_COMMAND_UI(ID_VIEW_LIST, OnUpdateViewList)
ON_COMMAND(ID_FILE_EXPORT, OnFileExport)
ON_COMMAND(ID_EDIT_PROPERTY, OnEditProperty)
ON_COMMAND(ID_VIEW_PROPERTY, OnViewProperty)
ON_COMMAND(ID_HELP_REG, OnHelpReg)
ON_UPDATE_COMMAND_UI(ID_FILE_EXPORT, OnUpdateFileExport)
ON_UPDATE_COMMAND_UI(ID_EDIT_DELETE, OnUpdateEditDelete)
ON_UPDATE_COMMAND_UI(ID_VIEW_PROPERTY, OnUpdateViewProperty)
ON_UPDATE_COMMAND_UI(ID_HELP_UPDATE, OnUpdateHelpUpdate)
ON_UPDATE_COMMAND_UI(ID_HELP_REG, OnUpdateHelpReg)
ON_COMMAND(ID_EDIT_DELETE, OnEditDelete)
ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdateFilePrint)
ON_UPDATE_COMMAND_UI(ID_FILE_PRINT_PREVIEW, OnUpdateFilePrintPreview)
ON_COMMAND(ID_SEARCH_BEGIN, OnSearchBegin)
ON_UPDATE_COMMAND_UI(ID_SEARCH_BEGIN, OnUpdateSearchBegin)
ON_COMMAND(ID_SEARCH_STOP, OnSearchStop)
ON_UPDATE_COMMAND_UI(ID_SEARCH_STOP, OnUpdateSearchStop)
ON_UPDATE_COMMAND_UI(ID_EDIT_COPYS, OnUpdateEditCopys)
ON_COMMAND(ID_EDIT_COPYS, OnEditCopys)
ON_WM_INITMENUPOPUP()
ON_COMMAND(ID_HELP_MAILTO, OnHelpMailto)
ON_COMMAND(ID_HELP_INDEX, OnHelpIndex)
ON_COMMAND(ID_HELP_UPDATE, OnHelpUpdate)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_CATEGORY_NOTIFY, OnCategorybarNotify)
ON_MESSAGE(WM_USER_THREAD_DONE,OnThreadDone)
ON_MESSAGE(WM_USER_SERVER_STATUS,OnServerStatus)
ON_MESSAGE(WM_USER_SEND_BODY,OnSendBody)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
m_bFirst = TRUE;
m_bFullScreen = FALSE;
m_IsThreadRunning = FALSE;
m_ThreadCount = 0;
m_iCurItem = 0;
m_lCurThreads = 0;
m_lMaxThreads = MAX_WAIT_THREAD;
hConnection = CreateSemaphore( NULL,m_lCurThreads,m_lMaxThreads,NULL);
InitializeCriticalSection(&m_CritSect);
m_NewsCount = 0;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// CG: The following line was added by the Splash Screen component.
m_bShowSplash = AfxGetApp()->GetProfileInt(_T("Base"),_T("ShowSplash"),1);
if(m_bShowSplash)
{
CSplashWnd::ShowSplashScreen(this);
Sleep(1500);
}
if(!CreateStanderBar())
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if(!m_wndMenuBar.CreateEx(this) ||
!m_wndMenuBar.LoadMenu(IDR_MAINFRAME))
{
TRACE0("Failed to create menu\n");
return -1; // fail to create
}
m_wndMenuBar.ModifyStyle(0, TBSTYLE_TRANSPARENT);
if(!m_wndAnimate.Create(WS_CHILD | WS_VISIBLE ,
CRect(0,0,0,0), this, ID_ANIMATE_RUN) ||
!m_wndAnimate.Open(IDR_AVI_RUN))
{
TRACE0("Failed to create animation control.\n");
return -1; // fail to create
}
if(!m_wndReBar.Create(this) ||
!m_wndReBar.AddBar(&m_wndMenuBar, NULL, NULL, RBBS_FIXEDBMP) ||
!m_wndReBar.AddBar(&m_wndAnimate, RGB(255,255,255),
RGB(0,0,0), NULL, RBBS_FIXEDSIZE | RBBS_FIXEDBMP) ||
!m_wndReBar.AddBar(&m_wndToolBar, NULL, NULL,
RBBS_BREAK | RBBS_FIXEDBMP | RBBS_CHILDEDGE))
{
TRACE0("Failed to create rebar\n");
return -1; // fail to create
}
m_bRebarImg = AfxGetApp()->GetProfileInt(_T("Base"),
_T("UseBarBack"),0);
m_strRebarImg = AfxGetApp()->GetProfileString(_T("Base"),
_T("BarBackImage"));
if(m_bRebarImg && !m_strRebarImg.IsEmpty())
SetBarBackImage(m_strRebarImg);
if(!m_wndStatusBar.Create(this))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
m_wndStatusBar.SetIndicators(indicators, 3);
TEXTMETRIC tm;
CClientDC dc (this);
CFont* pFont = m_wndStatusBar.GetFont();
CFont* pOldFont = dc.SelectObject(pFont);
dc.GetTextMetrics(&tm);
dc.SelectObject(pOldFont);
int cxWidth;
UINT nID, nStyle;
m_wndStatusBar.GetPaneInfo (1, nID, nStyle, cxWidth);
m_wndStatusBar.SetPaneInfo (0, nID, nStyle, tm.tmAveCharWidth*50);
m_wndStatusBar.SetPaneInfo (1, nID, nStyle, tm.tmAveCharWidth*50);
m_wndStatusBar.SetPaneInfo (2, nID, nStyle, tm.tmAveCharWidth*40);
m_wndReBar.SetBarStyle(m_wndReBar.GetBarStyle()|CBRS_BORDER_ANY);
LoadProfileSet();
int m_CurSelFolder = AfxGetApp()->GetProfileInt(_T("BarStatus"),_T("CurSelFolder"),1);
m_wndCategoryBar.SetSelFolder(m_CurSelFolder);
m_iCurSel = AfxGetApp()->GetProfileInt(_T("BarStatus"),_T("CurSubCategory"),0);
m_bCategoryBar = AfxGetApp()->GetProfileInt(_T("BarStatus"),_T("CategoryBar"),1);
if(!m_bCategoryBar) m_wndSplitter.HideColumn(0);
HICON hIcon = m_SmallFinance.ExtractIcon(m_wndCategoryBar.GetItemImage(m_iCurSel));
iCurSel = m_wndCategoryBar.GetItemImage(m_iCurSel);
if(!GetContainView()->InitColum(m_wndCategoryBar.GetItemText(m_iCurSel),hIcon))
{
AfxMessageBox(_T("程序初始化失败!"),MB_ICONSTOP);
return -1;
}
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style = WS_OVERLAPPED|WS_CAPTION|WS_THICKFRAME|WS_SYSMENU|
WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_MAXIMIZE;
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
cs.style &= ~FWS_ADDTOTITLE;
CStockReferApp *app = (CStockReferApp *)AfxGetApp();
cs.lpszClass = app->m_singleInstance.GetClassName();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
if (!m_wndSplitter.CreateStatic(this, 1, 2))
{
TRACE0("Failed to create splitter window\n");
return FALSE;
}
if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CContainView),
CSize(0, 0), pContext))
{
TRACE0("Failed to create MainView\n");
return FALSE;
}
if (!CreateCategoryBar())
{
TRACE0("Failed to create category bar.");
return FALSE;
}
return TRUE;
}
void CMainFrame::ActivateFrame(int nCmdShow)
{
// TODO: Add your specialized code here and/or call the base class
if(m_bFirst)
{
m_bFirst = FALSE;
WINDOWPLACEMENT WndStatus;
WndStatus.length = sizeof(WINDOWPLACEMENT);
WndStatus.rcNormalPosition = rcWndPos;
WndStatus.flags = AfxGetApp()->GetProfileInt(_T("Settings"), _T("Flag"),0);
WndStatus.showCmd = nCmdShow = AfxGetApp()->GetProfileInt(_T("Settings"), _T("ShowCmd"),SW_SHOW);
WndStatus.ptMinPosition = CPoint(0,0);
WndStatus.ptMaxPosition = CPoint(-::GetSystemMetrics(SM_CXBORDER), -::GetSystemMetrics(SM_CYBORDER));
SetWindowPlacement(&WndStatus);
}
CFrameWnd::ActivateFrame(nCmdShow);
}
BOOL CMainFrame::CreateCategoryBar()
{
DWORD dwStyle = CCategoryBar::fDragItems | CCategoryBar::fResetItemsPosition;
if (!m_wndCategoryBar.Create(WS_CHILD|WS_VISIBLE, CRect(0,0,0,0),
&m_wndSplitter, m_wndSplitter.IdFromRowCol(0, 0), dwStyle))
return FALSE;
// Tell the control to send message to this window (the mainframe)
// and not to its real parent (the splitter)
m_wndCategoryBar.SetOwner(this);
m_wndCategoryBar.AddFolder(_T("财经资讯"),0);
m_wndCategoryBar.AddFolder(_T("股市资讯"),1);
m_wndCategoryBar.AddFolder(_T("股市纵横"),2);
m_wndCategoryBar.AddFolder(_T("基金投资"),3);
int m_SmallIcon = AfxGetApp()->GetProfileInt(_T("BarStatus"),_T("SmallIconView"),0);
m_wndCategoryBar.SetSmallIconView(m_SmallIcon == 1 ? TRUE : FALSE);
// Here we insert the items; syntax is folder, index, text, image, lParam value for item
if(!InitCategoryBar()) return FALSE;
// Standard sizing for splitter
CRect rcDesk;
SystemParametersInfo(SPI_GETWORKAREA,0,rcDesk,0);
rcWndPos.left = AfxGetApp()->GetProfileInt(_T("Settings"), _T("Left"), 10);
rcWndPos.top = AfxGetApp()->GetProfileInt(_T("Settings"), _T("Top"), 10);
rcWndPos.right = AfxGetApp()->GetProfileInt(_T("Settings"), _T("Right"), rcDesk.Width() - 10);
rcWndPos.bottom = AfxGetApp()->GetProfileInt(_T("Settings"), _T("Bottom"), rcDesk.Height() - 10);
int m_CateBarLength = AfxGetApp()->GetProfileInt(_T("BarStatus"),
_T("CateBarLength"),rcWndPos.right/7);
m_wndSplitter.SetColumnInfo(0,m_CateBarLength,0);
m_wndSplitter.RecalcLayout();
return TRUE;
}
BOOL CMainFrame::InitCategoryBar()
{
// Here we create the imagelists for the control
m_LargeFinance.Create(32, 32, ILC_COLOR24|ILC_MASK, 17, 1);
m_SmallFinance.Create(16, 16, ILC_COLOR24|ILC_MASK, 17, 1);
CBitmap m_DefIcon;
m_DefIcon.LoadBitmap(IDB_STOCK_FINANCE);
m_LargeFinance.Add(&m_DefIcon,RGB(255,0,255));
HICON hIconSmall;
int i;
for(i=0;i<17;i++)
{
hIconSmall = m_LargeFinance.ExtractIcon(i);
m_SmallFinance.Add(hIconSmall);
}
m_wndCategoryBar.SetImageList(&m_LargeFinance, CCategoryBar::fLargeIcon);
m_wndCategoryBar.SetImageList(&m_SmallFinance, CCategoryBar::fSmallIcon);
CString strPos = AfxGetApp()->GetProfileString(_T("BarStatus"),_T("CategoryPosition"));
if(!strPos.IsEmpty())
{
i = strPos.Find(_T(";"));
if(i != -1)
{
strFolderPosOne = strPos.Left(i);
strPos = strPos.Mid(i + 1);
i = strPos.Find(_T(";"));
if(i != -1)
{
strFolderPosTwo = strPos.Left(i);
strFolderPosThree = strPos.Mid(i + 1);
}
}
}
int iFolderPosOne[3],pos;
if(strFolderPosOne.IsEmpty() || _stscanf(strFolderPosOne, _T("%d,%d,%d"),
&iFolderPosOne[0], &iFolderPosOne[1], &iFolderPosOne[2]) != 3)
{
iFolderPosOne[0] = 0;
iFolderPosOne[1] = 1;
iFolderPosOne[2] = 2;
}
for(i=0;i<3;i++)
{
pos = iFolderPosOne[i];
m_wndCategoryBar.InsertItem(0,i,strFolder[pos],pos,0);
}
int iFolderPosTwo[6];
if(strFolderPosTwo.IsEmpty() || _stscanf(strFolderPosTwo, _T("%d,%d,%d,%d,%d,%d"),
&iFolderPosTwo[0], &iFolderPosTwo[1], &iFolderPosTwo[2],
&iFolderPosTwo[3], &iFolderPosTwo[4], &iFolderPosTwo[5]) != 6)
{
iFolderPosTwo[0] = 3;
iFolderPosTwo[1] = 4;
iFolderPosTwo[2] = 5;
iFolderPosTwo[3] = 6;
iFolderPosTwo[4] = 7;
iFolderPosTwo[5] = 8;
}
for(i=0;i<6;i++)
{
pos = iFolderPosTwo[i];
m_wndCategoryBar.InsertItem(1,i,strFolder[pos],pos,0);
}
int iFolderPosThree[7];
if(strFolderPosThree.IsEmpty() || _stscanf(strFolderPosThree, _T("%d,%d,%d,%d,%d,%d,%d"),
&iFolderPosThree[0], &iFolderPosThree[1], &iFolderPosThree[2],
&iFolderPosThree[3], &iFolderPosThree[4], &iFolderPosThree[5],
&iFolderPosThree[6]) != 7)
{
iFolderPosThree[0] = 9;
iFolderPosThree[1] = 10;
iFolderPosThree[2] = 11;
iFolderPosThree[3] = 12;
iFolderPosThree[4] = 13;
iFolderPosThree[5] = 14;
iFolderPosThree[6] = 15;
}
for(i=0;i<7;i++)
{
pos = iFolderPosThree[i];
m_wndCategoryBar.InsertItem(2,i,strFolder[pos],pos,0);
}
m_wndCategoryBar.InsertItem(3,0,strFolder[16],16,0);
return TRUE;
}
BOOL CMainFrame::CreateStanderBar()
{
if (!m_wndToolBar.CreateEx(this,TBSTYLE_FLAT |
TBSTYLE_TRANSPARENT | TBSTYLE_EX_DRAWDDARROWS,
WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP
| CBRS_TOOLTIPS | CBRS_FLYBY)) return FALSE;
m_sizeButton = CSize(20,20);
CImageList imageList;
CBitmap bitmap;
CString str;
// Create and set the normal toolbar image list.
bitmap.LoadBitmap(IDB_COLD_TOOLBAR);
imageList.Create(m_sizeButton.cx, m_sizeButton.cy, ILC_COLORDDB|ILC_MASK, 11, 1);
imageList.Add(&bitmap, RGB(255,0,255));
m_wndToolBar.GetToolBarCtrl().SetImageList(&imageList);
imageList.Detach();
bitmap.Detach();
// Create and set the hot toolbar image list.
bitmap.LoadBitmap(IDB_HOT_TOOLBAR);
imageList.Create(m_sizeButton.cx, m_sizeButton.cy, ILC_COLORDDB|ILC_MASK, 11, 1);
imageList.Add(&bitmap, RGB(255,0,255));
m_wndToolBar.GetToolBarCtrl().SetHotImageList(&imageList);
imageList.Detach();
bitmap.Detach();
m_wndToolBar.SetButtons(NULL, 16);
m_wndToolBar.GetItemRect(0, &m_rSmallBtn);
// set up each toolbar button
str.LoadString(IDS_FILE_EXPORT);
m_wndToolBar.SetButtonInfo(0,ID_FILE_EXPORT,TBSTYLE_BUTTON,0);
m_wndToolBar.SetButtonText(0,str);
str.LoadString(IDS_FILE_PRINT_PREVIEW);
m_wndToolBar.SetButtonInfo(1,ID_FILE_PRINT_PREVIEW,TBSTYLE_BUTTON,1);
m_wndToolBar.SetButtonText(1,str);
str.LoadString(IDS_FILE_PRINT);
m_wndToolBar.SetButtonInfo(2,ID_FILE_PRINT,TBSTYLE_BUTTON,2);
m_wndToolBar.SetButtonText(2,str);
m_wndToolBar.SetButtonInfo(3,0,TBSTYLE_SEP,0);
str.LoadString(IDS_EDIT_COPY);
m_wndToolBar.SetButtonInfo(4,ID_EDIT_COPYS,TBSTYLE_BUTTON,3);
m_wndToolBar.SetButtonText(4,str);
str.LoadString(IDS_EDIT_DELETE);
m_wndToolBar.SetButtonInfo(5,ID_EDIT_DELETE,TBSTYLE_BUTTON,4);
m_wndToolBar.SetButtonText(5,str);
m_wndToolBar.SetButtonInfo(6,0,TBSTYLE_SEP,0);
str.LoadString(IDS_VIEW_LIST);
m_wndToolBar.SetButtonInfo(7,ID_VIEW_LIST,TBSTYLE_BUTTON,5);
m_wndToolBar.SetButtonText(7,str);
str.LoadString(IDS_VIEW_FULLSCREEN);
m_wndToolBar.SetButtonInfo(8,ID_VIEW_FULLSCREEN,TBSTYLE_BUTTON,6);
m_wndToolBar.SetButtonInfo(9,0,TBSTYLE_SEP,0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -