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.
Re: pointer to frame object created by runtime_class
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.
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!
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.
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..
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.
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.
Re: pointer to frame object created by runtime_class
Hello robertzp.
It is indeed a few years (=12 years)
Of course
Originally Posted by robertzp
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.
There are only 10 types of people in the world: Those who understand binary and those who do not.
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.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.