📄 mainfrm.cpp.svn-base
字号:
CMainFrame::CMainFrame()
{
memset(&m_fullScreen, 0, sizeof(m_fullScreen));
m_fullScreen.bFullScreen = FALSE;
::memset(&m_dataFrameWP, 0, sizeof(WINDOWPLACEMENT));
m_dataFrameWP.length = sizeof(WINDOWPLACEMENT);
m_dataFrameWP.showCmd = SW_HIDE;
}
CMainFrame::~CMainFrame()
{
}
#define FRM_SEARCH_WIDTH 180
#define FRM_SEARCH_HEIGHT 22
#define SLB_DATE_WIDTH 135
#define SLB_DATE_HEIGHT 22
BOOL CMainFrame::CreateMainBar()
{
if (!m_wndMainBar.CreateTextToolBar(this, IDW_MAINBAR, IDR_MAINBAR, -1, -1, CTextToolBar::labelBottom))
{
TRACE0("Failed to create mainbar\n");
return FALSE; // fail to create
}
CString strBarTitle;
strBarTitle.LoadString(IDS_TITLE_MAINBAR);
m_wndMainBar.SetWindowText(strBarTitle);
m_wndMainBar.SetButtonDropDown(ID_MAINBAR_SETTING, m_wndMainBar.CommandToIndex(ID_MAINBAR_SETTING), IDR_MENU_MAINBARSETTING);
m_wndMainBar.SetButtonDropDown(ID_MAINBAR_VIEW, m_wndMainBar.CommandToIndex(ID_MAINBAR_VIEW), IDR_MENU_MAINBARVIEW);
m_wndMainBar.SetButtonDropDown(ID_MAINBAR_TECH, m_wndMainBar.CommandToIndex(ID_MAINBAR_TECH), IDR_MENU_MAINBARTECH);
m_wndMainBar.SetButtonDropDown(ID_MAINBAR_PERIOD, m_wndMainBar.CommandToIndex(ID_MAINBAR_PERIOD), IDR_MENU_MAINBARPERIOD);
return TRUE;
}
BOOL CMainFrame::CreateSListBar()
{
if (!m_wndSListBar.CreateTextToolBar(this, IDW_SLISTBAR, IDR_SLISTBAR, -1, -1, CTextToolBar::labelRight))
{
TRACE0("Failed to create slistbar\n");
return FALSE; // fail to create
}
CString strTitle;
strTitle.LoadString(IDS_TITLE_SLISTBAR);
SetWindowText(strTitle);
m_wndSListBar.SetButtonDropDown(ID_SLISTBAR_GROUP, m_wndSListBar.CommandToIndex(ID_SLISTBAR_GROUP), IDR_MENU_SLISTBARGROUP);
m_wndSListBar.SetButtonDropDown(ID_SLISTBAR_DOMAIN, m_wndSListBar.CommandToIndex(ID_SLISTBAR_DOMAIN), IDR_MENU_SLISTBARDOMAIN);
m_wndSListBar.SetButtonDropDown(ID_SLISTBAR_CLASS, m_wndSListBar.CommandToIndex(ID_SLISTBAR_CLASS), IDR_MENU_SLISTBARCLASS);
return TRUE;
}
BOOL CMainFrame::CreateSimuBar()
{
if (!m_wndSimuBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, CRect(0,0,0,0), IDW_SIMUBAR)
|| !m_wndSimuBar.LoadToolBar(IDR_SIMUBAR))
{
TRACE0("Failed to create simubar\n");
return FALSE; // fail to create
}
CString strBarTitle;
strBarTitle.LoadString(IDS_TITLE_SIMUBAR);
m_wndSimuBar.SetWindowText(strBarTitle);
return TRUE;
}
BOOL CMainFrame::CreateStatusBar()
{
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return FALSE; // fail to create
}
if (!m_wndProgressBar.Create(this, IDD_PROGRESS, CBRS_BOTTOM, IDW_PROGRESSBAR))
{
TRACE0("Failed to create progress bar\n");
return FALSE; // fail to create
}
CProgressCtrl* pPrg = (CProgressCtrl*)m_wndProgressBar.GetDlgItem(IDC_PROGRESS);
if (pPrg != NULL)
pPrg->SetRange(0, 100);
HideProgressBar();
// Set Status Bar Styles
UINT nID, nStyle;
int cxWidth;
m_wndStatusBar.GetPaneInfo(1, nID, nStyle, cxWidth);
m_wndStatusBar.SetPaneInfo(1, nID, nStyle, 200);
m_wndStatusBar.GetPaneInfo(2, nID, nStyle, cxWidth);
m_wndStatusBar.SetPaneInfo(2, nID, nStyle, 200);
m_wndStatusBar.GetPaneInfo(3, nID, nStyle, cxWidth);
m_wndStatusBar.SetPaneInfo(3, nID, nStyle, 50);
m_wndStatusBar.GetStatusBarCtrl().SetMinHeight(20);
HICON icon = AfxGetApp()->LoadIcon(IDI_INDICATOR);
m_wndStatusBar.GetStatusBarCtrl().SetIcon(0, icon);
return TRUE;
}
BOOL CMainFrame::CreateWorkspBar()
{
CString strWorkspTitle;
strWorkspTitle.LoadString(IDS_TITLE_WORKSPBAR);
if (!m_wndWorkspBar.Create(strWorkspTitle, WS_CHILD | WS_VISIBLE, this, IDW_WORKSPBAR))
{
TRACE0("Failed to create workspbar\n");
return -1;
}
m_wndWorkspBar.SetFrameWnd(this);
// Add the views to the tab control.
CString strViewTitle;
strViewTitle.LoadString(IDS_TITLE_STRATEGYVIEW);
m_wndWorkspBar.AddView(strViewTitle, RUNTIME_CLASS(CStrategyView));
strViewTitle.LoadString(IDS_TITLE_GROUPVIEW);
m_wndWorkspBar.AddView(strViewTitle, RUNTIME_CLASS(CGroupView));
strViewTitle.LoadString(IDS_TITLE_TECHSVIEW);
m_wndWorkspBar.AddView(strViewTitle, RUNTIME_CLASS(CTechsView));
m_wndWorkspBar.SetTabImageList(IDB_WORKSP_TAB, 16, 1, RGB(0,255,0));
// allow bar to be resized when floating
m_wndWorkspBar.SetBarStyle(m_wndWorkspBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
return TRUE;
}
char szBarSection[] = "StockAnaBar";
char szMainBar[] = "MainBar";
char szSListBar[] = "SListBar";
char szSimuBar[] = "SimuBar";
char szWorkspBar[] = "WorkspBar";
char szViewBar[] = "ViewBar";
char szPeriodBar[] = "PeriodBar";
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// Create ToolBars
if (!CreateMainBar() || !CreateSListBar() || !CreateSimuBar() || !CreateStatusBar() || !CreateWorkspBar())
{
return -1; // failed to create
}
// Name Search ComboBox
if (!m_SearchBox.Create(WS_CHILD | CBS_DROPDOWN | CBS_SORT | CBS_AUTOHSCROLL | WS_VSCROLL | CBS_HASSTRINGS,
CRect(-FRM_SEARCH_WIDTH, -FRM_SEARCH_HEIGHT, 0, 200), this, ID_SLISTBAR_NAME))
{
TRACE0("Failed to create m_SearchBox\n");
return FALSE;
}
m_SearchBox.SetItemHeight(-1, 16);
m_SearchBox.SetAutoHide(TRUE);
SendMessage(WM_USER_UPDATEBARMENU, 0, 0);
// Enable Docking
EnableDocking(CBRS_ALIGN_ANY);
//m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndMainBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndSListBar.EnableDocking(CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM);
m_wndSimuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndWorkspBar.EnableDocking(CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT);
DockControlBar(&m_wndMainBar,AFX_IDW_DOCKBAR_TOP);
DockControlBar(&m_wndSListBar,AFX_IDW_DOCKBAR_TOP);
DockControlBarLeftOf(&m_wndSimuBar,&m_wndSListBar);
DockControlBar(&m_wndWorkspBar, AFX_IDW_DOCKBAR_LEFT);
// Bar State and Window Placement
ShowControlBar(&m_wndMainBar, AfxGetApp()->GetProfileInt(szBarSection,szMainBar,0), FALSE);
ShowControlBar(&m_wndSListBar, AfxGetApp()->GetProfileInt(szBarSection,szSListBar,0), FALSE);
ShowControlBar(&m_wndSimuBar, AfxGetApp()->GetProfileInt(szBarSection,szSimuBar,0), FALSE);
ShowControlBar(&m_wndWorkspBar, AfxGetApp()->GetProfileInt(szBarSection,szWorkspBar,0), FALSE);
// Set Timer
SetTimer(TIMER_TIME, 1000, NULL);
SetTimer(TIMER_STOCKINDEXREFRESH, 5000, NULL);
// Create QuoteTip and AlarmTip
CQuoteTipDlg::GetInstance();
CAlarmTipDlg::GetInstance();
// Notify Icon
NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(nid));
nid.cbSize = sizeof(nid);
nid.hWnd = GetSafeHwnd();
nid.uID = 1;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = WM_USER_NIFMESSAGE;
nid.hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
CString strName = AfxGetStockIndexReportTip();
strncpy(nid.szTip, strName, min(strName.GetLength(),sizeof(nid.szTip)-1));
Shell_NotifyIcon(NIM_ADD, &nid);
// StkReceiver Alarm
AfxGetStkReceiver().AddRcvAlarmWnd(GetSafeHwnd());
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CMDIFrameWnd::PreCreateWindow(cs))
return FALSE;
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
return TRUE;
}
void CMainFrame::ActivateFrame(int nCmdShow)
{
// window placement persistence
if (m_dataFrameWP.showCmd != SW_HIDE)
{
SetWindowPlacement(&m_dataFrameWP);
CFrameWnd::ActivateFrame(m_dataFrameWP.showCmd);
m_dataFrameWP.showCmd = SW_HIDE;
return;
}
CMDIFrameWnd::ActivateFrame(nCmdShow);
}
void CMainFrame::ShowProgressBar()
{
m_wndStatusBar.SetWindowPos(&wndBottom, 0, 0, 0, 0,
SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|
SWP_NOACTIVATE|SWP_HIDEWINDOW);
CRect rect;
GetClientRect(&rect);
CSize size = m_wndProgressBar.CalcFixedLayout(TRUE, TRUE);
rect.top = rect.bottom - size.cy;
m_wndProgressBar.SetWindowPos(&wndTop,//m_wndStatusBar,
rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
SWP_NOACTIVATE|SWP_SHOWWINDOW);
m_wndProgressBar.Invalidate();
MSG msg;
while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE))
{
AfxGetApp()->PumpMessage();
}
}
void CMainFrame::HideProgressBar()
{
m_wndProgressBar.SetWindowPos(&wndBottom, 0, 0, 0, 0,
SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|
SWP_NOACTIVATE|SWP_HIDEWINDOW);
CRect rect;
GetClientRect(&rect);
CSize size = m_wndStatusBar.CalcFixedLayout(TRUE, TRUE);
rect.top = rect.bottom - size.cy;
m_wndStatusBar.SetWindowPos(&wndTop,
rect.left,
rect.top,
rect.Width(),
rect.Height(),
SWP_NOACTIVATE|SWP_SHOWWINDOW);
m_wndStatusBar.Invalidate();
MSG msg;
while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE))
{
AfxGetApp()->PumpMessage();
}
}
void CMainFrame::ShowWorkspBar(BOOL bShow)
{
m_wndWorkspBar.ShowNormal(bShow);
}
void CMainFrame::OnToggleWorkspBar()
{
m_wndWorkspBar.ToggleShow();
}
void CMainFrame::SetStatusMsg(LPCTSTR lpszText)
{
if (m_wndStatusBar.IsWindowVisible())
{
SetMessageText(lpszText);
}
else if (m_wndProgressBar.IsWindowVisible())
{
CWnd *pWnd = m_wndProgressBar.GetDlgItem(IDC_MESSAGE);
if (pWnd)
pWnd->SetWindowText(lpszText);
}
}
void CMainFrame::SetProgress(int nPercent)
{
if (m_wndProgressBar.IsWindowVisible())
{
CProgressCtrl* pPrg = (CProgressCtrl*)m_wndProgressBar.GetDlgItem(IDC_PROGRESS);
if (pPrg != NULL)
pPrg->SetPos(nPercent);
}
else if (m_wndStatusBar.IsWindowVisible())
{
CString string;
int maxcount = nPercent/9;
CString strProgress;
strProgress.LoadString(IDS_MAINFRAME_PROGRESS);
for (int i=0; i<maxcount; i++)
{
string += strProgress;
}
if (100 == nPercent)
string = "";
m_wndStatusBar.SetPaneText(1,string);
}
}
void CMainFrame::DockControlBarLeftOf(CGuiToolBarWnd* Bar,CGuiToolBarWnd* LeftOf)
{
CRect rect;
DWORD dw;
UINT n;
// get MFC to adjust the dimensions of all docked ToolBars
// so that GetWindowRect will be accurate
RecalcLayout();
LeftOf->GetWindowRect(&rect);
rect.OffsetRect(1,0);
dw=LeftOf->GetBarStyle();
n = 0;
n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
// When we take the default parameters on rect, DockControlBar will dock
// each Toolbar on a seperate line. By calculating a rectangle, we in effect
// are simulating a Toolbar being dragged to that location and docked.
DockControlBar(Bar,n,&rect);
}
CPoint CMainFrame::CalcPopupMenuPoint(CToolBar * pBar, UINT nID, CMenu *pMenu)
{
ASSERT(pBar && pBar->IsKindOf(RUNTIME_CLASS(CToolBar)));
// Button rect
CRect rectButton;
pBar->GetToolBarCtrl().GetRect(nID, &rectButton);
pBar->ClientToScreen(&rectButton);
// Screen size
int cyScreen = GetSystemMetrics(SM_CYSCREEN);
// Menu height
int nMenuHeight = cyScreen/4;
if (pMenu)
{
nMenuHeight = 5;
for (UINT i=0; i<pMenu->GetMenuItemCount(); i++)
{
if (ID_SEPARATOR == pMenu->GetMenuItemID(i))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -