按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!
Heighty=15;
·153 ·
…………………………………………………………Page 163……………………………………………………………
Visual C++ 6。0 程序设计从入门到精通
maxHeight=200;
m_str=〃欢迎使用本程序!〃;
TIMER=0;
m_brush。CreateSolidBrush(RGB(180;240;210)); //改变对话框背景
m_brush1。CreateSolidBrush(RGB(255;0;0));
}
void CGundongDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGundongDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGundongDlg; CDialog)
//{{AFX_MSG_MAP(CGundongDlg)
ON_WM_SYSMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_WM_CTLCOLOR()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGundongDlg message handlers
BOOL CGundongDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add 〃About。。。〃 menu item to system menu。
// IDM_ABOUTBOX must be in the system mand range。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX 《 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
·154 ·
…………………………………………………………Page 164……………………………………………………………
第 6 章 文本和字体类
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
TIMER=SetTimer(ID_TIMER1;150;NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CGundongDlg::OnSysmand(UINT nID; LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout。DoModal();
}
else
{
CDialog::OnSysmand(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 CGundongDlg::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);
·155 ·
…………………………………………………………Page 165……………………………………………………………
Visual C++ 6。0 程序设计从入门到精通
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
{
CPaintDC dc(this); // device context for painting
dc。SetTextColor(RGB (180;240;210));
dc。SetBkMode(TRANSPARENT); //设置背景为透明!
CRect rect;
rect。left=150;
rect。right=350;
rect。top=10;
rect。bottom=40;
dc。Rectangle(&rect);
dc。FillRect(▭&m_brush1);
rect。left=10;
rect。right=135;
rect。top=40;
rect。bottom=200;
dc。Rectangle(&rect);
dc。FillRect(▭&m_brush1);
dc。TextOut(WidthX;15;m_str);
dc。TextOut(15;Heighty;m_str);
// CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window。
HCURSOR CGundongDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CGundongDlg::OnTimer(UINT nIDEvent)
{
·156 ·
…………………………………………………………Page 166……………………………………………………………
第 6 章 文本和字体类
// TODO: Add your message handler code here and/or call default
DrawV();
DrawH();
CDialog::OnTimer(nIDEvent);
}
void CGundongDlg::DrawV() //竖直方向滚动函数
{
CRect rect; //每次重画区域大小
rect。left=10;
rect。right=m_str。GetLength()+rect。left+120;
CFont * font=GetFont();
LOGFONT logFont;
font…》GetLogFont(&logFont);
rect。top=Heighty;
rect。bottom=rect。top+logFont。lfHeight+40;
InvalidateRect(&rect);
Heighty+=logFont。lfHeight+18; //每步向下移动距离
if(Heighty》=maxHeight) Heighty=15; // 回到起始位置
UpdateWindow();
}
void CGundongDlg::DrawH() //水平向滚动函数
{
CRect rect; //每次重画区域大小
rect。top=15;
CFont * font=GetFont();
LOGFONT logFont;
font…》GetLogFont(&logFont);
rect。bottom=rect。top+logFont。lfHeight+80;
rect。left=WidthX…m_str。GetLength()…10;
rect。right=rect。left+m_str。GetLength()+150;
InvalidateRect(&rect);
if(WidthX