Learning

导航

VC中获得当前运行的全局应用对象APP的方法

 ////////////////////////正确获得APP指针

(1)规范写法

    CViewInDlgApp *m_App= ( CViewInDlgApp*)AfxGetApp();//CViewInDlgApp是工程中App类
    m_App->str1="test";//使用App中已定义的字符串变量
    AfxMessageBox(m_App->str1);
   ////////////////////////正确获得APP指针
 (2) 简写

  (( CViewInDlgApp*)AfxGetApp())->str1="test";//使用App中已定义的字符串变量
   AfxMessageBox((( CViewInDlgApp*)AfxGetApp())->str1);

posted on 2011-07-06 10:36  xinjie  阅读(283)  评论(0编辑  收藏  举报