比如我的程序是test,vc自动生成的标题都是"无标题1",“无标题2”等,请问怎么修改这些标题?

解决方案 »

  1.   

    在mdi中,当子窗口没有最大化时,子窗口会有一个标题,我想问的是子窗口的标题如何修改,请大家执教。
      

  2.   

    CMDIFrameWnd *pMDIFrame = (CMDIFrameWnd*)AfxGetMainWnd();
    CFrameWnd *pFrame = pMDIFrame->GetActiveFrame();
    if(pFrame->GetSafeHwnd())
    {
    pFrame->SetWindowText("Hello");
    }最好还处理这个:
    BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs if( !CMDIChildWnd::PreCreateWindow(cs) )
    return FALSE; cs.style &= ~FWS_ADDTOTITLE;  // add this
    return TRUE;
    }
      

  3.   

    修改窗口标题栏    在缺省情况下,窗口标题栏中显示的标题为程序名 + 当前文档的文件名。比如 " MyProgram - 文档 1 . t x t " ,那若要在标题栏显示一个自己定义的字符串,而不是程序名,可以通过在程序里调用 CWnd::SetWindowText() 方法来实现,而如果我们还想要后面的文档名自动显示,这么做就不行了,这时可以用资源编辑器编辑字符串表( StringTable )资源,在 StringTable 中双击 IDR-MAIN-FRAME 项, caption 中显示一字符串 xx\n\yy...... ,将第一个参数修改为用户自己希望见到的主窗口标题即可。    如果你不想让系统自动帮你把文档的文件名添加到标题栏中,需要在 CMainFram 的 PreCreateWindow 函数中删除 FWS_ADDTOTITLE 标志的窗口样式:    cs.style &= ~FWS_ADDTOTITLE ;    这样,程序运行起来,窗口标题就是 "MyProgram" 而没有后面的 "- 文档 1.txt" 这样的字符串了
      

  4.   

    在资源中修改IDR_MAINFRAME 的内容.
      

  5.   

    to 楼上:
        IDR_MAINFRAME 是主窗体的名字吧,这可不是childframe的名字哦~
        同意lovenoend(有容乃大)
      

  6.   

    to  bcpl(Flex'n Relax) 
    我什么时机调用SetWindowText那?我试过这个方法,但是当ChildFrame切换时,系统就恢复它默认的Text形式了。
    to lovenoend(有容乃大)
    对于不同ChildFrame我有不同的字标题,如何针对不同的childFrame设置标题?多谢。
      

  7.   

    void CMDIFrameWnd::OnUpdateFrameTitle(BOOL bAddToTitle)
    {
    if ((GetStyle() & FWS_ADDTOTITLE) == 0)
    return;     // leave it alone!#ifndef _AFX_NO_OLE_SUPPORT
    // allow hook to set the title (used for OLE support)
    if (m_pNotifyHook != NULL && m_pNotifyHook->OnUpdateFrameTitle())
    return;
    #endif CMDIChildWnd* pActiveChild = NULL;
    CDocument* pDocument = GetActiveDocument();
    if (bAddToTitle &&
      (pActiveChild = MDIGetActive()) != NULL &&
      (pActiveChild->GetStyle() & WS_MAXIMIZE) == 0 &&
      (pDocument != NULL ||
       (pDocument = pActiveChild->GetActiveDocument()) != NULL))
    UpdateFrameTitleForDocument(pDocument->GetTitle());
    else
    {
    LPCTSTR lpstrTitle = NULL;
    CString strTitle; if (pActiveChild != NULL)
    {
    strTitle = pActiveChild->GetTitle();
    if (!strTitle.IsEmpty())
    lpstrTitle = strTitle;
    }
    UpdateFrameTitleForDocument(lpstrTitle);
    }
    }
    void CFrameWnd::OnUpdateFrameTitle(BOOL bAddToTitle)
    {
    if ((GetStyle() & FWS_ADDTOTITLE) == 0)
    return;     // leave it alone!#ifndef _AFX_NO_OLE_SUPPORT
    // allow hook to set the title (used for OLE support)
    if (m_pNotifyHook != NULL && m_pNotifyHook->OnUpdateFrameTitle())
    return;
    #endif CDocument* pDocument = GetActiveDocument();
    if (bAddToTitle && pDocument != NULL)
    UpdateFrameTitleForDocument(pDocument->GetTitle());
    else
    UpdateFrameTitleForDocument(NULL);
    }
      

  8.   

    怎么感觉这个问题很简单,但搞得很复杂,大家说得都没错,但又不全,在这里谈一下我的看法:新建/打开一个文档,是由文档模板打开:
    跟到CMultiDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName,
    BOOL bMakeVisible)
    进去后,如果lpszPathName == NULL,那么进入新建文档执行块,这时进入SetDefaultTitle(pDocument),即设置当前文档的默认标题,好让我们看一下怎么设置标题,继续跟,进入GetDocString函数,这个函数就是得到默认文件名了,默认文件名就是String Table中的类似IDR_MAINFRAME的第一个值,再往后面看到没有pDocument->SetTitle(strDocName);太简单了吧!只要打开文档后,我们重新调用文档的SetTitle函数就改变了当前文档所在子框架和主框架的title了,如果想单独修改文档所在子框架的title或主框架mainframe的title,那就得到框架指针调用SetWindowText好了。讲了这么多,不知道对不对,欢迎大家与我交流。