CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: pointer to frame object created by runtime_class

  1. #1
    Join Date
    Apr 2002
    Posts
    124

    pointer to frame object created by runtime_class

    Hello,

    My MDI application has a multidocument template with a NULL view. The template is created as follows:

    CMultiDocTemplate* pMyDocTemplate;
    pMyDocTemplate = (new CMultiDocTemplate (
    IDR_MAINFRAME,
    RUNTIME_CLASS(MyDoc), // document class
    RUNTIME_CLASS(MyWnd), // frame window class
    NULL)); // null view class

    AddDocTemplate(pMyDocTemplate);

    pMyDocTemplate->OpenDocumentFile(NULL);


    The above code works and the frame is created successfully.

    My question is how do I create a pointer to MyWnd? Sample code will be appreciated.

    Thanks...

  2. #2
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: pointer to frame object created by runtime_class

    MFC would create the frame internally. Any reason why you want to create the frame yourself ?

  3. #3
    Join Date
    Apr 2002
    Posts
    124

    Re: pointer to frame object created by runtime_class

    Hi Kirants,

    Yes, I know MFC creates the frame automatically and in fact it does it successfully in the app and I certainly don't want to create it myself.

    The frame contains several controls, a CListBox and a CDirTreeCtrl, and I need a pointer to the frame so that I can retrieve selected items and counts from these boxes from the IDR_MAINFRAME menu.

    For example if I had a pointer m_pMyWnd to the frame, I could access the listbox selected count using the following statement:

    int nSelCount = m_pMyWnd->listbox.GetSelCount();

    I have search codeguru and found many sample codes for pointers to views using the IsKindOf function but I could not find anything for the frame.

  4. #4
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: pointer to frame object created by runtime_class

    Is this what you are looking for ?

    http://www.codeguru.com/forum/showth...hreadid=281430

  5. #5
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,917

    Re: pointer to frame object created by runtime_class

    Quote Originally Posted by robertpantangco
    The frame contains several controls, a CListBox and a CDirTreeCtrl, and I need a pointer to the frame so that I can retrieve selected items and counts from these boxes from the IDR_MAINFRAME menu.
    Why do you create controls in a frame?
    Is using CFormView derived class as view a problem?
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  6. #6
    Join Date
    Apr 2002
    Posts
    124

    Re: pointer to frame object created by runtime_class

    Hi Kirants,
    Excellent link.

    However when I tried the following in the main app:

    MyWnd* m_pMyWnd;

    m_pMyWnd = AfxGetMainWnd()->MDIGetActive();

    I get a compile error:

    error C2039: 'MDIGetActive' : is not a member of 'CWnd'

    I also tried:

    m_pMyWnd = AfxGetMainWnd()->GetActiveFrame();

    and got the same compile error.

    Any suggestions?

  7. #7
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,917

    Re: pointer to frame object created by runtime_class

    MyWnd* m_pMyWnd;

    m_pMyWnd = (MyWnd*)((CMDIFrameWnd*)AfxGetMainWnd())->MDIGetActive();

    Again:

    Quote Originally Posted by me earlier
    Why do you create controls in a frame?
    Is using CFormView derived class as view a problem?
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  8. #8
    Join Date
    Apr 2002
    Posts
    124

    Re: pointer to frame object created by runtime_class

    Dear John,

    Your code works! THANK YOU VERY MUCH!

    To answer your question about why I am not using CFormView:

    -first of all, I am not familiar with it
    -by placing controls in the frame, I felt like I have more control about where the controls are placed and sized.
    -maybe when I get more proficient in MFC, I will take you up on your suggestion but right now, the app works and I am quite happy!

    Thanks again...

  9. #9
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,917

    Re: pointer to frame object created by runtime_class

    CFormView is just dialog that behaves as view. It is much easier to maintain controls in a dialog (form view). You can use class wizard to insert message handlers for controls, just like in a dialog.

    CMDIChild frame was designed to host views.

    Also placing controls just by editing dialog template that form view uses is much easier than creating all dynamically. Changing styles of controls is just clicking on properties dialog in resource editor.

    You can easily subclass each control by simply using wizard and inserting variable of the control type (class).

    When you do it in a frame, you do not have these advantages.
    In addition you do not utilize document without view therefore it is unnecessary baggage in your scenario.

    It is really easy to create application that has CFormView derived view. When creating application press next to go to step 6 and choose CFormView as base class for a view.

    Of course you have the lat word - this id your application.
    I just think that if you learn it is better to use framework to do all possible work according to MEMC (Minimum Coding Maximum Result).
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  10. #10
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: pointer to frame object created by runtime_class

    yup.. If you aren't familiar, this is a good start . Look at it that way.. and you'll wonder why you didn't think of using formview in the first place..

  11. #11
    Join Date
    Apr 2002
    Posts
    124

    Re: pointer to frame object created by runtime_class

    Kirants,
    My thinking when I designed this application was influenced to a great degree by my need to communicate directly with the IDR_MAINFRAME menu which I have customized separately from my other multidoctemplate which does the real document/view processing.

    I am using this controls frame (if you might call it that) to influence what documents get processed and viewed including batch processing of selected files.

    I would rather implement something that I can understand before moving on to a more elegant approach.

  12. #12
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: pointer to frame object created by runtime_class

    I understand what you say. It IS difficult to try hundreds of new things at the same time , especially when it comes to MFC.

    Anyways, I was just suggesting it with good intentions. Whether you can do it or not is very much dependent on your own comfort level and how you have planned things for yourself.

    Wish you good luck..

  13. #13
    Join Date
    Jul 2016
    Posts
    35

    Re: pointer to frame object created by runtime_class

    Hello JohnCz,

    This reply is a few years late but I finally bit the bullet and am trying to implement CFormView to hold my controls.

    In my original code, I can size the initial size of the frame and I had complete control of the creation and the sizing and position of the controls.

    In CFormView, I have difficulty sizing and positioning the controls in the view using OnSize when it initially displays on the screen.


    According to MFC, you can size the controls before the View's OnInitialUpdate but you have to make sure the controls have already been created.

    Does CFormView create the controls automatically?

    If not, how do you create the controls on the formview?

    Kindly explain how to do this.

    I am also assuming that after controls are created, you can send a WM_SIZE to the view which will do the MoveWindow for each of your controls.

    Thanks

  14. #14
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,917

    Re: pointer to frame object created by runtime_class

    Hello robertzp.
    It is indeed a few years (=12 years)
    Of course
    Quote Originally Posted by robertzp View Post
    you can size the controls before View's OnInitialUpdate but you have to make sure the controls have already been created.
    But why? Before OnInitialUpdate controls are created but they are not subclasses yet.
    Main window is not shown (or is not supposed to), but after OnInitialUpdate is called as a result to the WM_INITIALUPDATE message from the frame window.
    I wrote a sample app without doc support, as this is a form view app and most of the time doc support is an overkill.
    You can also write own class to handle resizing or find one that already exists. It is rather hard to write such a class, since you have to know how to resize controls and how resizing affects another controls.
    I know that attempts were made, I do not know how they work since I have never used any.
    By the way, attached is VS 2010 solution.
    Attached Files Attached Files
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  15. #15
    Join Date
    Jul 2016
    Posts
    35

    Re: pointer to frame object created by runtime_class

    John,

    Thank you for the demo resize project. I have applied some of the concepts, it works great, and they can be used as a starting point for more complicated sizing and placement of controls in formview.

    Since my application has many childwindows, I implemented this formview using document/frame/view framework. My controls are now resized horizontally as the frame is sized.

    I do have some questions. It appears that RepositionControls will execute only after the frame containing the view is activated. Prior to frame activation, the client rectangle is empty.

    Is there any way the controls can be sized and placed prior to frame activation.

    My next question is I would like to be able to resize the controls proportionally when the mainframe window is resized.

    How can I send a message from the mainframe window to the MDIChildWnd of the view frame so that the OnSize function of the view is invoked?

    If I can do this, I can code RepositionControls to do the proportional sizing of the controls.

    You demo project is very helpful for programmers working with CFormView.

    Thanks again.

Page 1 of 2 12 LastLast

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)