#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Phoenix, AZ
    Posts
    484
    Rep Power
    36

    Learning to create windows manually in VC++


    I've been kinda thrown to the wolves at work and am needing to learn VC++. My background is in Pascal, early Delphi, but I'm currently mostly Visual Basic and Perl.

    I'm having to update/modify a program that uses MFC only for some interface screens but were implemented by hand and not by using the class wizard. I need to learn how to do the same thing so I can add some more interfaces.

    I've been looking through "Beginning Visual D++" and "Teach Yourself Visual C++" but they do everything through the class wizard. Any thoughts on where to look or what books would help me out with this?
    There are only 10 kinds of people in this world. Those who understand binary, and those who don't!
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,251
    Rep Power
    2222
    We also have some hybrid Windows apps here, so I can sympathize.

    First, I hope you already have a background in C/C++. The hardest time I had when I transitioned from Pascal to C was in figuring out character strings. At least you should already be familiar with most of the object-oriented concepts from Delphi.

    Second, it's not clear to what extent the app you need to maintain uses MFC. Does it have message maps to route the events to the event handlers or does it have a WndProc that handles the messages with a giant switch statement?

    Of course VC++ books will emphasize using the Class Wizard. That's the VC++ approach. But the good news is that VC++ is not like VB; you can still go in and work directly with the code bypassing the development tools. The main thing that I find the Class Wizard does for me is to generate the right event handler parameters and to tie dialog controls to member variables for automatically initializing and reading the control values. But I can still write that myself, so the Class Wizard is not essential, though it does make life a bit easier.

    A book that might help you in this respect is Jeff Prosise's "Programming Windows with MFC". It shows you how to use the MFC classes without using the VC++ approach.

    Now, if the app is structured around a WndProc and its giant switch statement instead of using the CWinApp class and message maps, then you will need to understand Windows API programming. Charles Petzold's "Programming Windows 95" (or later) should help you there. Especially if the dialog controls are being handled with GetDlgItem(RESOURCEID), etc.

    EDIT:
    Apparently Prosise's book changed a bit with the second edition. Here is a recommendation I just read from a user review of the book on Amazon.com:
    I just resently bought Herbert Schildt's "MFC programming from the ground up". This book seems to be the only truely wizard free MFC programming book on the market. The examples are hand coded and start forward. The beginner programmer would probably be better off, reading Schildt before going to Prosise.
    Last edited by dwise1_aol; May 9th, 2003 at 08:16 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Phoenix, AZ
    Posts
    484
    Rep Power
    36
    dwise1_aol,

    Hey thanks a million on book recommendations. I'll try to pick up the Prosise book today if I can find it. I should be able to bypass the beginners stuff since I have a good background otherwise.

    Though I have no background in C/C++, you're right, I do have an understanding of OO through Delphi and even perl (though perl doesn't do it fully yet).

    The methods I need to learn are the newer way using message maps. But you are right on target that I want to learn to do it without the wizard. I just need to learn what is needed and where. I've been looking through the current code and just to bring up a window from a menu option, has bits of code all over the place and it's hard to discern the pieces that need to be there.

    I'll look for Schildt's book too. Have you run across any non-wizard type tutorials out on the net?

    Thanks for the concise and insightful response. I'm off to Barnes and Nobles....:D

    Joel
    There are only 10 kinds of people in this world. Those who understand binary, and those who don't!
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,251
    Rep Power
    2222
    Originally posted by noslenj123
    Though I have no background in C/C++, you're right, I do have an understanding of OO through Delphi and even perl (though perl doesn't do it fully yet).
    While C syntax is generally comparable to that of Pascal, there are differences that can drive you crazy at first.

    First, C/C++ is case-sensitive, so sMyString is different from smyString is different from smystring is different from SmyString, etc. But then you also have that in Perl. I just generally copy&paste variable and class names as much as I can.

    Second, C uses pointers a lot more than Pascal does. In C, you don't really have call-by-name/call-by-value; it's all call-by-value and if you want the same effect at call-by-name, then you use a pointer. In C++, you won't have to worry about that as much because you can declare a function argument to be a reference, whereupon it's just like call-by-name in Pascal. But still, be prepared to decipher pointer notation in existing code. At least the pointer reference and dereference syntax in C/C++ is much simpler than in Perl.

    Third, string operations are almost completely different than in Pascal. However, most MFC programs use the CString class, which simplifies this area a lot.

    I'll have to get back to you later with a URL for a C tutorial.

    Originally posted by noslenj123
    The methods I need to learn are the newer way using message maps. But you are right on target that I want to learn to do it without the wizard. I just need to learn what is needed and where. I've been looking through the current code and just to bring up a window from a menu option, has bits of code all over the place and it's hard to discern the pieces that need to be there.
    We had gone through some of that in class, so I don't know of a book to refer you to. Prosise or Schildt might discuss it.

    However, you could always reverse-engineer it. Create a test app with the Wizard. When you see the app you're maintaining do something, like pass values into and out of a dialog box, or you need to add something, like an event handler for, say, MouseMove, then add that to your test app and see what the Wizard generates.

    That should help fill the gap until you find a good reference, plus it will offer you an approach to take when the reference doesn't cover your specific problem.

    Originally posted by noslenj123
    I'll look for Schildt's book too. Have you run across any non-wizard type tutorials out on the net?
    Well, my problem is that I'm beyond that point, so I'm not familiar with the beginner materials. When I encounter a problem, I work through it using my current understanding and the help files. Then I Google for that particular problem or class of problems.

    I had a language professor who maintained that beginners need to be taught by someone who remembered being a beginner. In my case, I was a beginner before the resources of the Web were available to me, so in effect I do not remember being a beginner. FWIW, I do Windows apps so occasionally that I'm not an expert either. I just kind of go in and do what I can and need to.

    EDIT:
    In the back of an earlier edition of our textbook, Kruglinski's "Inside Visual C++", Appendix A is "Message Map FUnctions in the MFC Library". It lists map entries and their corresponding function prototypes.

    BTW, in your reverse-engineering efforts, be sure to look in both the code and the class declarations (ie, in both the .CPP and .H files) for code inserted by the wizards.
    Last edited by dwise1_aol; May 10th, 2003 at 02:52 PM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Phoenix, AZ
    Posts
    484
    Rep Power
    36
    I picked up Schildt's book and though I've only read a few chapters, it is clearing things up nicely so far. The great thing is that it doesn't use app/class wizards so you learn it all by hand, which is what I wanted. Thanks for the advise on that one! ;)

    I'll try to pick up Prosise's book too. I think between those two books and reverse engineering as you suggested, I should have no problems mangling the code soon enough......lol

    Thanks again! Your answers are well thought out and very helpful. You just have to love this open community stuff. I give back in my way in the perl groups.....

    If this were a point system forum, you'd get top rating!!!

    :p
    There are only 10 kinds of people in this world. Those who understand binary, and those who don't!
  10. #6
  11. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,251
    Rep Power
    2222
    You're welcome, but a good part of it is enlightened self-interest. I've been learning a lot myself, especially when I help others solve their problems.

IMN logo majestic logo threadwatch logo seochat tools logo