Thread: Access Function in Child Window From Parent Window

  1. #1
    Registered User Welder's Avatar
    Join Date
    Oct 2007

    Access Function in Child Window From Parent Window

    I have a SDI application where my Child is a Listview control. How do I access the listview class from the parent window class? I have tried everything. Messages didn't work, but I may have been doing it wrong.

    I am using MFC, VS2008 Pro. And if this helps, here is an example of what I am working with. If you have the new MFC feature pack, create a new project with the Visual Studio interface style, menu bar (not ribbons), single document (sdi), navigation (outlook bar), and the main document is a listview.

    What I am trying to do is have a user select a folder in the CMFCShellTreeCtrl (which is part of the parent window/class), then click a button or select a menu item, and call Cmylistview::foo() which is the child.

    Please don't flame, I have looked up and down google and have not found anything that answers this question. I am guessing it is a trickier process than simply sending a message which is why I couldn't find an answer.


  2. #2
    Join Date
    Jan 2002
    I'm not sure if an mfc wrapper exists for EnumChildWindows but that api function and the corresponding EnumChildProc should provide what you need.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User Welder's Avatar
    Join Date
    Oct 2007
    Thank you Ken for replying.

    As for the rest of you ladies who didn't bother to chime in, I found the answer...And it was a DAMN easy one. Well, not for a MFC newb like myself.

    CIMGOPTView is my main view in my SDI. wndTree is my Shell Tree Control. ScanRemote() is a function in my view class.

    HTREEITEM filehnd = m_wndTree.GetSelectedItem();
    CString str;
    m_wndTree.GetItemPath(str, filehnd);
    CIMGOPTView * view = (CIMGOPTView *)GetActiveView();
    if(view == NULL)

    I tried everything from:

    CIMGOPTView* i = dynamic_cast<CIMGOPTView*>( this );


    SendMessage(ID_STARTSCAN,0,(LPARAM)str.GetBuffer(s tr.GetLength()));

    And even shared variables between classes. And all it took was a simple bit of code that any experienced MFC programmer should be familiar with.

    Sorry if I am coming off sounding like a dick, but I don't have many hairs left on my head after this one troubleshoot. Do a search and tell me if you come up with this answer. I had to dig through source code examples all day to find this.

  4. #4
    Join Date
    Oct 2007
    Inside my computer
    I never really use SDI/MDI so I wouldn't know. Kind of depends on what type or projects you do.
    The only thing I can say from experience is that you can use generic methods to find your child (ie, FindWindow, EnumChildWindows), then construct the appropriate class object and call attach. But this is with dialogs. I have no idea if it works with SDI/MDI.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. parent window minimizing on child window destruction
    By Yarin in forum Windows Programming
    Replies: 1
    Last Post: 03-02-2008, 09:34 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  4. Parent not repainting Bitmp after child window closes
    By CodeX in forum Windows Programming
    Replies: 5
    Last Post: 10-05-2006, 12:03 AM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM