📄 selectorview.cpp.svn-base
字号:
// SelectorView.cpp : implementation of the CSelectorView class
//
#include "stdafx.h"
#include "../StaticDoc.h"
#include "SelectorView.h"
#include "../Dialog/ListExportDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSelectorView
IMPLEMENT_DYNCREATE(CSelectorView, CFormView)
BEGIN_MESSAGE_MAP(CSelectorView, CFormView)
//{{AFX_MSG_MAP(CSelectorView)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_TIMER()
ON_WM_ERASEBKGND()
ON_WM_SIZE()
ON_WM_SETFOCUS()
ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdateFilePrint)
ON_BN_CLICKED(IDC_RUNSELECTOR, OnRunselector)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
ON_MESSAGE(WM_USER_GETVIEWTITLE, OnGetViewTitle)
ON_MESSAGE(WM_USER_GETVIEWCMDID, OnGetViewCmdid)
ON_MESSAGE(WM_USER_CANCLOSEVIEW, OnCanCloseView)
ON_MESSAGE(WM_USER_COLORCHANGE, OnColorChange)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSelectorView construction/destruction
CSelectorView::CSelectorView()
: CFormView(CSelectorView::IDD)
{
m_bShouldUpdate = FALSE;
m_bRunning = FALSE;
}
CSelectorView::~CSelectorView()
{
}
#define SELECTORVIEW_COLUMN_COUNT 6
BOOL CSelectorView::InitializeGrid( )
{
// Create GridCtrl
m_Grid.SetEditable(FALSE);
m_Grid.SetListMode(TRUE);
m_Grid.SetHeaderSort(FALSE);
m_Grid.SetSingleRowSelection(FALSE);
m_Grid.EnableDragAndDrop(TRUE);
m_Grid.SetGridLines( GVL_NONE );
m_Grid.EnableTitleTips( TRUE );
m_Grid.SetRowResize( FALSE );
m_Grid.SetColumnResize( TRUE );
m_Grid.SetBkColor( AfxGetProfile().GetColor(CColorClass::clrSListBK) );
m_Grid.SetTextBkColor( AfxGetProfile().GetColor(CColorClass::clrSListBK) );
m_Grid.SetSelectedBkColor(AfxGetProfile().GetColor(CColorClass::clrSListSelected));
TRY {
m_Grid.SetRowCount(1);
m_Grid.SetColumnCount(SELECTORVIEW_COLUMN_COUNT);
m_Grid.SetFixedRowCount(1);
m_Grid.SetFixedColumnCount(1);
}
CATCH (CMemoryException, e)
{
e->ReportError();
e->Delete();
return FALSE;
}
END_CATCH
for( int nCol=0; nCol<m_Grid.GetColumnCount(); nCol++ )
{
m_Grid.SetItemBkColour( 0, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
m_Grid.SetItemFgColour( 0, nCol, AfxGetProfile().GetColor(CColorClass::clrTitle) );
}
CRect rectGrid;
m_Grid.GetClientRect( &rectGrid );
int nWidth = rectGrid.Width() / m_Grid.GetColumnCount() - 1;
m_Grid.SetColumnWidth( 0, 70 );
m_Grid.SetColumnWidth( 1, nWidth );
m_Grid.SetColumnWidth( 2, 70 );
m_Grid.SetColumnWidth( 3, 70 );
m_Grid.SetColumnWidth( 4, nWidth + 30 );
m_Grid.SetColumnWidth( 5, nWidth + 40 );
// Set Column Header
UINT idsHeader[SELECTORVIEW_COLUMN_COUNT] = {IDS_SELECTORVIEW_CODE, IDS_SELECTORVIEW_NAME,
IDS_SELECTORVIEW_DATE, IDS_SELECTORVIEW_CLOSE, IDS_SELECTORVIEW_SIGNAL,
IDS_SELECTORVIEW_DISCRIPT };
for( int nCol=0; nCol<SELECTORVIEW_COLUMN_COUNT; nCol++ )
{
GV_ITEM item;
item.mask = GVIF_TEXT|GVIF_FORMAT;
item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE;
item.row = 0;
item.col = nCol;
item.szText.LoadString( idsHeader[nCol] );
m_Grid.SetItem(&item);
}
return TRUE;
}
void CSelectorView::SetFont( LPLOGFONT pLogFont )
{
ASSERT( pLogFont );
HFONT hFont = ::CreateFontIndirect(pLogFont);
m_Grid.SendMessage( WM_SETFONT, (WPARAM)hFont, MAKELPARAM(1, 0) );
// m_Grid.AutoSize( );
DeleteObject(hFont);
}
void CSelectorView::GetSelectedStocks( CSPStringArray & astr )
{
int nTotalCount = m_Grid.GetSelectedCount();
astr.RemoveAll();
astr.SetSize( 0, nTotalCount > 10 ? nTotalCount : -1 );
for( int nRow=1; nRow<m_Grid.GetRowCount(); nRow++ )
{
BOOL bSelected = FALSE;
for( int nCol=0; nCol<m_Grid.GetColumnCount(); nCol ++ )
bSelected |= ( m_Grid.GetItemState(nRow,nCol) & GVIS_SELECTED );
if( !bSelected )
continue;
LPARAM id = m_Grid.GetItemData(nRow,0);
CStockInfo & info = m_container.GetStockInfoByID(id);
astr.Add( info.GetStockCode() );
}
}
void CSelectorView::OnDblclkItem( int nStockIndex )
{
if( nStockIndex >= 0 && nStockIndex < m_container.GetSize() )
{
CStockInfo & info = m_container.ElementAt(nStockIndex);
AfxShowStockGraph( info.GetStockCode() );
}
}
/////////////////////////////////////////////////////////////////////////////
// CSelectorView overrides
BOOL CSelectorView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
BOOL CSelectorView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// TODO: Add your specialized code here and/or call the base class
if( ::IsWindow(m_Grid.GetSafeHwnd()) )
if( m_Grid.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
return CFormView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
BOOL CSelectorView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if( m_Grid.GetSafeHwnd() == pMsg->hwnd )
{
if( WM_LBUTTONDBLCLK == pMsg->message
|| ( WM_KEYDOWN == pMsg->message && VK_RETURN == pMsg->wParam ) )
{
int nColumnCount = m_Grid.GetColumnCount();
int nRowCount = m_Grid.GetRowCount();
if( nColumnCount <=0 || nRowCount <= 0 )
return CFormView::PreTranslateMessage(pMsg);
CRect rectCell;
m_Grid.GetCellRect(0,0,&rectCell);
CPoint pt = pMsg->pt;
::ScreenToClient( m_Grid.GetSafeHwnd(), &pt );
if( pt.y >= rectCell.top && pt.y < rectCell.bottom )
return CFormView::PreTranslateMessage(pMsg);
int nSelRow = m_Grid.GetFocusCell().row;
if( nSelRow >= 1 && nSelRow < m_Grid.GetRowCount() )
{
int id = m_Grid.GetItemData(nSelRow,0);
OnDblclkItem( id );
}
}
}
return CFormView::PreTranslateMessage(pMsg);
}
void CSelectorView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSelectorView)
DDX_Control(pDX, IDC_STATIC_INFO, m_staticInfo);
DDX_Control(pDX, IDC_PROGRESS, m_progress);
DDX_Control(pDX, IDC_RUNSELECTOR, m_btnRunSelector);
DDX_Control(pDX, IDC_TECH, m_cmbTech);
DDX_Control(pDX, IDC_KTYPE, m_cmbKType);
DDX_Control(pDX, IDC_STOCKGROUP, m_cmbStockGroup);
//}}AFX_DATA_MAP
DDX_GridControl(pDX, IDC_GRID, m_Grid);
}
void CSelectorView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
InitializeGrid( );
m_staticInfo.SetWindowPos( NULL, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE );
m_progress.SetWindowPos( NULL, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE );
LOGFONT lf;
memset( &lf, 0, sizeof(lf) );
AfxGetProfile().GetFontSListView( &lf );
SetFont( &lf );
m_cmbStockGroup.InitStrings( TRUE, TRUE, AfxGetGroupContainer( ) );
m_cmbStockGroup.SetCurSel( 0 );
m_cmbStockGroup.SelectGroupAll( );
m_cmbKType.InitializeDay( );
m_cmbTech.Initialize();
}
void CSelectorView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
if( UPDATE_HINT_SELECTORVIEW != lHint )
return;
if( IsWindowVisible() )
SetFocus( );
int nColumnCount = m_Grid.GetColumnCount();
if( nColumnCount <= 0 )
return;
if( GetParentFrame()->GetSafeHwnd() != AfxGetMainFrame()->GetActiveFrame()->GetSafeHwnd() )
{
m_bShouldUpdate = TRUE;
return;
}
m_bShouldUpdate = FALSE;
m_Grid.DeleteNonFixedRows();
// Progress
CMainFrame * pMainFrame = AfxGetMainFrame();
if( pMainFrame )
{
pMainFrame->ShowProgressBar( );
pMainFrame->SetProgress( 0 );
pMainFrame->SetMessageText( IDS_MAINFRAME_WAITING );
}
CRect rectClient;
GetClientRect( &rectClient );
int nPageCount = 1 + rectClient.Height() / abs(m_Grid.GetFixedRowHeight()) + 1;
for( int i=0; i<m_container.GetSize() && i<m_signals.GetSize(); i++ )
{
CStockInfo & info = m_container.GetStockInfoByID(i);
int nRow = m_Grid.InsertRow( info.GetStockName() );
m_Grid.SetItemData( nRow, 0, i );
for( int nCol=0; nCol<SELECTORVIEW_COLUMN_COUNT; nCol++ )
{
m_Grid.SetItemFormat( nRow, nCol, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -