?? demo3dlg.cpp
字號:
// demo3Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "demo3.h"
#include "demo3Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDemo3Dlg dialog
CDemo3Dlg::CDemo3Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CDemo3Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDemo3Dlg)
m_strPass = _T("tiger");
m_strSource = _T("tian");
m_strSql = _T("select * from emp");
m_strUser = _T("scott");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pMapFile = NULL;
}
void CDemo3Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDemo3Dlg)
DDX_Control(pDX, IDC_GRIDMY, m_Grid);
DDX_Text(pDX, IDC_EDITPASS, m_strPass);
DDX_Text(pDX, IDC_EDITSOURCE, m_strSource);
DDX_Text(pDX, IDC_EDITSQL, m_strSql);
DDX_Text(pDX, IDC_EDITUSER, m_strUser);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDemo3Dlg, CDialog)
//{{AFX_MSG_MAP(CDemo3Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTNQUERY, OnBtnquery)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDemo3Dlg message handlers
BOOL CDemo3Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CDemo3Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDemo3Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDemo3Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDemo3Dlg::OnBtnquery()
{
// TODO: Add your control notification handler code here
this->Release();
CString strConn;
UpdateData(TRUE);
BOOL bResult = m_db.ConnectDB(m_strSource, m_strUser, m_strPass);
if(bResult == FALSE)
{
return;
}
m_ImageList.DeleteImageList();
m_ImageList.Create(MAKEINTRESOURCE(IDB_BITMAP1), 16, 1, RGB(255,255,255));
m_Grid.SetImageList(&m_ImageList);
m_Grid.GetDefaultCell(FALSE,TRUE)->SetFormat(DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
m_pMapFile = new CMyODBCDBGridFile(&m_Grid, &m_db, m_strSql, "c:\\csl.txt");
if(m_pMapFile == NULL)
{
m_db.DisConnect();
return;
}
CFont *pFont = m_Grid.GetFont();
if (pFont)
{
LOGFONT lf;
pFont->GetLogFont(&lf);
lf.lfItalic = (BYTE) TRUE;
m_Grid.GetDefaultCell(FALSE, TRUE)->SetFont(&lf);
}
m_pMapFile->InitGrid();
}
void CDemo3Dlg::Release()
{
if(this->m_pMapFile)
{
m_pMapFile->Release();
m_db.DisConnect();
delete m_pMapFile; m_pMapFile = NULL;
}
}
BOOL CDemo3Dlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
// TODO: Add your specialized code here and/or call the base class
if (wParam == (WPARAM)m_Grid.GetDlgCtrlID())
{
*pResult = 1;
GV_DISPINFO *pDispInfo = (GV_DISPINFO*)lParam;
if (GVN_GETDISPINFO == pDispInfo->hdr.code)
{
SetGridItem(pDispInfo);
return TRUE;
}
}
return CDialog::OnNotify(wParam, lParam, pResult);
}
void CDemo3Dlg::SetGridItem(GV_DISPINFO *pDispInfo)
{
m_pMapFile->SetGridText(pDispInfo);
if((pDispInfo->item.col ==0) && (pDispInfo->item.row != 0))
{
pDispInfo->item.iImage = rand()%m_ImageList.GetImageCount();
pDispInfo->item.mask |= (GVIF_IMAGE);
}
if((pDispInfo->item.col == 6) && (atoi(pDispInfo->item.strText) > 2000))
{
COLORREF clr = RGB( 128, 128, 128);
pDispInfo->item.crBkClr = clr; // or - m_Grid.SetItemBkColour(row, col, clr);
pDispInfo->item.crFgClr = RGB(255,0,0); // or - m_Grid.SetItemFgColour(row, col, RGB(255,0,0));
pDispInfo->item.mask |= (GVIF_BKCLR|GVIF_FGCLR);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -