友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!阅读过程发现任何错误请告诉我们,谢谢!! 报告错误
狗狗书籍 返回本书目录 我的书架 我的书签 TXT全本下载 进入书吧 加入书签

VC语言6.0程序设计从入门到精通-第62章

按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!






X 轴起始坐标为 cx0,如果当前字符串的尺寸信息存储在 size 指向的 SIZE 结构中,则后续文 

本的起始坐标 cx1 为:  



     cx1 = cx0 + size。cx;  



     (2 )确定换行时的文本坐标  

     通过计算当前行文本字符的高度与行间隔之和,即可得到换行时文本的起始坐标,上述 

两个数值可通过获取当前字体的信息得到,如果当前字体的信息存储在                                                           tm  指向的 

TEXTMETRICS 结构中,则换行时 Y 轴上文本的起始坐标 cy 为:  



     cy = tm。tmHeight + tm。tmExternalLeading;  



     3 .文本输出  



     Windows 程序设计时用得最多的文本输出函数便是 Textout,其 API 的函数原型如下:  



     BOOL TextOut(  



         HDC hdc;                      // DC 句柄  



         int nXStart;                  //  起始点 X 坐标  



         int nYStart;                  //起始点 Y 坐标  



         LPCTSTR lpString;    //  输出的字符串  



         int cbString                //  输出的字符串中字符数目  



     );  



     通过调用此函数,可以在指定位置输出文本。  



6。4    字体和文本输出实例  



实例 6…1:字体和文本输出实例。源代码在光盘中“06实例 6…1gundong ”目录下。  



     本节实现了一个动态字幕的例子 。从本例中读者可以学习到动态地改变文本坐标来实现 

实现动态字幕的方法。该示例是基于对话框模式的,通过改变文本的坐标然后进行实时刷新 

                                                    

来显示字幕,屏幕刷新通过定时器来实现 。。 

     本例的部分核心源代码如下。  



     CGundongDlg::CGundongDlg(CWnd* pParent /*=NULL*/)  



          : CDialog(CGundongDlg::IDD; pParent)  



      {  



          //{{AFX_DATA_INIT(CGundongDlg)  



                // NOTE: the ClassWizard will add member initialization here  



          //}}AFX_DATA_INIT  



          // Note that LoadIcon does not require a subsequent DestroyIcon in Win32  



          m_hIcon = AfxGetApp()…》LoadIcon(IDR_MAINFRAME);  



          WidthX=200;  



          minWidth=10;  



          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);  



                                                         
返回目录 上一页 下一页 回到顶部 0 0
未阅读完?加入书签已便下次继续阅读!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!