|
Technical aspect:
'this' is not passed on the stack. It is passed in the ECX register.
Stephen Kellett
|
|
|
|
|
Actually, it can be passed any way. Just because it currently is in your implementation doesn't mean it always is, or that it cannot be passed any other way.
|
|
|
|
|
I was referring to VC++, I should have said so (I did but the submission was reject, so I was terse the next time).
For those interested, if you are using VC++, search for
naked
in the MSDN docs, you'll find all the register usage notes.
Stephen Kellett
|
|
|
|
|
i would like to know, i got the learn c++ 21 days book, and it teaches me C++, but what about visual C++.
The book teached me dos programming (I think)
not windows as i thought.
I got Microsoft Visual Studio 6.0, to program C++
but i cant figure out: Is C++ the same as Visual C++??
Is it the same, or is it defrents. I want to program Windows
programs not dos.
Any help would be good.. THANKS (I know am dumb)
|
|
|
|
|
Before you learn Windows programming, you should at least becoming passingly familiar with C++, and the easiest way to do that is with console mode programming (what looks like DOS).
Once you are comfortable with C++, then you can move on to the more visual fundamentals.
|
|
|
|
|
First of all let me back up TOTALLY what Eric said. MFC (or even Win32) is an extension to C++, and there is no way any sensible person would attempt to jump in there without first learning C++. It's kinda like learning to dance before you can walk, one is a superset of the other, and while it can be done, the end result is usually a poor C++ programmer.
Having said that, I recommend you buy a book like 'Learn Visual C++ in 21 days' to progress into the world of Windows. I promise you the first time you look at a Doc/View application you'll wonder where everything is and how it all works, but knowing C++ will give you a start in understanding what things do, if not where they should be.
In answer to question two - Visual C++ is a C++ compiler that also compiles ATL COM objects, Win32 and MFC programs ( among others ). It can be used to write (almost) ANSI C++, or, more commonly, to write Win32 or MFC programs.
No, you're not dumb, we all start somewhere and the differences between standard C++ and Windows are not immediately apparent ( that is from the POV of a beginner with a C++ book ). You should buy a book that teachs Visual C++, and I also recommend as a long term reference 'MFC programming with Visual C++ Unleashed' - a rockin' good book. Finally, make sure you get a copy of the MSDN on your computer - an OLD edition should have come with your VC++, but getting it sent every quarter is well worth the cost.
Also, don't hesitate to ask questions in forums like this - you might be surprised to find that people who seem to know more than you could ever hope to actually learned because other people answered THEIR questions once upon a time....
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
Hi Graap... I am from Korea. I've been learning Windows Programming from Jan in this year.
Do You know about C Language...? C++ is an Extention of C Language... So I think you must to study C Language before start to learn C++ & Visual C++'s MFC. But This is a recommended thing.
C++ is an OOP(Object Oriented Programming) Languege. OOP Language is powerfull in the reusable code aspect. You know... Now a days Programs are very large and heavy... If these programs are made of C... Most of Developers say 'Oh GOD!... or What a shame....' C is a procedural Language... So analysis of program source is very difficult. But C++ OOP Language... These codes are very intuitive.
Early days of Windows Programming... C was a major Windows Programming Language. In these days Developers used Windows API(Application Program Interface)Function that built with C. But as days go by... C reached to its limit. So MS made C++ Classes as named of MFC(Microsoft Foundation Class) to take advantage of C++ and support easy way & shortcut of Windows programming. Now a days Most of Windows programmer use MFC. These Classes wrapped a lot of Windows API as its member function. These Classes are not perfect thing. So We use these classes with Visual C++ Compiler. Visual C++ is a Tool to use MFC, not a Language. Common code for Windows programs was written by Visual Studio. So the only thing We have to do is to manipulate MFC classes and add new user defined classes.
I recommend that you first study Windows program Architecture. There are a few Bible About this. Charles petzold's 'Programming Windows" is for API Programmer and Jeff Prosise's 'MFC Windows 98 Programming' is for MFC Programmer. You can gain a lot of thing about Windows programming in these book.
There are not shortcut to be a Windows Programmer.
Good Luck!
-PS-
Do You use the MSN Instance Messenger? My ID is lee_chanwoo@yahoo.co.kr If you have additional question... access me through this messenger or Email. Email address is the same as My MSN ID.
|
|
|
|
|
I used to advocate learning C before C++, but I no longer do so, since there are plenty of good books on C++ that cover the C basics now and it's pretty seldom that most people have to write in C anymore (as opposed to using C in a C++ program which is still quite common).
If you absolutely must write C code sometime in the future, it'll be a lot easier to learn the differences between C++ and C then than to do it now.
|
|
|
|
|
First of all NEVER say the word DUMB to yourself or antone! ;-D
This word is discouraging!
O.K., to the main stuff:
#1, as you say and hear the VISUAL word, it should be clear that you have an interface, that is a GUI or Grphical User Interface. The VISUAL C++ is for a program with GUI like the windows operationg system or if you know about the X Windows/Motif which is a GUI library for the Unix systems!
The C++ itself only is for NON-GUI programs, like the ones for the DOS or even the Unix systems. No graphical user interfaces exist, all are charcter based.
If you want to start with windows C++ with a GUI, you must start learning C++ 1st, then learn MFC. The second is the library for all the windows based GUI components and it makes it very easy to program windows with GUI.
As Christian mentioned, learn C++ with the Visual C++ Console projects which makes a windows with dos shell mode application and no GUI.
To learn windows programming, you should know about Message and Event based programming, which is all what Windows does, in contrast is the Dos.
Good Luck and keep asking QUESTIONS, they SLOVE things!
Never DISCOURAGE yourself, especially in this field!
Cheers
Masoud
|
|
|
|
|
I would really just like to re-enforce a few things that other have said. First off, definitly gain a strong foundation in C++ using console programs first. If you attempt to wander into Win32 GUI programming to quickly you will fall flat. Next I would like to encourage you to do what Lee Chan Woo said, get Petzold's book on the API and Prosise's book about MFC. These are the definitive bibles in their areas. On that same note it would do you good to stay away from in-21 day books. These books only teach you how to use the compiler to write programs and how to write the actual program. you learn about wizards and gimmics, NOT CODE!! The two books mentioned before work to make you understand what is going on in the background so you no exactly what you program is doing and, while more work up front, will give you a better programmig carrer. End result, after all is said and done, you should be able to write an MFC application only using notepad and actual compiler and linker files (the joy of writing your own makefile!)
Good luck to ya.
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."
--anonymous
Joseph Dempsey
dempsey6@home.com
|
|
|
|
|
Given that you've just disagreed with me, allow me to qualify my position. If a person has started with 'C++ for dummies', there is every possibility that they are still an extreme beginner. There is nothing wrong with that, and there is every reason to learn at a pace where you take everything in. I must admit I am only familiar with the C++ in 21 days book, which I regard as a good starter, and is written by Jesse Liberty, who also wrote my fave C++ 'how to' book, C++ Unleashed. I certainly would never hire or hope to work next to someone who considered finishing such a book to qualify them, but that is not really the question, is it ?
I see no reason why someone who doesn't want too steep a learning curve could not use such a book to learn how things sit together, albeit via using wizards for a lot of things, and then go on to the stanadrd references you mention ( FWIW I have Petzold but not Prosise, because Prosise seemed to me to recover stuff I knew and had in other books, and ultimately it's rare I look in a book anyhow, as I have MSDN ) to learn what is going on behind the scenes.
Ultimately one needs to know what is going on behind the scenes, but just because I know how to add a message handler by hand doesn't mean I don't use the Class Wizard, it just means I can add messages that CW does not cover and know how to fix things if CW blows up in my face. In other words, knowing what wizards are there is also important. Indeed, if code reuse is the Holy Grail, then the principle would be not to reinvent the wheel, which is why we have wizards to simplify tedious tasks in the first place ?
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
Has any of you realized about the bug in the method GetSelectedCount() of the MFCGridControl the first time the GVN_SELCHANGED is received. It doesn't return the correct count. Has anybody solved this bug?
Thanks,
Jose.
|
|
|
|
|
MFC doesn't have a grid control. What control are you talking about?
|
|
|
|
|
Methinks he means Chris Maunder's grid control.
--Mike--
http://home.inreach.com/mdunn/
"Would it save you a lot of bother if I just gave up and went mad now?"
-- Arthur Dent
|
|
|
|
|
Hello all...
I'm a newbie struggling with the STL and have a question about how to sort
std::list<CMyBaseClass*> objects. If I call list.sort(),
CMyClass::operator<(const CMyClass &rhs) is never called, so I'm thinking
that the pointers are causing problems. Is there a way I can sort this list
of objects by defining a bool CMyClass::Compare function? Thanks for any
information.
--
________________________
matt weagle
matt_weagle@nospam.hotmail.com
|
|
|
|
|
Kind of.
List has 2 sort functions, not just one. The first sorts the objects by value, meaning that in your example it's just sorting the pointers.
The second takes a template function called greater, which can be used to create a custom sort function by defining your own.
There is also std::sort, which will also work.
|
|
|
|
|
You can try this:
std::list<cmybaseclass*> theList;
bool Less(const CMyBaseClass* pFirst, const CMyBaseClass* pSecond)
{
return (*pFirst < *pSecond);
}
std::sort(theList.begin(), theList.end(), Less);
Michael S. Scherotter
Lead Software Architect
Tartus Development, Inc.
|
|
|
|
|
template<class Pred>
void sort(greater<T> pr);
So you want the predicate reversed, surely?
std::list theList
// function object, a bit more 'STL-style'
class CMyBaseClassGreater {
public:
bool operator()(CMyBaseClass* pFirst, CMyBaseClass* pSecond)
{
return *pFirst > *pSecond;
}
}
theList.sort(CMyBaseClassGreater());
std::sort won't work on a list, as it needs random access iterators, which list doesn't provide. You have to use std::list::sort().
|
|
|
|
|
Thanks for the info. I actually got as far as figuring out the function object, but still couldn't get it to compile. I kept getting C2664 errors, complaining that it couldn't convert the function object to the proper type. Such as:
error C2664: 'void __thiscall std::list<class CMyClass*,class std::allocator<class CMyClass*> >::sort(struct std::greater<class CMyClass *>)' : cannot convert parameter 1 from 'struct ObjectComp' in 'struct std:greater<class CMyClass*>'
From digging through dejanews, I ran across a couple of threads that suggested that SP4 breaks template behavior of list::sort. Basically saying that the code snippet suggested works fine on gcc and Dinkumware's STL etc., but not on MSVC SP4. Is this possible? One day I will grow to like the STL
|
|
|
|
|
Thanks for the suggestion but that is something that I had tried until I realized that you can't use the sort algorithm for a list container. The example you showed only works for random access containers.
Thanks
|
|
|
|
|
You can sort using any predicate function. Here are some examples from code I am working with:
struct greater_magnitude
{
bool operator()(const CTFARect& x, const CTFARect& y) const {
return (fabs(x.Value()) > fabs(y.Value()));
}
};
std::list<CTFARect> m_lstRects;
...
m_lstRects.sort(greater_magnitude());
In your case, you'd define struct my_comparison_predicate with member bool my_comparison_predicate::operator()(const CTFARect *x, const CTFARect * y) const after my example above.
But to use this, you have to fix some bugs in the Microsoft standard C++ library.
Look at Dunkumware's list of bug fixes for the VC++ standard library. Edit the standard library headers in "Program Files\Microsoft Visual Studio\vc98\include" to implement the fixes on the Dinkumware page.
Then, you must edit the file "list" thus to allow the use of predicates:
*** list Tue Jun 27 23:50:23 2000
--- list.original Mon Jun 15 05:00:00 1998
***************
*** 281,288 ****
erase(_F++);
else
++_F; }
!
! template<class _Pr1> void remove_if(_Pr1 _Pr)
{iterator _L = end();
for (iterator _F = begin(); _F != _L; )
if (_Pr(*_F))
--- 281,288 ----
erase(_F++);
else
++_F; }
! typedef binder2nd<not_equal_to<_Ty> > _Pr1;
! void remove_if(_Pr1 _Pr)
{iterator _L = end();
for (iterator _F = begin(); _F != _L; )
if (_Pr(*_F))
***************
*** 297,304 ****
erase(_M);
else
_F = _M; }
!
! template<class _Pr2> void unique(_Pr2 _Pr)
{iterator _F = begin(), _L = end();
if (_F != _L)
for (iterator _M = _F; ++_M != _L; _M = _F)
--- 297,304 ----
erase(_M);
else
_F = _M; }
! typedef not_equal_to<_Ty> _Pr2;
! void unique(_Pr2 _Pr)
{iterator _F = begin(), _L = end();
if (_F != _L)
for (iterator _M = _F; ++_M != _L; _M = _F)
***************
*** 321,328 ****
_Splice(_L1, _X, _F2, _L2);
_Size += _X._Size;
_X._Size = 0; }}
!
! template<class _Pr3> void merge(_Myt& _X, _Pr3 _Pr)
{if (&_X != this)
{iterator _F1 = begin(), _L1 = end();
iterator _F2 = _X.begin(), _L2 = _X.end();
--- 321,328 ----
_Splice(_L1, _X, _F2, _L2);
_Size += _X._Size;
_X._Size = 0; }}
! typedef greater<_Ty> _Pr3;
! void merge(_Myt& _X, _Pr3 _Pr)
{if (&_X != this)
{iterator _F1 = begin(), _L1 = end();
iterator _F2 = _X.begin(), _L2 = _X.end();
***************
*** 349,362 ****
{_A[_I].merge(_X);
_A[_I].swap(_X); }
if (_I == _MAXN)
! _A[_I - 1].merge(_X);
else
{_A[_I].swap(_X);
if (_I == _N)
++_N; }}
while (0 < _N)
merge(_A[--_N]); }}
! template<class _Pr3> void sort(_Pr3 _Pr)
{if (2 <= size())
{const size_t _MAXN = 15;
_Myt _X(allocator), _A[_MAXN + 1];
--- 349,362 ----
{_A[_I].merge(_X);
_A[_I].swap(_X); }
if (_I == _MAXN)
! _A[_I].merge(_X);
else
{_A[_I].swap(_X);
if (_I == _N)
++_N; }}
while (0 < _N)
merge(_A[--_N]); }}
! void sort(_Pr3 _Pr)
{if (2 <= size())
{const size_t _MAXN = 15;
_Myt _X(allocator), _A[_MAXN + 1];
***************
*** 368,374 ****
{_A[_I].merge(_X, _Pr);
_A[_I].swap(_X); }
if (_I == _MAXN)
! _A[_I - 1].merge(_X, _Pr);
else
{_A[_I].swap(_X);
if (_I == _N)
--- 368,374 ----
{_A[_I].merge(_X, _Pr);
_A[_I].swap(_X); }
if (_I == _MAXN)
! _A[_I].merge(_X, _Pr);
else
{_A[_I].swap(_X);
if (_I == _N)
|
|
|
|
|
Hi,
I create a simple MFC App, with a toolbar. After that I try the following code to disable one of the buttons:
CToolBarCtrl &tb = m_wndToolBar.GetToolBarCtrl();
tb.EnableButton(ID_FILE_SAVE, false);
Why is the button not disabled?
If works fine if I try to disable a menuitem, but I cannot figure out how to disable a toolbar button...
I have also tried to send the message directly (TB_ENABLEBUTTON) but that won't work either...
TIA,
- Anders
|
|
|
|
|
MFC uses message maps to enable and disable things. Sounds like you're fighting with MFC over whether it should or shouldn't be neabled.
If there are no handlers for the message, it's automatically disabled. If you do have a handler, then you need to handle the ON_UPDATE_CMD_UI messages and call pCmdUI->Enable(FALSE).
|
|
|
|
|
Thanks a lot, it works
- Anders
|
|
|
|
|
Hi,
I have a CDialog which has a menu. In that menu, I have a popup-menu that contains my last opened files, like the last opened project in the Visual Studio. This works
wonderful when I start my program, but I have a problem with the update on that MRU lis during the run-time. Ususally, the current opened filename is on the top of that list.
When you choose that 3rd file in that list, usually, it will be moved up the the first position. And yes, it does so, the only problem is that the menu-item-text doesn't seems to
get updated with the new name, since I don't get the filename that is written there, I get the last opened file instead. How can I force my program to update the item text of
that menu??????
Thanx,
Grit
|
|
|
|
|