Limiting Child Windows

This is a discussion on Limiting Child Windows within the Windows Programming forums, part of the Platform Specific Boards category; Can anyone help me with this? I am working on an MDI app but I want the user to be ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    24

    Limiting Child Windows

    Can anyone help me with this?

    I am working on an MDI app but I want the user to be able to open only 2 documents at a time.

    Second, does anyone know how to select text that has already been displayed in a view so that it can be highlighted or the font changed?

    Thanks for the help

    Tesita Mamacita

  2. #2
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    GetDlgItemText() for getting text, and why not use a global variable counter to limit the amount of windows? have it add one each time a window is opened, then once it's = 2 disable the menu item they're opening the window from or something.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Tesita,

    Do you have menus on the children?

    I am having trouble getting a menu into my MDI child. Have a reg class and the menu in it but no menu will show up.

    In GetMenu() it states that if the window is a child the return is undefined.

    Does this mean you can't have a menu on a MDI child window?

    I use MS VC5/97 with no ++.

    As to your text problem, where is the text? If it is on a HDC you could process the mouse msg's [WM_LBUTTONDOWN, WM_MOUSEMOVE, WM_LBUTTONUP ]. This will tell you where the user has clicked/draged.
    Use PtInRect(), might need ClientToScreen() and MAKEPOINTS()

    If you use ClipCursor() watch it in debug as it can have some funny/frustrating results.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    24

    Highlighting text in the view

    I used the TextOut function of the CDC class to display lines of text in the view. These lines were inputted using a dialog and each new line was placed on a new line in the view also.

    What I now want to do is to be able to click on any line of text in the view and have it highlighted. Given that I can click anywhere in a line how would I be able to have a rectangle defined to represent the line of text.

    Wouldn't I have to have previously stored the CRECT object representing the dimensions of each line of text and if a particular point fell within the CRECT object for the particular line that would be a way of determining which area to highlight.

    I know that I can use the WM_MOUSEDOWN WM_MOUSEUP handlers to retrieve the user's location in the view.

    Am I on the right track? This solution seems a possibility but implementing it is just a little more difficult.

    Thanks for any words of advice

    Tesita

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    You could use MAKEPOINTS() on the location returned from the mouse msg.
    Start at the first line and use GetTextExtentPoint32() to get the text rect. Convert both to screen cood ClientToScreen() and test with PtInRect().

    I'm not sure the GetTextExtentPoint32() will give you exactly what you want, may have to keep adding the y size as you move down the HDC.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    23
    Tesita,

    For your problem of highlighting text, change the base class of your view to CEditView. Its all there.

    Try it...
    If they can, why can't I...

  7. #7
    Registered User
    Join Date
    Nov 2001
    Posts
    24
    -Ken-
    Below is the advice that you gave to me some time ago.

    GetDlgItemText() for getting text, and why not use a global variable counter to limit the amount of windows? have it add one each time a window is opened, then once it's = 2 disable the menu item they're opening the window from or something.

    Where do you suggest that I declare the global variable?
    I have also tried having the global variable incremented in the OnNewDocument() function of my document class but this is not working properly. As for the menu item should I have it disabled in the OnUpdate command handler?

    Please help

    Tesita

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    23
    >>I want the user to be able to open only 2 documents at a time.

    Just do it this way:

    1. In your class CChildFrame, add a private static integer variable just called m_FrameCtr like; static int m_FrameCtr;

    2. In the ChildFrm.cpp file before any function at global space write this code: int CChildFrame::m_FrameCtr=0;

    3. Add an Handler to a virtual function called LoadFrame() and increment the counter there like:
    BOOL CChildFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)
    {
    m_FrameCtr++;
    return CMDIChildWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext);
    }

    4. Add an Handler to a virtual function called DestroyWindow() and decrement the counter there like;
    BOOL CChildFrame:: DestroyWindow()
    {
    m_FrameCtr--;
    return CMDIChildWnd:: DestroyWindow();
    }

    5. Goto resource view and add a handler to an UPDATE_COMMAND_UI of the new menu under CChildFrame class like;
    void CChildFrame::OnUpdateFileNew(CCmdUI* pCmdUI)
    {
    if(m_FrameCtr==2)pCmdUI->Enable(FALSE);
    else pCmdUI->Enable();
    }


    After you implement this the user can no longer open new document more than twice because the menu will become disable.


    Try it...
    If they can, why can't I...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't create child windows
    By OnionKnight in forum Windows Programming
    Replies: 4
    Last Post: 04-10-2011, 05:13 PM
  2. Child windows
    By Gordon in forum Windows Programming
    Replies: 1
    Last Post: 04-25-2008, 01:53 PM
  3. Keeping child windows in their place
    By Smallz in forum Windows Programming
    Replies: 1
    Last Post: 08-27-2006, 07:22 AM
  4. Child Windows and Messages
    By Terrell in forum Windows Programming
    Replies: 10
    Last Post: 09-05-2002, 07:39 AM
  5. child windows
    By face_master in forum Windows Programming
    Replies: 14
    Last Post: 03-01-2002, 07:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21