?? queryview.cpp
字號:
/////////////////////////////////////////////////////////////////
// //
// QueryView.cpp //
//-------------------------------------------------------------//
// By Eugene Khodakovsky //
// April,2002 //
// Eugene@cpplab.com //
// Last Update: April, 2002 //
/////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Query.h"
#include "QueryDoc.h"
#include "QueryView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CQueryView
IMPLEMENT_DYNCREATE(CQueryView, CFormView)
BEGIN_MESSAGE_MAP(CQueryView, CFormView)
//{{AFX_MSG_MAP(CQueryView)
ON_WM_SIZE()
ON_EN_CHANGE(IDC_EDIT_QUERY, OnChangeEditQuery)
//}}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)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CQueryView construction/destruction
CQueryView::CQueryView()
: CFormView(CQueryView::IDD)
{
//{{AFX_DATA_INIT(CQueryView)
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CQueryView::~CQueryView()
{
}
void CQueryView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CQueryView)
DDX_Control(pDX, IDC_LIST_CTRL, m_listCtrl);
DDX_Control(pDX, IDC_QUERY_CAP, m_wndQueryCap);
DDX_Control(pDX, IDC_EDIT_QUERY, m_wndQueryEdit);
//}}AFX_DATA_MAP
DDX_Text(pDX, IDC_EDIT_QUERY, GetDocument()->m_strQuery);
}
BOOL CQueryView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CQueryView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
if(m_queryFont.CreatePointFont(50,"Courier"))
{
m_listCtrl.SetFont(&m_queryFont);
}
DWORD dwExStyle = LVS_EX_FULLROWSELECT;
m_listCtrl.SetExtendedStyle(dwExStyle);
ResizeParentToFit();
SetSize();
}
void CQueryView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
SetSize();
}
/////////////////////////////////////////////////////////////////////////////
// CQueryView printing
BOOL CQueryView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CQueryView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CQueryView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CQueryView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CQueryView diagnostics
#ifdef _DEBUG
void CQueryView::AssertValid() const
{
CFormView::AssertValid();
}
void CQueryView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CQueryDoc* CQueryView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CQueryDoc)));
return (CQueryDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CQueryView message handlers
void CQueryView::SetSize()
{
if(!::IsWindow(m_listCtrl.GetSafeHwnd()))
return;
const cH = 25, d = 5;
CRect rcClient,rcListCtrl,rcQueryCap,rcQueryEdit;
GetClientRect(rcClient);
rcListCtrl = rcClient;
rcQueryCap = rcClient;
rcQueryEdit = rcClient;
rcQueryCap.DeflateRect(d,d);
rcQueryCap.bottom = rcQueryCap.top + cH;
rcQueryEdit = rcQueryCap;
rcQueryCap.right = rcQueryCap.left + 40;
rcQueryEdit.left = rcQueryCap.right + 2;
rcListCtrl.DeflateRect(d,35,d,d);
rcListCtrl.top = rcQueryEdit.bottom + 4;
m_wndQueryCap.MoveWindow(rcQueryCap);
m_wndQueryEdit.MoveWindow(rcQueryEdit);
m_listCtrl.MoveWindow(rcListCtrl);
}
void CQueryView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
switch (lHint)
{
default:
break;
case HINT_UPDATE_WINDOW: // redraw entire window
Invalidate(FALSE);
break;
case HINT_ON_QUERY_RESULT_READY:
{
ShowQueryResult();
UpdateData(FALSE);
}
case HINT_ON_NODE_SELECTED:
{
// ShowColumns();
UpdateData(FALSE);
}
break;
}
}
void CQueryView::ShowColumns()
{
// Clear List control
m_listCtrl.DeleteAllItems();
while(m_listCtrl.DeleteColumn(0)) {}
CSQLQuery& query = GetDocument()->m_query;
// Show columns
int cols = query.GetColumnsCount();
for( int nCol = 0; nCol < cols; nCol++)
{
CString strColName = query.GetColumnName(nCol);
m_listCtrl.InsertColumn(nCol,strColName,LVCFMT_LEFT,60);
}
}
void CQueryView::ShowQueryResult()
{
LockWindowUpdate();
// Clear List control
m_listCtrl.DeleteAllItems();
while(m_listCtrl.DeleteColumn(0)) {}
CSQLQuery& query = GetDocument()->m_query;
// Show columns
int cols = query.GetColumnsCount();
for( int nCol = 0; nCol < cols; nCol++)
{
CString strColName = query.GetColumnName(nCol);
m_listCtrl.InsertColumn(nCol,strColName,LVCFMT_LEFT,80);
}
// Show data
int nItem = 0;
while(!query.eof())
{
CString str; query > str;
m_listCtrl.InsertItem(nItem,str);
for( int nSubItem = 1; nSubItem < cols; nSubItem++)
{
CString str; query > str;
m_listCtrl.SetItemText(nItem,nSubItem,str);
}
nItem++;
}
UnlockWindowUpdate();
}
void CQueryView::OnChangeEditQuery()
{
UpdateData();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -