Im writing a C++ program, and I need to add a member variable to a class. This member variable is an object that takes 2 parameters to it's contructor. How do I declare the variable in the header of my class, and initialize it in the constructor of the class that I am using it in?
ROY! Please don't go!
Student of Computer Science
University of Kansas
When you hit the enter key in VS6 it inserts "\r\n" which drops you down a line. This is normal behavior in windows, however I'm editing C++ files that are being used in unix and the \r is an annoyance there.
My question is, does anyone know how to stop VS from inserting the \r -or- Is there a way to run a small script that would strip this out when you save the file?
I don't believe there is a solution in VC6 except to write a little program. (In fact VC6 will take files that have just LF and convert them automatically to CR/LF. By default, VC7 will preserve the original style.)
If you are working with Unix and Windows at the same time, I recommend you installing Cygwin[^].
One of their utilities is u2d and d2u (Unix to Dos/Dos to Unix), which make the conversion you need.
I know that installing Cygwin just for this is overkill, but I think you should give it a try, since it can really ease when you are working with multiplatform code.
It's not the fall that kills you: it's the sudden stop - Down by Law, Jim Jamursch (1986)
We can override OnOk(), or PreTranslateMessage(), but not SetWIndowText() right? What makes a function overridable? Is it that only event handlers are overridable? I'm reading about the word "virtual" but dont see it in the members of say CWnd...like GetWindowTExt etc. I looked in "Input Message Hanfdlers" which has functions like OnHScroll, OnKeyDOwn etdc which are ones that I've seen overridden yet they dont say "virtual" in the declaration (in MSDN)
short answer: you can override any function, in a derived class. but whether your overridden function is called or not depends on who's calling it, what kind of object the caller think he has and the "virtual" option...
i tried to explain it... but realized that this does a better job:
ns wrote: SO having the keyword "virtual" isnt necessary to make a function overridable it seems.
the virtual option affects who calls your override. if you override a non-virtual function, your function will not be called if the caller thinks he's using a base-class object. ie. if the caller only has a CWnd pointer and calls a non-virtual function on your CMyWnd object, he will end up in the base class function, not your override. the effect of the virtual keyword is to allow callers without knowledge of derived classes to call function in the derived class.
Remember that MFC is a thin wrapper over the Win32 API. MFC's CWnd class provides virtual functions that can be overridden in your derived class, as you already know. Some of these virtual functions are actually callback handlers, such as OnSize(), OnGetMinMaxInfo(), etc. They are what get called when a WM_SIZE, WM_GETMINMAXINFO, etc. message is sent/posted to the window.
Now to the interesting part...
MFC provides a back door to allow you to handler *any* Windows message, not just one that's handled by a provided overridable. This is done by the virtual function OnWndMsg(). You can provide custom handling for WM_SETTEXT here. Just be sure to call the base class method for all other messages, or else you could have some seriously weird windowing behavior on your hands!