|
Vaclav_Sal wrote: If you build a new view class in MFC you end up with missing pieces - no GetDocument is a prime example. Private constructor and destructor other hindrance.
I thought this was the way it's always been.
GetDocument() is already declared/defined in the base class. There's no reason for
your derived class to have another one.
Constructor/destructor are private because views aren't meant to be created
directly.
Welcome to MFC Doc/View If you follow the rules, it works fine.
For custom functionality, study the MFC source code carefully!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Mmm,
"However, after adding the newly created view class in doc/view template it cannot be used until the constructor is made public."
Im not agree with that. I have a multiview project MainView is CScrollView derived and there are 3 SecViews template from CForm derived but I can have up to 49 Views opened at the same time. The constructors of my SecondaryViews are still protected.
For the problem with the GetDocument (), it is easy to implement a trick. I use GetDocument ONLY in my MainView but I can access to the document from ALL the classes I have implemented (more than 50), it doesn't matters if they are View-derived or Object-derived or another parent class.
By printing from secondary views you don't get it easly with the assistant but you can add it manually and works perfectly.
If u need some examples about ask for
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Vaclav_Sal wrote: However, after adding the newly created view class in doc/view template it cannot be used until the constructor is made public.
You never, ever construct views using their constructor.
This is done by the FrameWnd or the SplitterWnd containing it using IMPLEMENT_DYNCREATE .
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Vaclav_Sal wrote: if I add this new class via Gallery
I don't know what you mean by 'Gallery', but normally, views are created by a (class derived from) CFrameWnd or a CSplitterWnd by calling CreateView() . Most often in OnCreateClient().
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
|
I have an application that writes to the registry to start itself on startup, but I need some function to get the application path. Anyone have any ideas?
Thanks in advance.
|
|
|
|
|
|
Great! Thanks a lot for that suggestion. I looked at it on MSDN, and there's only a small problem left. I am using a CString named path to store the path, and so for the buffer I used path.GetBuffer(0) like ::GetModuleFileName(NULL,path.GetBuffer(0),sizeof(path.GetBuffer(0))); . Unfortunately, the path, no matter what my executable is named, is C:\Dstrcore.cpp. Any clue as to what's going on? I suspect that it's something to do with the CString.
Also, is there any other way to get a buffer of modifyable length like the CString method GetBuffer? char* doesn't seem to work for me...I have to initialize it like path=new char [10], but I don't know how many characters the path will be...CString helps by null terminating the string and also by having a buffer of modifyable length...If anyone can figure out how to do this with a char*, I'd be really grateful.
Thanks again.
|
|
|
|
|
|
hxhl95 wrote: ...I used path.GetBuffer(0) like ::GetModuleFileName(NULL,path.GetBuffer(0),sizeof(path.GetBuffer(0)));.
Since GetBuffer() returns a pointer, you are passing 4 as the third argument to GetModuleFileName() . Try:
GetModuleFileName(NULL, path.GetBuffer(MAX_PATH), MAX_PATH);
path.ReleaseBuffer();
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
What's MAX_PATH? Never heard of it before
|
|
|
|
|
hxhl95 wrote: What's MAX_PATH?
See here[^], and also check your Include folder.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
How does a conversion operator works ?
Why it is created with overloading keyword "operator" ?
Why it does not have a return type, while with the "operator" keywork we have to have mention a return type ????
Please, all the gentlemen here, help me, i am trying to hone my C++ programming skills to a good level.
|
|
|
|
|
Zealous_Me wrote: i am trying to hone my C++ programming skills to a good level.
Why do you think forum based messages are an appropriate way to do that?
IMHO you would be better served working some tutorials and/or reading some books.
|
|
|
|
|
Hey if u don't know the answer then don't waste my time, and let somebody with enough knowledge to come up and respond. for your kind information i have read enough of my book ->>BY-> Robert Lafore but I couldn't find an answer thats why I put it here.
|
|
|
|
|
Zealous_Me wrote: i have read enough of my book
Also see Effective C++ series by Scott Meyers
|
|
|
|
|
Thank you for suggesting me good book. I'll definitely consult the book. and I am sorry if my answer was rude to you.
|
|
|
|
|
I looked at some of your old posts and you gave this rude answer before ("don't waste my time"). When you are rude to higher-up members chances are you'll be blacklisted and no one will answer your questions. So good luck on that one.
_____________________________________________
Flea Market! It's just like...it's just like...A MINI-MALL!
|
|
|
|
|
Hey thanks for the suggestion dude !! well, actually i wanna hone my coding skills at a fast rate and I put up a question only when i do not find an answer myself after long hard work. but, after putting the question up here i always look get an answer but in return if I get an answer of "look in some book" or "do some tutorials" then u tell who'll not go mad at such a reply.
I don't wanna waste anyone else's time and also my time, thats why I come up with a question when I have done enough to find an answer with my level of knowledge.
Well, thank you for warning me and I'll be careful to not to react if someone gives me answers that are not at all useful.
|
|
|
|
|
Stop shouting at others until you have read Effective C++ and More Effective C++ by Scot Myers.
"I have read enough of my book" does not sound very promising, though.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Conversion functions provide a way to explicitly convert an object of a type to another type.
Zealous_Me wrote: Why it is created with overloading keyword "operator" ?
Probably because conversions are done using a "casting operator" - parenthesis "()"
Zealous_Me wrote: Why it does not have a return type, while with the "operator" keywork we have to have mention a return type ????
This is a matter of the chosen syntax. Bjarne would know best, but I imagine the syntax is this way to differentiate the
conversion function from a function call operator.
For example, the syntax could have been chosen to be
type operator()
but a function call operator looks like this:
type operator()([optional arguments])
Having the syntax for a conversion function like this:
operator type()
seems more clear to me that it's a "cast operator" to "type".
As led mike suggested, reading is good -Operator Overloading[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: As led mike suggested, reading is good
Apparently my answer was not good
|
|
|
|
|
It wasn't you - apparently "Robert Lafore"'s answers aren't good
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|