CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Window Caption

  1. #1
    Guest

    Window Caption

    hai

    How i can change my window caption in my Mdi Application.......
    Iam using the command
    ::SetWindowText(AfxGetMainWnd()->m_hWnd,"HELLO";

    Problem is the caption is apprearing as HELLO-untitled1
    i don't want that "untitled1" i want simply want HELLO

    pl. suggest me.

    suchitra.




  2. #2
    Join Date
    Apr 1999
    Posts
    306

    Re: Window Caption

    goto the precreatewindow function and put this code:

    cs.style &= ~FWS_ADDTOTITLE;
    cs.lpszName = "My Name";


  3. #3
    Guest

    Re: Window Caption

    hai

    Thankyou for you respons...my problem is single document multipleview...each view i want
    seperate caption......pl. suggest me

    suchitra.




  4. #4
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: Window Caption

    Combine your method with ric's - his suggestion stops the 'Untitled1' from appearing, but in the OnActivateFrame() override for each child frame you can do what you originally said - change the title from there. It should stay as you put it, then.



    --
    Jason Teagle
    [email protected]

  5. #5
    Guest

    Re: Window Caption

    Hai Jason Teagle

    Thank you for your response...as you suggested i tried but iam not getting that One more problem
    is when i uncheck the Option in View->Toolbar My window caption is becoming Empty..can you pl.
    suggest me.

    Suchitra......



  6. #6
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: Window Caption

    For some reason the View menu seems deeply embedded in the MFC framework, so you can't easily get to it. So, to make sure that the frame has a title when you have the View - Toolbar item unchecked, you need to override CMainFrame's OnCommand() method (available in Class Wizard), and add the following code in that override:

    --- CMenu *pMenu, *pSubMenu = NULL ;
    int iState = -1 ;

    // There is no point in letting the framework do its stuff first, because the
    // menu item still won't be checked at this point - it requires idle time to
    // update - so we must check the state BEFORE the toggle.

    if (LOWORD(wParam) == ID_VIEW_TOOLBAR)
    {
    pMenu = GetMenu();
    if (pMenu != NULL)
    // pSubMenu = SubMenuFromID(pMenu, ID_VIEW_TOOLBAR);
    // if (pSubMenu != NULL)
    {
    // iState = pSubMenu->GetMenuState(ID_VIEW_TOOLBAR,
    // MF_BYCOMMAND);
    iState = pMenu->GetMenuState(ID_VIEW_TOOLBAR,
    MF_BYCOMMAND);
    }
    if (iState == -1 || (iState & MF_CHECKED) )
    SetWindowText("Default Title");
    }




    ---

    You'll notice that I commented out some lines. I expected GetMenuState() to only return a valid state if the ID actually existed in that particular menu - so I wrote an elaborate routine to scan submenus to find the ID - but it turns out that it can return the state of the ID no matter how nested it is, as long as it is a unique ID.

    This makes me feel stupid, because yesterday I advised someone that their GetMenuState() wasn't working because they were trying to use the wrong submenu - and I was wrong!

    Anyway, this should solve your problem, although you need to check the View - Toolbar menu state when you change the window title as child frames are activated, otherwise they will change its title regardless of the state of the menu item.



    --
    Jason Teagle
    [email protected]

  7. #7
    Guest

    Re: Window Caption

    hello Jason Teagle ,

    I tried the code which you suggest......the problem is the window caption is apprearing and
    immediately disappearing. waititng for your suggestion

    Suchitra.




  8. #8
    Join Date
    May 1999
    Posts
    38

    Re: Window Caption

    Add this call:

    cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing

    just before the call to ProcessShellCommand in the app's InitInstance.

    HTH
    Pashka


  9. #9
    Join Date
    Apr 1999
    Posts
    68

    Re: Window Caption

    I think I misled you slightly in where to change the main window's title - please remove the code from CChildFrame::OnActivateFrame() and instead, place it in CChildFrame::OnMDIActivate() (add a handler for WM_MDIACTIVATE). You should check to see if the bActivate parameter is TRUE, since you don't want the main window's title changed when a child is becoming inactive.

    Now, once you have done that, let's just go over what you have so far. If I understand it correctly, when you click each child frame you want the main frame's title to show a different caption for each frame, and nothing else. You should have this now, have you? Or is this where the title goes blank immediately?

    Now, can I ask, why did you talk about the View - Toolbar menu option? Are you trying to use this to control the window title in some way (how?), or did you just mean that you happened to choose that menu item and it caused the window title to go blank? Perhaps if you explain exactly how you want the main window title to behave as you open and close child frames, and operate the program, it might make it clearer.


    Rather than keep posting on this thread, why don't you e-mail me ([email protected]) with your answers.


  10. #10
    Join Date
    Aug 1999
    Location
    UK
    Posts
    180

    Getting thru

    This work?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured