编码实现修改应用程序标题

来源:互联网 发布:软件开发专业就业方向 编辑:程序博客网 时间:2024/06/16 05:49

1.问题背景

   使用afxmessagebox弹出信息框,此函数没有设置标题的参数,默认标题为创建的项目名称。

   注:因使用的环境不允许使用messagebox.so....寻找之路。。。


2.初识 m_pszAppName

  MSDN: The application name can come from the parameter passed to the CWinApp constructor, or, if not specified, to the resource string with the ID ofAFX_IDS_APP_TITLE. If the application name is not found in the resource, it comes from the program's .EXE filename.

  根据MSDN的描述,我们只要改掉这个值就可以了,如何修改。

3.实践操作

  我想实现在CDlg_Test.cpp中所有的标题都设为“网络安全”。

  a)构造函数时修改

       //First free the string allocated by MFC at CWinApp startup.
      //The string is allocated before InitInstance is called.

       free((void*)AfxGetApp()->m_pszAppName);

       //Change the name of the application file.
      //The CWinApp destructor will free the memory.

       AfxGetApp()->m_pszAppName = _tcsdup("网络安全");

       ps:此时使用afxmessage(),标题就变为改之后的。

  b)重写DoMessageBox--此种方式笔者没有亲自实验:)

    int CEx0811aApp::DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt) 
    {
          LPCTSTR pOldAppName = m_pszAppName;
          m_pszAppName = "新标题";// 其实afxmessgebox的标题就是这个变量决定的
          int iRet = CWinApp::DoMessageBox(lpszPrompt, nType, nIDPrompt);
          m_pszAppName = pOldAppName ;
          return iRet ;
     }


0 0
原创粉丝点击