您现在的位置是: 软件 > 开发者网络 > 程序方舟 > 开发专栏 > Visual C++开发 > 正文
·速成电脑精英(包分配)白领高薪一族从这里开始



-Java套接字编程(下)
-MediaStudio Pro 6.5教程
-三款卸载软件最新试用
-基于Visual C++的Winsock API研究

通过例程分析状态条用法
2001-03-22· ·bull77··yesky

上一页  1 2  


  第三步:

  在这一步,我们实现在状态条实现滚动文字。

  < 1 > 在MainFrm.cpp中,我们可以发现如下的定义

  

  static UINT indicators[] =
   {
    ID_SEPARATOR,
    ID_INDICATOR_CAPS,
    ID_INDICATOR_NUM,
    ID_INDICATOR_SCRL,
   };

  我们将其改为

  static UINT indicators[] =
   {
    ID_SEPARATOR,
    ID_STATUS1,
    ID_STATUS2,
    ID_STATUS3,
    ID_INDICATOR_CAPS,
    ID_INDICATOR_NUM,
    ID_INDICATOR_SCRL,
   };


  <2>在菜单VIEW中选择Resource Symbols , 在对话框中选择NEW, 在NAME中输入ID_STATUS1,VALUE中取默认值,同样方法定义ID_STATUS2,ID_STATUS3。

  <3>定义字符串资源,在ResouceView中选择String Table,在其中为ID_STATUS1定义字符串资源为"me",同样方法定义ID_STATUS2,ID_STATUS3。

  <4>在MainFrm.h中定义如下变量:

  public:

   CString str,str1;

  <5>在MainFrm.cpp中修改OnCreate函数如下:

  int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
   {
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
     return -1;
    if(!m_wndStatusBar.Create    (this,WS_CHILD|WS_VISIBLE|CBRS_TOP,AFX_IDW_STATUS_BAR) ||     !m_wndStatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT)))
    {
     TRACE0("Failed to create status bar\n");
      return -1; // fail to create
     }
    m_wndStatusBar.SetPaneInfo(1,ID_STATUS1,SBPS_POPOUT,320);
    m_wndStatusBar.SetPaneInfo(2,ID_STATUS2,SBPS_POPOUT,100);
    m_wndStatusBar.SetPaneInfo(3,ID_STATUS3,SBPS_POPOUT,100);
    str1=str="你好,欢迎使用本程序,祝你合家幸福,事业有成!";
    SetTimer(1,200,NULL);
    SetTimer(2,10,NULL);
    return 0;
   }

  <6>在类CmainFrame中重载函数OnTimer(),并添加如下代码:

  void CMainFrame::OnTimer(UINT nIDEvent)
   {
    file:// TODO: Add your message handler code here and/or call default
    if(nIDEvent==1){
     if(str.IsEmpty()) str=str1;
      str=str.Right(str.GetLength()-2);
      m_wndStatusBar.SetPaneText(1,str);
    }
    if(nIDEvent==2){
     SYSTEMTIME t;
     ::GetLocalTime(&t);
     CString str2;
     str2.Format("%d:%d:%d:%d",t.wHour,t.wMinute,t.wSecond,t.wMilliseconds);
     m_wndStatusBar.SetPaneText(3,str2);
   }
   CFrameWnd::OnTimer(nIDEvent);
  }

  <7>将MainFrm.h中,定义m_wndStatusBar之前的 protected: 改为public:

  <8>通过类向导在类CmystatusView中重载WM_MOUSEMOVE,并在实现函数中添加如下代码:

  void CMystatusView::OnMouseMove(UINT nFlags, CPoint point)
  {
   // TODO: Add your message handler code here and/or call default
   CString str3;
   str3.Format("X:%d,Y:%d",point.x,point.y);
   ((CMainFrame*)AfxGetMainWnd())->m_wndStatusBar.SetPaneText(2,str3);
    CView::OnMouseMove(nFlags, point);
  }

好了,到这里我们所有的功能就都实现了,快编译运行一下吧!怎么样?还满意吗?

上一页  1 2  

■ 相关内容
 标题栏上添加按钮
 用渐变色填充背景
 用JavaMail写简易电子邮件发送系统
 深入研究Application和Session对象
 Flash5 ActionScript 应用教程
 快速精通FRAME(下)
感谢 访问天极网,如果您觉得该文章涉及版权问题,请看这里!