home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 26
/
CD_ASCQ_26_1295.iso
/
vrac
/
mfcfaq12.zip
/
MFCFAQ12.TXT
< prev
Wrap
Text File
|
1995-08-03
|
164KB
|
3,996 lines
Microsoft Foundation Classes (MFC)
Frequently Asked Questions
Scot Wingo (scot_wingo@msn.com)
Version 1.2
Last updated: 7/29/95
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*Version 1.2 Note*
Welcome to version 1.2 of the world famous MFC FAQ! This version has
lots of new material. Some of my favs->
2.4.2 - Lots of new book reviews
2.4.3 - Cool MFC articles
6.6 - Windows Common Controls - a HOT topic on Usenet/Cserve
11.17 - Learn MFC today, or some suggestions on how to. (good mfc-l thread)
Finally, I'm starting a fancy new "Instant-FAQ (TM)" service, where I
keep a list of email addresses and when a new version of the FAQ is
ready, it is automatically blasted out to you via email. This way you
won't have to search for announcements of the new FAQ, they will be
mailed to you before the rest of the world gets them!
To participate in the "Instant-FAQ (TM)" program for the next release,
just send your email to me at: scot_wingo@msn.com and I'll add you for
free. We at MFC FAQ headquarters aim to please!! (In other words,
it's like a free MFC FAQ subscription, this is NOT a mailing list or
listserver.)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Copyright
---------
This document is compilation Copyright (c) 1995 by Scot Wingo. It
may be freely copied and/or distributed in its entirety as long as this
copyright notice is not removed. It may not be sold for profit or
incorporated into commercial products without the author's written
permission. [Compilation copyright means that you can freely use
individual sections of this document, but any significant collection of
sections is subject to the copyright. Hey, I may want to turn this
into a book or a movie some day!]
This FAQ is in no way connected with Microsoft. It contains some
answers to frequently asked questions about their products. The
author in no way guarantees that any of these answers are correct.
This is just a collection of information posted to public on-line
forums to help the average MFC programmer. [In other words, please
don't sue me. ]
[Note: If you are not using a fixed font, the tables and other
formatting of this FAQ will not look correct. Courier 12 works well
for me.]
Table of Contents
=================
Key:
% - Indicates serious revision since version 1.1
* - Indicates something entirely new and exciting since version 1.1
1. MFC FAQ Info and Credits
1.1. How do I get this FAQ?
- "Instant-FAQ (TM)"
1.2. What's the goal of this FAQ?
1.3. Why are you doing this?
1.4. How can I contribute!?!
1.5. Credits
1.6. How is this different than the MSVC MFC FAQ?
1.7. What other languages is this FAQ translated to?
1.7.1. Japanese version of MFC FAQ
2. Where to go for Juicy MFC Information
2.1. Microsoft
2.1.1. MSVC and MSVC Subscription
%2.1.2. Microsoft Developers Network (MSDN)
%2.1.3. Knowledge databases
2.1.4. Microsoft Software Library
2.2. Internet
%2.2.1. World Wide Web pages
2.2.2. Mailing lists
2.2.3. Usenet news groups
2.2.4. Other FAQs of interest
2.2.5. FTP sites
2.3. CompuServe
2.4. Printed matter
2.4.1. Magazines and journals
%2.4.2. Books on MFC
*2.4.3. Cool MFC Articles
2.5. Trade shows
2.6. User's groups
2.7. Technical Support
3. A Brief History of MFC (Answers to questions about MFC/MSVC versions)
3.1. How do I know what version of MFC I have?
3.2. Pre-MFC 1.0
3.3. MFC 1.0
3.4. MFC 2.0
3.5. MFC 2.1
3.6. MFC 2.5
3.6.1. MFC 2.51
3.6.2. MFC 2.52
3.6.3. MFC 2.52b
3.7. MFC 3.0
3.8. MFC 3.1
3.9. MFC 3.2
3.10. MFC 4.0
3.11. Table of MFC releases
4. Generic Class Questions
4.1. CException - Exceptions and exception handling.
4.1.1. How do I throw a CUserExeception derived exception?
5. GDI Class Questions
5.1. CDC
5.1.1. How to I create a CDC from a HDC?
5.2. CBitmap
5.2.1. How do I read a 256-color bitmap file from disk?
6. Window, Control, and Dialogs Class Questions
6.1. Windows
6.1.1. How can I use a custom icon for a window?
6.1.2. How do I change the styles for a window that's created by MFC?
6.1.3. How do I get the minimal size of a window using MFC?
*6.1.4. How do I change a Window's title?
*6.1.5. How do I get rid of 'Untitled' in my main window caption?
6.2. Controls
6.2.1. How do I get a CControl pointer from a Dialog Template?
6.2.2. How do I subclass a control using MFC?
6.2.3. Why do I get an ASSERT when I subclass a control?
6.2.4. How do I validate the contents of a control when it loses focus?
*6.2.5. How do I enable/disable a bank of checkboxes?
*6.2.6. How do I change the background color of a control?
6.3. Dialogs
6.3.1. How do I center my dialog?
6.3.2. How do I get the 'old style' common dialogs on win95?
6.3.3. How do I subclass a win95 common dialog?
6.3.4. CDialog::Create fails, what could be wrong?
6.3.5. How do I create a toolbar/statusbar in a dialog?
*6.3.6. Why isn't my CDialog::PreCreateWindow getting called?
*6.3.7. How do I embed a common dialog in a property page?
*6.3.8. Why can't I DDX/DDV to initialize my CDialog controls?
6.4. Control bars, status bars, toolbars, dialog bars.
6.4.1. How do I add a combobox to my toolbar?
6.4.2. How do I update the text of a pane in a status bar?
6.4.3. How do I make my CToolBar customizable at run-time?
6.4.4. How do I turn off the toolbar or status bar?
6.4.5. How do I create a toolbar/statusbar in a dialog?
6.5. Menus
6.5.1. How do I get a pointer to the menu bar in a MDI app?
*6.5.2. How do I implement a right-mouse popup-menu?
*6.5.3. How do I dynamically change the mainframe menu?
*6.5.4. How do I 'attach' a menu to a window's creation/destruction?
*6.6. Windows Common Controls (a.k.a. Windows 95 controls)
6.6.1. Can I use these controls under NT or Win32s?
6.6.2. Where's a demo of this wickedly cool controls?
6.6.3. How do you handle NM_DBLCLK for a CListCtl?
7. Documents, Views and Frame Class Questions
7.1. Views
7.1.1. How do I size a view?
7.1.2. How do I size a CFormView?
7.1.3. How do I use new views with a doc template?
7.1.4. How do I change the background color of a view?
7.1.5. How do I get the current View?
7.1.6. How do I create multiple views on one document?
*7.1.7. How do I get all the views in an MDI app?
7.2. Documents
7.2.1. Do I have to use the Document/View architecture?
7.2.2. How do I get the current Document?
7.2.3. When are documents destroyed?
7.2.4. How do I create multiple documents?
7.2.5. How do I get a list of open documents?
8. OLE Class Questions
8.1. Structured Storage
8.1.1. When I upgraded, I could not read my files generated by
the old version of MFC. What do I do?
8.2. OLE Controls (previously called OCX's)
8.2.1. What is an OLE control?
8.2.2. How do I write OLE controls?
8.2.3. What versions of MFC support OLE control containment?
9. WOSA Class Questions
9.1. CRecordSet
9.1.1. When I add a CRecordSet class, I get tons of linker errors..
9.2. WinSock
9.2.1. I'm having problems with CSocket blocking, what's up?
10. DLL and Build Questions
10.1. Do I need a CWinApp object in a DLL?
10.2. How should I define the WEP in an MFC DLL?
10.3. How do I build an 'extension DLL'?
11. MFC Tips, Tricks, and Caveats (a.k.a Miscellaneous)
11.1. What's the best way to convert my C Windows App to MFC?
11.2. Why is my MFC application running really slow?
11.3. How can I create an application that is initially maximized?
11.4. How do I enable TRACE macros in my applications?
11.5. How do I perform background processing in my application?
11.6. How do I send a message to another thread?
11.7. Does Microsoft use MFC in their products? Which ones?
11.8. How do I limit my MFC application to one instance?
11.9. How do I get my MFC app to use the Registry on Win32?
11.10. How do I programmatically terminate my MFC application?
*11.11. What's the difference between IMPLEMENT_DYNAMIC,
IMPLEMENT_DYNCREATE and IMPLEMENT_SERIAL?
*11.12. How can I declare an abstract base class to be IMPLEMENT_SERIAL?
*11.13. What is afx.inl and afxwin1.inl, etc..?
*11.14. Is MFC available on the Macintosh?
*11.15. Is MFC available on OS/2?
*11.16. Is MFC available on UNIX/Motif?
*11.17. How should I learn/start learning MFC?
*11.18. What DLLs should I distribute with my MFC app?
12. Wizard Questions
12.1. How can I change the AppWizard options I selected for my application?
13. Visual C++ Questions
13.1. Windows 95 questions
13.1.1. I'm running MSVC 2.0 and I can't get Windows 95 look in
my dialogs, what's wrong?
%13.1.2. When I compile under Windows 95, it flashes in and out of
DOS mode.
13.1.3. Can MSVC 1.50 or 2.0 be used for Windows 95?
13.2. Configuration questions
%13.2.1. What are the memory requirements for MSVC?
13.2.2. How can I get MSVC 2.1, I can't find it in stores?
13.2.3. Should I run under Win 95 or NT?
13.2.4. How do I set the include/lib/exe directories?
13.2.5. I can't compile any programs! Help!
13.2.6. Can I setup a project to search different paths for source?
%13.2.7. How do I build a browser file for all of MFC?
13.3. Language feature questions
%13.3.1. Does MSVC support templates and exception handling?
13.3.2. Does MSVC support STL?
13.3.3. Does MSVC support RTTI?
13.4. Religious questions
13.4.1. Which is better OWL or MFC, BC++ or MS MSVC?
13.4.2. Should I use Visual C++ or Visual Basic?
%13.4.3. MFC philosophy (from a microsoftie!)
13.5. Advanced Visual C++ tips and tricks
13.5.1. How do I see the MSVC 'Easter Eggs'?!
%13.5.2. What are the command line options to MSVC?
13.5.3. How to change the color of ClassWizard generated code!
13.5.4. Ten cool things you can do in the VC++ editor.
13.6. Miscellanous Visual C++ questions
13.6.1. What are all these files that MSVC is creating?!
%14. Third Party MFC Products/Reviews
%15. MFC FAQ Revision History
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1. MFC FAQ Info and Credits
=============================
The MFC FAQ maintainer can be contacted via the following:
Internet: scot_wingo@msn.com
My URL is: http://www.unx.com/~scot
CompuServe: >INTERNET: scot_wingo@msn.com, or 75463,2146
Microsoft Network: scot_wingo
Snail Mail:
Scot Wingo
P.O. Box 638
Georgetown, CT 06829
I welcome any comments, criticisms or suggested additions for the
FAQ.
---------------------------------------------------------------------------
1.1. How do I get this FAQ?
============================
Hey, this is one of those chicken and egg questions, if you're reading
this you already have the FAQ. But seriously, the MFC FAQ is put
out just about monthly, so chances are you are reading an old and
stale version, instead of the fresh and fancy latest version. If
you want to make sure you have the latest version:
* "Instant-FAQ (TM)" - If you'd like to have a copy of any new MFC FAQ
releases emailed right to your front door, just send me an email via
scot_wingo@msn.com and I'll add you to the 'subscription'. No cost
or anything, just another FAQ service.
"Why wait for the announcements and then go get the FAQ yourself,
use "Instant-FAQ (TM)"
"Instant-FAQ(TM) changed my life!!! I no longer have to wait for
months for the latest FAQ. It's just waiting in my email box the
second it's released, no fuss no muss! Thanks Instant-FAQ(TM)"
-Anonymous Instant-FAQ(TM) participant.
[All restrictions apply in states that do not allow Instant-FAQ
service, please see your local MFC FAQ dealer for details.]
* The latest version can be downloaded from:
ftp://landru.unx.com/pub/mfc_faq/mfc_faqXX.txt
Where XX represents the latest version.
* This FAQ is also available on the World Wide Web.
http://www.unx.com/~scot/mfc_faq.html
[Note: Still under construction]
* The FAQ also is on CompuServe in the MSMFC forum, Developer
exchange download section, and the file name is MFC_FAQXX.TXT.
Where XX is the version number
* An announcement of a new FAQ release is posted to the usenet newsgroups:
comp.os.ms-windows.programmer.controls
comp.os.ms-windows.programmer.graphics
comp.os.ms-windows.programmer.mfc <coming soon!>
comp.os.ms-windows.programmer.misc
comp.os.ms-windows.programmer.ole
comp.os.ms-windows.programmer.tools
comp.os.ms-windows.programmer.win32
comp.answers
news.answers
comp.lang.c++
* There's also an announcement on the mfc mailing list. (See Section 2.2.2.)
* If all else fails, you can send me an email and I'll send the
latest copy to you.
---------------------------------------------------------------------------
1.2. What's the goal of this FAQ?
=================================
The goal of this FAQ is to be a clearing house for answers to MFC
questions commonly asked on primarily the usenet newsgroups but also
some stuff that gets asked on CompuServe may be included. I'm hoping
not to duplicate the great documentation out there, the tech notes,
MSDN, etc.. Hopefully you will look there first and then use this FAQ
as your last resort. The FAQ will be much more interesting if you
check those resources first, then we won't have to cover 'the basics'.
Right now the FAQ is in raw ASCII format (lowest common denominator),
but maybe some day, I'll turn it into a help file if there's enough
interest for it.
I'm trying to load the FAQ up with good phone numbers,
CODE-CODE-CODE!, URLs and email addresses of places to call. I'm
putting 800 numbers first, and then the US number second.
International folks hate it when there are only 800 numbers, so if you
want a phone number in the FAQ, please send me both.
---------------------------------------------------------------------------
1.3. Why are you doing this?
=============================
I keep seeing the same posts and they're driving me insane!!! But
seriously, I started the MFC FAQ when I had gobs of free time and was
trying to get really totally submerged in MFC. I figured, what better
way to get submerged, than to manage the FAQ.
I'm also working on a top-secret MFC project and this is a good way
for me to learn more about MFC and what MFC folks are having a hard
time with.
---------------------------------------------------------------------------
1.4. How can I contribute!?!
=============================
Good question! You can send me an email with your frequently asked
question and answer and I'll stick it right in the FAQ. It's that
easy, I'll even make sure you get credit for that entry. Please remember
to tell me what section of the FAQ you would like your FAQ added to.
Also, if you search for the word 'TODO' that indicates there is
some information I need to fill in and would really like your help
with..
---------------------------------------------------------------------------
1.5. Credits
==============
I borrowed the format from Tom Haapanen's Windows Programmers FAQ, so
I'm eternally indebted to him for that. Tom also knew the exact dates
of all MFC releases practically down to the second ;->
I'd also like to use this space to thank some of the folks that always
try and help out people on the usenet groups:
Chris Marriott - He has the highest bandwidth of darn good answers
I've ever seen.
Mike Blaszczak - A Microsoftie that reads netnews and gives great
answers! (See section 2.4.2 for info about his book!) If anybody knows
how to pronounce his name, let me know..
And of course thanks to everyone in the Microsoft MFC/MSVC group that
made MFC the phenomenon it is today: Scott Randall, Jim McCarthy, Dean
McCrory, etc.., etc..
These folks have given me lots of great feedback on the FAQ:
Jim B - jimb@turningpoint.com,
Individual FAQ contributions are usually near the FAQ.
---------------------------------------------------------------------------
1.6. How is this different from the MSVC MFC FAQ?
==================================================
There is a MFC FAQ that comes with MSVC, this FAQ is different because:
A) It's not from Microsoft (so it has more dirt!)
B) The information here is gleaned from Usenet and CompuServe, where
their information is from technical support. Hopefully the
Usenet/CompuServe folks ask better questions (they are
definitely cheaper ;-> )
---------------------------------------------------------------------------
1.7. What other languages is this FAQ translated to?
=====================================================
1.7.1. Japanese version of MFC FAQ
-----------------------------------
I am coordinating efforts with Masahiko Funaki to have a Japanese
version of the FAQ. He gets all changes so that he can maintain
the Japanese version. He can be reached via email at: 'funa@hic.co.jp'.
---------------------------------------------------------------------------
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2. Where to go for Juicy MFC Information
=========================================
Hopefully this FAQ is where you will look when all else fails. This
section documents what else is out there and how to get your paws on it.
---------------------------------------------------------------------------
2.1 Microsoft
=============
MFC comes with Microsoft's Visual C++, Watcom's C++, and Symantec's
C++ compilers.
2.1.1 Visual C++ and Visual C++ subscription.
-----------------------------------------
Microsoft sells Visual C++ in two flavors, a one-shot where you just
get the most current release and a subscription where you receive a
years worth of updates for a little extra cash. See Section 3 for
the details of what MFC release is the latest and greatest. Only
major versions are sold through outlets, so if you need a point
release, you need the subscription.
NOTE: There are TWO subscriptions out there.
1. The Visual C++ subscription, which is the compiler/MFC, etc.. for a year.
2. The Microsoft Developer's Network subscription (See next section),
where you get some developer resources (no compiler/no MFC). It's
easy to get these confused.
Prices fluctuate, so contact one of the compiler vendors for
information:
* Microsoft
(800) 719-5577
(206) 936-8661
http://www.microsoft.com
* Symantec:
(800) 628-4777
(408) 253-9600
http://www.symantec.com
* Watcom
(800) 265-4555
(519) 886-3700
http://www.watcom.com
There are also two programmer mail order houses that carry all of the
MFC supported compilers including the Visual C++ subscription:
* Programmer's Paradise
(800) 445-7899
(908) 445-7899
* The Programmer's Shop
(800) 421-8006
(617) 740-2510
...........................................................................
2.1.2 Microsoft Developers Network (MSDN)
-----------------------------------------
Another great investment is the Microsoft Developers Network (MSDN),
which is a quarterly subscription set of CDROMs that contains all of the
information you can imagine about the Microsoft developer products,
including MFC. There are two levels, level one gets you the CDs that
have all the developer tool information.
Level 1: MSDN "Development Library" - This is a single disc which
contains an absolute wealth of useful developer
information. Such as:
o Technical Articles (VC++ 1.0-2.0, C/C++, Windows, etc)
o Sample Code (Book & Magazine Samples, Product Samples
covering everything from MFC to SDK, etc.)
o Backgrounders and White Papers (including MFC 2.5 & 3.0)
o Specifications (Plug and Play, TAPI, Unicode, Winsock, etc)
o Knowledge Base and Bug Lists
o Books & Periodicals (MSJ, Dr. Dobb's, MS Press Books, etc)
o Product Docs (Word, Excel, VC++, MFC Migration Guide, etc)
o SDK's & DDK's (Win32 SDK, Telephony SDK, Speech API, etc)
o Product Tools and Utilities (Winsock, UI Guide, etc)
o Unsupported Tools and Utilities (Self Study Modules, etc)
o Conference and Seminar Papers (DevCast IV & V, Tech*Ed, etc)
Level 2: MSDN "Development Platform" - The full set is currently
(July '95 Release), is 19 discs containing:
o Discs 1-4 (U.S. "Core" Pack): U.S. Windows NT Service
Packs, Windows Versions (3.11, WFW 3.11), and SDK's,
Windows NT 3.51 Workstation Retail and Checked Builds,
Win32 SDK (Final Windows NT Components), MS DOS 6.22
o Discs 5-16 (International Pack): Intl. SDKs and Drivers
Intl. Windows NT Service Packs, Intl. Additional Windows
NT Service Packs and Windows 3.11 Versions, Windows 95
International Beta Releases (May 1995), Intl. Win 3.1 &
Windows for Workgroups 3.11,
-also-
International versions of Windows NT 3.5 Workstation:
Available in: German, French, Italian, Spanish,
Dutch, Swedish, Norwegian, Finish, Danish,
Traditional Chinese, Portuguese, Korean, Japanese
and the Japanese Win32 SDK.
o Discs 17-19 (Device Driver Kit): Windows NT 3.5 DDK
(Japanese), Windows NT 3.51 DDK, General DDK's
Level two subscribers have the option of receiving around 20 CD's
each quarter with all the latest operating systems. It even has the
operating systems in every language you can imagine! (Swahili NT,
gotta have it!) If you want to have the latest and greatest, get
level 2. If you can live with going to Egghead for operating systems,
and don't need the Swahili NT, level one should be good. You also get
a pretty good newsletter every quarter or so.
There's a MSDN FAQ at: ftp.microsoft.com:/developr/msdn/faq
There's a MSDN Web at: http://www.microsoft.com/msdn/
There's a gopher at: topher://gopher.microsoft.com/1/msdn
You can contact MSDN at:
(800) 759-5474
(303) 684-0914
msdn@microsoft.com
Level 1: $195 ($275 CAN) per year
Level 2: $495 ($695 CAN) per year
Level 1 to Level 2 upgrades: $395 ($555 CAN) per year
NOTE: This is NOT the Visual C++ subscription. It is described in
section 2.1.1. MSDN does not come with compilers or MFC, but does
come with SDKs (include files, libraries, etc..) and tons of other
developer related information.
...........................................................................
2.1.3 Knowledge Databases
-------------------------
Microsoft support creates these knowledge databases that answer
frequently asked questions and sometimes have samples and stuff. You
can get the knowledge databases from ftp.microsoft.com, CompuServe,
and they come on the MSDN (see section 2.1.2 above) CD-ROMs.
There's a tool that lets you quickly search these. Whenever I've tried
to find something here, I always end up with MFC 1.0 information
that's not very useful. Your mileage may vary.
http://www.microsoft.com/KB/indexes/visual_c.htm is the URL
for the MSVC knowledge databases.
...........................................................................
2.1.4. Microsoft Software Library
----------------------------------
Microsoft maintains a giant library of samples, tools, and demos
called the Microsoft Software Library. Here's how to find it on the
various electronic media->
* CompuServe
GO MSL
* Microsoft Download Service (MSDL)
Dial (206) 936-6735 to connect to MSDL
* Internet (anonymous FTP)
ftp ftp.microsoft.com
Change to the SOFTLIB\MSLFILES directory
- John Elsbree, elsbree@nwrain.com, programmer.misc, 6/24/95
---------------------------------------------------------------------------
2.2. Internet
==============
Throw on some sunglasses, put the top down and take a cruise on that
big ole' information highway. There's tons of great MFC information
at your finger tips (sorry billg), if you know where to look..
...........................................................................
2.2.1. World Wide Web Pages
----------------------------
Here are some URLs with MFC, or MFC related information:
MFC/MSVC specific
-----------------
o http://www.microsoft.com - Microsoft's WWW.
o http://www.microsoft.com/KB/indexes/visual_c.htm - MSVC KB
Windows NT/95 specific
----------------------
o http://www.bhs.com - Windows NT home page.
o http://biology.queensu.ca/~jonesp - Windows 95 home page.
o http://www.netex.net/w95/windows95 - More Windows 95 stuff
C++ specific
------------
o http://www.info.desy.de/user/projects/c++.html - Lots of C++ stuff.
o http://www.watcom.com/c/c.html - FAQ
o http://www.quadralay.com/www/CCForum/CCForum.html - C++ tutorials and
conversations.
o http://vinny.csd.mu.edu/learn.html - Whopping big list of books and
tutorials for C++.
o http://www.iftech.com/classes/vcpp/vcpp0.htm - Interface Technologies,
Inc. "Intro to MFC Programming with VC++ 1.5"
o http://www.solsem.com/Instructors.html - Info on Seminars for MFC
and VC++, Windows 95, NT, etc.
o http://execpc.com/~owl/cplus.html - On With Learning - Visual C++
Training Video Tapes
o http://www.yahoo.com/computers/languages/c_c__/ - Yahoo's Computer
Languages: C/C++ Page with links to other resources
TODO ** Need more URLs!
Lots of magazines are on the web, see section 2.4.1 for those URLs
...........................................................................
2.2.2. Mailing lists
---------------------
As far as I can tell, there's only one mailing list, mfc-l. It's a
great mailing list, with many Microsofties that lurk and answer. To
subscribe send an email to listserv@netcom.com with the message:
subscribe mfc-l
David Elliott (dce@netcom.com), started and manages this list. Thanks
for setting it up David!!
...........................................................................
2.2.3. Usenet Newsgroups
---------------------------
You can get to Usenet groups through the Internet, or through many of
the on-line services these days. Unfortunately, there is not a MFC
specific newsgroup, but most of the Windows programming groups are
full of MFC questions. Here's a quick rundown of where you can go for
MFC conversations, in order of MFC content:
* comp.os.ms-windows.programmer.tools -
This is where most of the MFC stuff happens, it IS a tool after all.
* comp.os.ms-windows.programmer.misc -
Give it a shot, lots of noise here, but usually good noise.
* comp.os.ms-windows.programmer.win32 -
I like this group, doesn't seem to crowded, people know what's going
on, I guess because they're already into win32.
* comp.os.ms-windows.programmer.ole -
An occasional thread about some of the OLE classes pops up here.
* comp.lang.c++ -
This is suppose to be for C++ language issues, but people are always
posting about MSVC and MFC here. This group is really frustrating
to read, I recommend staying away. There's about a 100000:1 noise
ratio on here.
...........................................................................
2.2.4. Other FAQs of interest
------------------------------
* Windows FAQ - Maintained by Tom Haapanen.
ftp.metrics.com:~/faq
Explains lots of great stuff about Windows that you won't find here.
* Windows Programming FAQ - Maintained by Tom Haapanen.
ftp.metrics.com:~/faq
Awesome Windows Programming FAQ.
* C++ FAQ - Maintained by Marshall Cline.
ftp to rtfm.mit.edu:/pub/usenet/comp.lang.c++, also on comp.lang.c++
This is an awesome FAQ, answers every C++ question you'd ever
conceive of. It's not specific to MSVC so be careful, some behavior
could be different.
* WinHelp FAQ - Maintained by Pete Davis
Posted regularly to comp.os.ms-windows.programmer.winhelp
If you have a question about the Windows help system, this is for
you.
* Windows NT FAQ - Maintained by Adam Hamilton
Posted to comp.os.ms-windows.nt.misc?
Pretty good, lots of networking stuff in there.
* Portable GUI (PIGUI) FAQ - Maintained by Wade Guthrie
(wade@nb.rockwell.com). Yes MFC is cross-platform, this FAQ describes
it better than we can ever hope to here. Should be accessible via
rtfm.mit.edu it's the comp.windows.misc newsgroup FAQ.
...........................................................................
2.2.5. FTP sites
-----------------
There's not much MFC code out there. You can check out these sites:
* ftp.microsoft.com - Has all the knowledge databases and a couple of
MFC specific things. Check out the software library too (softlib).
* ftp.cica.indiana.edu - pub/pc/win3/progrmr
* wuarchive.wustl.edu - Good site, don't know about MFC stuff.
pub/win3/progrmmr
* ftp.uu.net - /vendors/microsoft has some developer support things
that are on both ftp.microsoft.com and CompuServe. Microsoft seems to
be moving away from here.
* oak.oakland.edu - (SimTel Mirror) SimTel/win3/pgmtools
If you don't have Internet access, you can order CDROMs with these
entire archives from Walnut Creek. Call (800) 786-9907 or (510)
947-5996 for more information.
---------------------------------------------------------------------------
2.3. CompuServe
================
CompuServe, in my opinion, is by far the best resource for MFC
information. The MSMFC forum is dedicated to MFC discussions and has
downloads that you can't even begin to find anywhere else. Here's
some other CompuServe forums of interest:
MFC GO MSMFC
Windows GO MSWIN
Win32 GO MSWIN32
Windows NT GO WINNT
Software Library GO MSL
Languages (C++) GO MSLANG
Microsoft Developer Network GO MSDN
Microsoft Developer Services GO MSDS
Microsoft Press GO MSP
For more information about CompuServe call:
(800) 487-4838
(614) 457-8650
---------------------------------------------------------------------------
2.4. Printed Matter
=====================
2.4.1. Magazines and journals
----------------------------
I've tried to list these in order of MFC content. The ones first have
the most MFC content with the ones last having the least. Even though
they don't directly cover MFC, most of the Windows programming
magazines are still pretty valuable. Any of these that I've read, I
put comments with. If you'd like to comment, email me and I'll throw
it in here.
* Visual C++ Developer
Pinnacle Publishing ($149/yr)
(800) 788-1900
(206) 251-1900
My favorite, very meaty, lots of MFC coverage, diskette with each
issue.
* Visual C++ Professional
Oakley Publishing ($149/yr)
(800) 234-0386
(503) 747-0800
Similar to above, but just a smidge less MFC.
* Inside Microsoft Visual C++
The COBB Group ($69/yr)
(800) 223-8720
(502) 493-3300
Similar to above, but even less MFC. Lot's of stuff about the
compiler, etc..
* Microsoft Systems Journal (MSJ)
Miller Freeman Inc.
(800) 666-1084
(303) 678-0439
http://www.mfi.com/msj
About 1 MFC article every 2 months
* Windows Tech Journal
Oakley Publishing
(800) 234-0386
(503) 747-0800
Same as above.
* Windows/DOS Developers Journal
R+D Publications
(913) 841-1631
Same as above.
* PC Techniques
Coriolis Group
(602) 483-0192
http://www.coriolis.com
Same as above.
* Dr. Dobbs
Miller Freeman Inc.
(800) 456-1215
(303) 678-0439
http://www.ddj.com
About one MFC article every 3-4 months, maybe.
* C++ Report
SIGS Publications
(800) 361-1279
(212) 242-7447
These guys never talk about MFC, but they all hate it. Purists!
* C/C++ Users Journal
R+D Publications
(913) 841-1631
Same as above.
...........................................................................
2.4.2. Books on MFC
-------------------
There's tons of books on Visual C++, but not many of them go into
the details about MFC. Here's a list of books that are over 50%
oriented towards MFC (e.g. don't have pages of screenshots of compiler
options dialogs and the MSVC IDE)
* Microsoft Visual C++ Documentation Set
Microsoft Press
(800) MSPRESS
(416) 293-8464
o Volume 2: Programming with MFC and Win32 ($27)
ISBN 1-55615-802-5
o Volume 3: MFC Library Reference ($45)
ISBN 1-55615-801-7
These come in the on-line docs, but nice to have printed versions of them.
If you are going to do MFC programming, volume 2 is a 'must have'
* Inside Visual C++, Second Edition
Microsoft Press ($40)
David J. Kruglinski (Ex-Microsoftie)
ISBN: 1-55615-661-8
# Sounds like it would be Visual C++ specific, but this is the 'Petzold
of MFC programming. In other words, it's a 'must have' (along
with volume 2 of the printed docs. If you can't afford both,
stick with volume 2 on-line and get this one)
**Note, this does not have Win32 coverage, yet.
-scot_wingo@msn.com
# The best MFC book that I know of is "Inside Visual C++" by David
Kruglinski. Despite the name, this is primarily an MFC book.
-Chris Marriott, chris@chrism.demon.co.uk, programmer.graphics, 6/15/95
* The Revolutionary Guide to Win32 Programming with MSVC
WROX Press ($45), June 1995
Mike Blaszczak
ISBN: 1-874416-47-8
# I just finished reading this one. As the title indicates, it's
Win32 specific. I also think it's a little too advanced for
beginners. If you're into Win32 (Win 95) programming, it has
really good chapters on those classes. Also comes with a neato
poster! Chapter 9 on DLLs is best coverage of that material, ever.
-scot_wingo@msn.com
# If you understand C++ and _some_ windows programming this is a
great book to learn MFC.
-Shelley Lambert, reach@ee.mcgill.ca, programmer.tools, 6/18/95
# It is the best book on Win95 programming I have found.
-Gary Coombs, N40JW@News.Radio.Org, programmer.win32, 6/19/95
* Writing Windows Applications with MFC
M+T Books ($40)
Bryan Waters
ISBN: 1-55851-379-5
# At first I thought it was too beginner, but the last 5 chapters kick
butt. Lots of info on MFC internals, exception handling, and topics
not covered elsewhere. Good for someone new to Windows and MFC
programming.
* Visual C++ How To
Waite Group ($40)
# I can tell you that its a real good book for what its intended to be.
Which is, sort of like your FAQ. It comes with a CD and has little
tidbits like:
1.) How to animate an icon. I adapted this a bit to figure out how to
change icons (in an MDI on the fly).
2.) How to detect multiple instances of a Windows app and pull the
other one to the top of the Z-order. This is a perennial Usenet
question and I pulled the code and had it working first time.
3.) How to put a bitmap on the main client window of a MDI app.
Again, a nasty little thing to figure out on your own, but given good
directions, quite easily done from the book.
The CD is also broken out between those that are using VC 1.5 versus 2.0.
# Like other Waite Group "How-To" programming books, this one is
in "Cookbook" or FAQ format. You read the table of contents for
the functionality you are looking for, and the associated chapter
contains the code to implement it.
Topics include: Document and View, Status Bars and Toolbars,
Controls, Multimedia, Bitmaps and Icons, Dialogs
OLE and DDE, System and a FAQ of short tips
Many new classes are given here which all supplement the MFC in a
fairly logical manner. Some of the chapters which were of interest
to me were:
2.1 - Put the current time in the status bar
2.3 - Add a status bar to my Views
2.4 - Display Progress information in the status bar
4.1 - Preview an AVI file using the common file dialog
4.3 - Play AVI files in a CView
4.4 - Play large WAV files
4.6 - Create 3D animation using OpenGL and MFC
5.5 - Smoothly animate bitmaps
6.6 - Write customized DDX/DDV routines
8.3 - Localize MFC applications using resource DLLs
8.5 - Make multiple inheritance work in MFC
And many tidbits from the FAQ...
I like the cookbook format which allows me to glue in specific
functionality on demand. I found this book to be fairly helpful
in that regard. I look forward to Volume II ;-)
-cntrline@winnet.com via email, 7/15/95
* Visual C++ 2: Developing Professional Applications in Windows 95 and
Windows NT using MFC
Marshall Brain and Lance Lovette
Prentice Hall
ISBN: 0-13-305145-5
Should be out end of June 1995
TODO: Find comments on this book.
* Animation Techniques in Win32
Nigel Thompson
Microsoft Press (Early 1995)
ISBN: 1-55615-669-3
At first glance, I ignored this book on the shelves, however, when
I finally picked it up, it used MFC completely throughout. A very
good book on doing graphics with MFC.
-jdc@biosym.com, John Clark, via email 6/6/95
* Teach Yourself Microsoft Foundation Class Library Programming in 21 Days
Robert Shaw
SAMS ($30)
ISBN: 0-672-30462-7
-bossi@hp2.sm.dsi.unimi.it (Giuliano Bossi) no review.
# I find "Teach Yourself Visual C++ in 21 Days" a good reference, since
it is set up to cover a small group of features each "day", so you can
quickly go to a subject area, and get a from-scratch description of it
and how to use it. However, the author is not strong on using the VC
IDE, claiming that "you have to write this code yourself the first few
times, so you better appreciate what AppStudio and ClassWizard are
doing behind the scenes." I'd prefer the approach where we use the
tools at hand, and then map out what those magic MESSAGE_MAP macros
are really doing.
-Paul.McGuire@SEMATECH.Org, email, 7/11/95
* MS Foundation Class Primer: Prog Windows 3 & Windows NT w/MFC
Jim Conger
The Waite Group Press ($32) Mar-93, 830 pages
ISBN: 1-878739-31X
-jalvarez@uno.com
# The best MFC book that I've seen that DOESN'T use VC++ Wizards is
"Microsoft Foundation Class Primer"
-stasic@news.dorsai.org, ED, programmer.misc, 6/24/95
# This book is a good intro for people new to MFC, but it's
getting pretty dated. This book was written during the time
of MS C++ 7.0, and some of the newest functionality just isn't
covered (for obvious reasons ;), which can confuse a newbie.
At any rate, it's still makes pretty good book for someone
looking for the basics.
-cntrline@winnet.com, email, 7/15/95
* Master Visual C++ 2,2/E w/CD-ROM (covers MFC 3.0 library)
Howard W. Sams & Company ($ 50) Jan-95, 1183 pages
Gurewich & Gurewich
ISBN: 0-672305-321
-jalvarez@uno.com
# I picked up a copy of "Master Visual C++" specifically for its
coverage of creating custom VBX's. This is not covered in Kuglinski's
"Inside Visual C++" nor in "Teach Yourself Visual-C++ in 21 Days".
"Master Visual C++" is just my speed, since I am a dabbler who does
not read instructions or tutorials, just jumps in over my head, then
starts looking for the routine calls I overlooked. Similar to the
Heavy Metal book, this book could have been squeezed down to about 1/3
the size, but here that is not the point. Each example starts with a
demo of the finished product, then goes through the steps
descriptively, then goes through the steps again with the code. My
little VBX was done in a day an a half, and I have a much better feel
for the ins and outs of this process.
-Paul.McGuire@SEMATECH.Org, email, 7/11/95
* Heavy Metal Visual C++ Programming
Steve Holzner
Brady Publishing
ISBN 1-56884-196-5
# Hate to disagree, but I find this book disappointing. The reason is, I
felt like being treated as a semi-idiot when reading the book. Don't get
fooled by its number of pages -- it could have been easily reduced to
half of its size, if the author knew how to list the code efficiently.
Furthermore, there are too many misprints in the version I have.
-Huayong (yang@math.umass.edu), programmer.tools, 6/18/95
# The rule of thumb is never buy Holzner's book. His book only
leads you the the door. You can't find practically useful
examples. Almost every updated vesion is the same.
-Runhong (chen@nice3.ne.rpi.edu), programmer.tools, 6/18/95
* Programming the Windows 95 User Interface
Microsoft Press
ISBN 1-55615-884-X
Nancy Cluts (Due out August '95)
NOTE: Microsoft Developer Network Developer Library contains the
complete preliminary draft of this wonderful work, along with
all the source code to the examples, with *BOTH* Win32 and MFC
source! Chapters cover all of the controls and features
necessary for Windows 95 development! I've got mine on order,
and I also printed it all out! Anybody interested in looking
at the first draft, it's on the July '95 MSDN Developer Library
In:
\Books and Periodicals\Programming the Windows 95 User Interface
-cntrline@winnet.com, email, 7/15/95
* Visual C++ Power Toolkit
Ventana Press ($50), 1995, 785 pages
Info: http://www.vmedia.com/vc++.html
(919) 942-0220
Richard Leinecker, Jamie Nye
Includes a CD-ROM
ISBN 1-56604-191-0
# YACTB = Yet Another Cookbook Type Book. Although this book tries to be
a sourcebook for programmers by giving many new classes and clever
code, it just isn't laid out as logically as other books I've seen
recently (see: "Visual C++ How-To" listing).
This book covers a lot of topics, such as: Customizing the
Interface, Animation, Screen Effects, Music & Sound,
Advanced Animation, Data Compression, OLE 2.0, Communications and
Scanner Input (Using TWAIN).
I haven't found this book to be as useful as other books for my
purposes yet, but it does include a lot of new Classes which may
prove useful for other programmers.
-cntrline@winnet.com, email, 7/15/95
# I just grabbed this one and at first glance it looked really
useful, then I started reading it and BLECH! The author's writing is,
well, it's not so great. Also, the classes are sloppy and show no OO
design at all. The author's comment is "I'm not hungarian, so
why should I name variables like one". Can't say I recommend
this one.
-scot_wingo@msn.com
* The following are rumored to be coming out RSN (Real soon now)
* MFC 3.0 Bible - The Waite Group ($45)
* MFC Internals - AW George Shephard and Scot Wingo
* Extending MFC - AW David Shmitt?
* Visual Programming - Richard Hale Shaw
* Programming Windows 95 with MFC, Microsoft Press, Jeff Prosise
* Waite Group MFC book (title unkown!) Don Kiely, donkriely@crn.com
...........................................................................
2.4.3. Cool MFC Articles
------------------------
There's probably a million 'good' MFC articles out there, but this
section is for the ulta-hip, totally-swinging, must-have,
gotta-read MFC articles. If you submit an article for this
section, please include all the 'volume' information and a short
paragraph about why it's so damn cool! [Note if you have questions
about the magazines or MSDN mentioned below, see sections: 2.4.1
and 2.1.2]
* "Fun with MFC: 33 Tips to Help You Get the Most Out of ..."
-Paul DiLascia, MSJ, November 1993, Volume 8, Number 11
# This is my A#1 MFC article of all time. Even though this
article is 2 years old, it has principals and ideas that are
extremely valuable to today's MFC programmer. Good news is
that it's on MSDN in their MSJ archives! You can also find
this gem under books online: Extensions: articles/Technical
Articles/Fun with MFC: 33 Tips.
-scot_wingo@msn.com
* Scott Randall has a great little article that you can find right
on your Visual C++ 2.x in Books Online. It's under Extensions:
articles/Technical Articles/Tools for using MFC 2.0. Describes
the philosophy behind the VC++ Wizards.
* "Meandering Through the Maze of MFC Message and Command Routing"
-Paul DiLascia, MSJ, July 1995, Volume 10, Number 7
# Best explanation of messages ever, a MFC FAQ "must-read".
* "Rewriting the MFC Scribble Program Using an OOD Approach"
-Allen Holub, MSJ, August 1995, Volume 10, Number 8
# Not my favorite article, but 'DID' stir up lots of talk on
most MFC forums. Any article that generates this much noise
has to be good.
* "Self Decorating Pages"
-David A. Schmitt, Windows Tech Journal, July 1995
* "Dad, Can I Drive the Printer Tonight?"
-David A. Schmitt, Windows Tech Journal, August 1995
# This series of articles is pretty good, especially if you are
into printing.
* "Plunge into MFC's User Interface"
-Scot Wingo, Windows Tech Journal, August 1994
# WOW! This guy is the best!
* Coming in September:
C++ Report, SIGS Publications,
"A Brief History of MFC" - recaps section 3 of this FAQ and
throws in some new information.
TODO: Get more good article pointers.
---------------------------------------------------------------------------
2.5. Trade shows
================
* MFC Professional Developers Conference
Microsoft
(800) 206-3000
(612) 550-6340
First one was in early June 1995.
* Software Development (East and West)
Miller Freeman
(415) 905-2222
http://www.mfi.com
tloftus@mfi.com
This is where Microsoft unveils the latest MSVC technology, they
have a big booth and last year had a problem solving area. Many
Microsofties also give talks on MFC, some free, some part of the
program.
There are two Software Development shows a year. The West show is
held in San Francisco in Spring and the East show is held in
Washington, D.C. in the Fall. The West show is bigger.
* VBITS MFC Companion Conference
(800) 848-5523
Fawcette Publications puts on a Visual Basic show called VBITS, they
are starting to put on MFC tracks too.
TODO - Comments anyone? I heard it was slow this year in NYC.
* WinDev
(508) 649-4200
A Boston show, last held in June 12-16, 1995. It's put on by Boston
University and has a MFC/C++ track in addition to other MFC related
talks.
TODO - Anyone have comments on this?
---------------------------------------------------------------------------
2.6. Users Groups
===================
I don't know of any MFC specific user's groups, but there are some
really good C++ user's groups that have some MFC content in their
programs. The NW C++ User's group has a really nice email newsletter
that anybody can subscribe to by emailing cpp@netcom.com. Here's the
contact information for the known C++ User's groups->
|--------------------------------------------------------------|
| Area Contact Name Contact Email |
|--------------------------------------------------------------|
| New York, NY | Saul Rosenberg | Rosenberg@decus.org |
| Redmond, WA | Steve Shimeall | steves@amc.com |
| San Jose, CA | Gene Paymar | epaymar@hooked.net |
| Santa Clara, CA | Marian Corcoran | mcorcora@ix.netcom.com |
| Tucson, AZ | Martin Lapidus | lascaux@primenet.com |
| North West | Robin Rowe | cpp@netcom.com |
|--------------------------------------------------------------|
---------------------------------------------------------------------------
2.7. Technical Support
=======================
* Microsoft MSVC Technical Support
(206) 635-7007
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
3. A Brief History of MFC
==========================
I constantly see postings from folks confused about what version to
use where, etc.. So this history kind of explains where MFC has been
and where it's going.
[This is the history as I remember it. If you have any details that
you can fill in, release dates, inside info, etc.. Let me know!]
To understand the MFC releases, you need to realize that there are 16
and 32-bit releases of MFC. 16-bit releases call Win16 and run on
Windows 3.1 and 3.11 (Windows for Workgroups)
The 32-bit releases call Win32 and run on Windows NT and Windows 95
(and can run on Windows 3.1 with Win32s, but it still calls Win32)
Skip to section 3.10 for a quick table of releases if you want to skip
the long descriptions of each release.
In each section, the new classes added to MFC are highlighted. It's
nearly impossible to do cool class diagrams in ASCII, so their
hierarchy is just shown by indentation. I've also left CObject out of
most of the hierarchies for brevity. You can pretty much assume that
CObject is a parent of most of the classes except things like CString,
etc.
---------------------------------------------------------------------------
3.1. How do I know what version of MFC I'm using?
==================================================
Check the top of the MFC header file afxver_.h (lives in
mfc\include\afxver_.h). Older versions use afxver.h. In there you
will see a #define for _MFC_VER.
This is the hex version of the MFC release with this key:
0x0250
|||_____________ Point release ( very minor)
||______________ Minor number
|_______________ Major number
So in this example, the MFC release is 2.5.0.
---------------------------------------------------------------------------
3.2. Pre-MFC 1.0
=================
In the beginning, Microsoft created a group called the AFX group
(stands for (A)pplication (F)ramework(X)). This group probably was
created to come out with an OWL competitor, since Borland C++ was
doing pretty well. They came up with a class library that presented a
very high abstraction from the Windows API, kind of like OWL does.
[Note: The group was actually formed before OWL 1.0 according to
elsbree@nwrain.com ]
Legend has it that they then went and tried writing applications with
it for a couple of months and found that it was just too far removed
from the Windows API. They couldn't leverage any knowledge of
Windows and most of these guys were die hard Windows API hackers.
Legend also has it that at this point they scrapped the ENTIRE AFX
class library, and then worked on what would become MFC 1.0... You
can still see remnants of the AFX days, many of the source files have
afx prefixes and lots of macros in MFC today still have AFX in them.
The AFX group was actually responsible for two things: the MFC library
and the IDE's support for MFC (namely, the resource editor and the
wizards). The AFX name was dropped in April 1994, and the group's
members simply became part of smaller teams within the Visual C++
group. One of those smaller teams is today's MFC team.
I've also heard rumors that MFC was once called the MS Fulcrum Classes.
---------------------------------------------------------------------------
3.3. MFC 1.0
=============
This release was simultaneously released with Microsoft C/C++ 7.0 in
early 1992. It provided a very thin abstraction over the Windows API.
This initial release did not have any of the document view
architecture we know and love today, however it did lay the foundation
by introducing CObject, MFC persistence via CArchive and many other
features still heavily used in MFC today. This was a 16-bit release
released in 03/92.
A 32-bit version of MFC 1.0 was released in July 1993, together with
Windows NT 3.1 and the final Win32 SDK. The files there are dated
93-07-24. The Win32 SDK did not include Visual C++ or the MFC 2.x.
MFC 1.0 introduced these classes:
General:
CObject
CWinApp
CMenu
CArchive
CDumpContext
CRuntimeClass
CMemoryState
CFileStatus
CString
CTime
CTimeSpan
CPoint
CRect
CSize
Exceptions:
CException
CMemoryException
CNotSupportedException
CArchiveException
CFileException
CResourceException
File Services:
CFile
CStdioFile
CMemFile
Collections:
CByteArray
CWordArray
CDWordArray
CPtrArray
CObArray
CStringArray
CPtrList
CObList
CStringList
CMapWordToPtr
CMapWordToOb
CMapPtrToWord
CMapPtrToPtr
CMapStringToPtr
CMapStringToOb
CMapStringToString
Graphics:
CDC
CClientDC
CWindowDC
CPaintDC
CMetaFileDC
CGdiObject
CPen
CBrush
CFont
CBitmap
CPalette
CRgn
Windows Support:
CWnd
CFrameWnd
CMDIChildWnd
CMDIFrameWnd
CDialog
CModalDialog
CStatic
CButton
CEdit
CListBox
CComboBox
CScrollBar
---------------------------------------------------------------------------
3.4. MFC 2.0
=============
MFC 2.0 was a 16-bit release that shipped with Visual C++ 1.0. It
added the Document/View framework on top of MFC 1.0 and also added OLE
1.0 classes, message maps and common dialog classes. This was a
16-bit release released on 02/93
MFC 2.0 introduced these classes:
General:
CCreateContext
CPrintInfo
CDataExchange
CCmdUI
Exceptions:
CFileException
COleException
Dialogs:
[Note CModalDialog was nuked and functionality moved to CDialog, you
can still see a #define CModalDialog CDialog in the header files]
CDialog [not introduced here, but revamped to be a base for common dlgs]
CFileDialog
CColorDialog
CFontDialog
CPrintDialog
CFindReplaceDialog
Windows Support:
[Just new derivatives of CButton/CEdit and VBX class.]
CButton
CBitmapButton
CEdit
CHEdit
CBEdit
CVBControl
Document Architecture:
CCmdTarget
CWinApp [Moved in hierarchy, use to be derived from CObject]
CDocTemplate
CSingleDocTemplate
CMultiDocTemplate
CDocument
COleDocument
COleClientDoc
COleServerDoc
Views:
CView
CScrollView
CFormView
CEditView
Control Bars:
CControlBar
CToolBar
CStatusBar
CDialogBar
CSplitterWnd
OLE 1.0 Classes:
COleServer
COleTemplateServer
CDocItem
COleClientItem
COleServerItem
---------------------------------------------------------------------------
3.5. MFC 2.1
=============
MFC 2.1 shipped with Visual C++ 1.1 for NT, it was basically a Win32
port of MFC 2.0. It was a 32-bit release that was released on
08/93.
MFC 2.1 did not introduce any new classes.
---------------------------------------------------------------------------
3.6. MFC 2.5
=============
MFC 2.5 shipped with Visual C++ 1.5. It introduced the OLE 2 and ODBC
classes. It was the last 'official' 16-bit release.
Released in 12/93
MFC 2.5 introduced these classes:
General: [OLE and DB related]
CFieldExchange
COleDataObject
COleDispatchDriver
CRectTracker
Exceptions: [OLE and DB exceptions]
COleException
COleDispatchException
CDBException
Files: [New OLE File support]
CFile
COleStreamfile
Dialogs: [New OLE Dialogs]
CDialog
COleDialog
COleInsertdialog
COleChangeIconDialog
COlePasteSpecialDialog
COleConvertDialog
COleBusyDialog
COleLinksDialog
COleUpdateDialog
Windows Support: [Some OLE additions]
CFrameWnd
COleIPFrameWnd
CControlBar
COleResizeBar
Document Architecture: [Significant classes added for OLE here.]
CCmdTarget
COleObjectFactory
COleTemplateServer
COleDataSource
COleDropSource
COleDropTarget
COleMessageFilter
CDocument
COleDocument
COleLinkingDoc
COleServerDoc
CDocItem
COleClientItem
COleServerItem
Views: [New view for DB support]
CView
CScrollView
CFormView
CRecordView
ODBC/Database Classes:
CDatabase
CRecordSet
CLongBinary
...........................................................................
3.6.1. MFC 2.51
----------------
A point release to 2.5 (16-bit) that was a bug fix release. Shipped
with MSVC 2.0 in 9/94 with MFC 3.0 (32-bit).
...........................................................................
3.6.2. MFC 2.52
----------------
A point release to 2.5 (16-bit) that added some of the MFC 3.0
features such as property sheets, Winsock and MAPI support.
Shipped with MSVC 2.1 in 1/95 with MFC 3.1 (32-bit).
NOTE: This is only available via the MSVC Subscription.
Classes added in 2.52:
CSocket
CAsyncSocket
CSocketFile
CPropertyPage
CPropertySheet
MAPI:
[Note that MAPI support was added to CDocument, no new classes]
CDocument::OnFileSendMail
CDocument::OnUpdateFileSendMail
COleDocument::OnFileSendMail
...........................................................................
3.6.3. MFC 2.52b
----------------
[Excerpt from the 2.52b rel notes]
Visual C++ 1.52b includes the industry-standard Microsoft
Foundation Class Library (MFC) version 2.52b. Besides classes for OLE
and database, this version includes classes for OLE control
development.
Bugs Fixed in Visual C++ 1.52b
Visual C++ 1.52b fixes a number of bugs from Visual C++ 1.5. Of
particular interest to most developers are the following bug fixes:
MFC 2.52b
Error L2025 occurred on CWnd::DoDataExchange.
This bug has been corrected. See Microsoft Knowledge Base article
Q120152 for more information.
CArchive::ReadObject sometimes caused an assertion in a CPtrArray
object because CPtrArray can hold a maximum object size of 16K in a
large memory model application. CArchive did not take the memory model
into account; since CArchive enforced a 32K limit, objects of 32K
could be written but an assertion was generated if CArchive read in
more than 16K.
This bug has been corrected.
There was a memory leak in 16-bit AUX_DATA.
The three pens used in the class CPropertySheet were leaking. See
Microsoft Knowledge Base article Q128604 for more information.
The CArchive buffer pointer could wrap around the end of a segment unintentionally.
This bug has been corrected.
If AfxSockInit failed, applications sometimes produced a General
Protection Fault.
This bug has been corrected. See Microsoft Knowledge Base article
Q130653 for more information.
The MAPISendMail dialog did not stay modal.
This bug has been corrected.
Source file DLGPROP.CPP had non-near data. This could prevent
applications from being able to run multi-instance.
This bug has been corrected.
---------------------------------------------------------------------------
3.7. MFC 3.0
=============
MFC 3.0 shipped with Visual C++ 2.0 in 9/94. It introduced docking
toolbars, property sheets and template based collection classes. This
was the first release in the MSVC subscription, it was a 32-bit release.
Classes added in MFC 3.0:
Tabbed Dialog Support:
CWnd
CPropertySheet
CDialog
CPropertyPage
---------------------------------------------------------------------------
3.8. MFC 3.1
=============
MFC 3.1 shipped with Visual C++ 2.1 in 1/95. It introduced MAPI,
WinSock and Windows Common Controls. The MFC toolbar, status bar,
etc.. still live in MFC. This is the latest release out. It is a
32-bit release.
NOTE: Only available via MSVC subscription.
Classes added in MFC 3.1:
MAPI:
[Note that MAPI support was added to CDocument, no new classes]
CDocument::OnFileSendMail
CDocument::OnUpdateFileSendMail
COleDocument::OnFileSendMail
Windows Common Controls Classes: [All of these are CWnd derived]
CAnimateCtrl
CHeaderCtrl
CHotkeyCtrl
CImageList
CListCtrl
CProgressCtrl
CSliderCtrl
CSpinButtonCtrl
CStatusBarCtrl
CTabCtrl
CToolBarCtrl
CToolTipCtrl
CTreeCtrl
WinSock Support:
CAsyncSocket
CSocket
---------------------------------------------------------------------------
3.9. MFC 3.2
=============
MFC 3.2 shipped with Visual C++ 2.2 via the subscription in
mid/late July. It is a 32-bit release. Includes a 2.52b 16-bit
release update.
[here's an excerpt from the release notes]
Support for Windows Common Controls in USRDLLs. In order to use the
MFC Windows Common Control classes you must link in the appropriate
static libraries, as shown in the following table:
Library Target
DAFXCC.LIB Release version
DAFXCCD.LIB Debug version
DAFXCCU.LIB Release Unicode version
DAFXCCUD.LIB Debug Unicode version
Updated MFC Common Control classes that work with those controls
that have been recently released in Windows NT 3.51 and those that
will be available in Windows 95 and a future version of Win32s.
Improved common control documentation that is more complete and
reflects changes since the first implementation.
New MFC sample applications
---------------------------
NOTEPAD + Notepad+ is an enhanced version of Notepad. The
enhancements are mainly from questions our customers
have been asking.
SAVER Saver is a screen saver written using MFC. It
"morphs" the text "MFC" to the text "C++".
OLEVIEW The OLEVIEW sample is very similar to the OLE2VIEW.EXE
applet provided in \MSVC20\BIN. The sample illustrates
how to implement OLE Object viewers through custom OLE
interfaces. These custom interfaces are implemented in
IVIEWERS.DLL
BATCH BATCH is an MDI application that lets you compress
different AVI (Audio Video Interleaved) files in
different ways.
WORDPAD WORDPAD illustrates use of the CRichEditCtrl and
CRichEditView classes, which encapsulate the new Rich
Edit common control.
These samples are located in the SAMPLES\MFC directory of your
Visual C++ installation.
Updated Win32 SDK components
----------------------------
With the release of Windows NT 3.51 and the upcoming release of
Windows 95, the Win32 SDK has been updated to support both of these
operating systems. Changes include new header files, new import
libraries, and additional documentation. Visual C++ 2.2 includes the
latest header files, import libraries and Win32 API documentation to
support writing Windows NT- and Windows 95-compatible applications.
---------------------------------------------------------------------------
3.10. MFC 4.0
==============
Rumor has it that MFC 4.0 will be part of MSVC 4.0 (they are finally
going to get the numbers in synch) to ship shortly after Windows 95
ships (9/95). The MFC status bar, toolbars, property dialog and
other UI classes will be rewritten to use the Windows 95 common
controls. There will be other Windows 95 enhancements as well and much
better OLE control support too! Just heard that there will be some
new database classes based on the Jet Engine <Access DB engine> and
something called message reflection, so you can stop messages from
bouncing up to parents if you want to grab them all.
Classes added in MFC 4.0: <Heard about these through the grapevine>
CSynchronize
CMutex
CEvent
CMultiLock
CShellNew - Windows 95
**NOTE: This has not been released yet, MFC 3.2/MSVC 2.2 is the latest
release with MFC 4.0/VC++ 4.0 due out in September.
---------------------------------------------------------------------------
3.11. Table of MFC releases
============================
** Hint, MFC releases are always MSVC release - 1. This is because MFC
1.0 came out with MS C 7.
MFC Rel MSVC Release 16 or 32 bit Notes
---------------------------------------------------------------------------
1.0 <C/C++ 7.0> 16 Just thin Windows coverage
2.0 1.0 16 Document/Views added
2.1 1.1 for NT 32 First 32-bit release for NT
2.5 1.5 16 OLE/ODBC, last 16-bit release
2.51 2.0 16 Bug fixes.
2.52 2.1 16 Adds prop sheets to 2.5
2.52b 2.2 16 Shipped in July '95, bug fixes
3.0 2.0 32 Property sheets, dock toolbars
3.1 2.1 32 Winsock/MAPI, Win commcntrls
3.2 2.2 32 Shipped in July '95, more commcntrls
4.0 4.0 32 Not out yet, Win 95, OLE Control container
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
4. Generic Class Questions
=========================
4.1. CException - Exceptions and exception handling.
----------------------------------------------------
4.1.1. How do I throw a CUserException derived exception?
----------------------------------------------------------
When I try to catch a derived exception I get the following error:
error C2039: 'classCMyException' : is not a member of
'CMyException' 'classCMyException' : undeclared identifier
'IsKindOf' : cannot convert parameter 1 from 'int*' to 'const
struct CRuntimeClass*'
You need to make your CMyException class dynamically creatable
using the DECLARE_DYNAMIC() and IMPLEMENT_DYNAMIC() macros. The
CATCH macro expects to be able to access run-time information about
the thrown class.
-blaszczak@bix.com, Mike B, 6/5/95, comp.os.ms-windows.programmer.misc
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
5. GDI Class Questions
======================
5.1. CDC
========
5.1.1. How do I create a CDC from a HDC?
----------------------------------------
Sometimes the Windows API will just give you a handle to a DC and
you might want to create a CDC from that. On example is
owner-drawn lists, combos and buttons. You will receive a draw
item message with a hDC. Here's some code to turn that hdc into
the more familiar CDC.
void MyODList::DrawItem(LPDRAWITEMSTRUCT lpDrawItem)
{
CDC myDC;
myDC.Attach(lpDrawItem->hDC);
//Do more stuff here
//If you don't detach, it will get deleted and windows will
//not be happy if you delete it's dc..
myDC.Detach();
}
You can use this technique for any of the other MFC class/ Windows
handle pairs too.
Another approach is to call the CDC FromHandle method:
CDC * pDC = CDC:FromHandle(lpDrawItem->hDC);
It's not clear which is 'better', FromHandle is less error prone
because you do not have to remember to 'detach'.
-jmccabe@portage1.portup.com (Jim McCabe) 6/5/95
---------------------------------------------------------------------------
5.2. CBitmap
============
5.2.1. How do I read a 256 color bitmap file from disk?
------------------------------------------------------
Currently, MFC does not contain direct support for reading and
displaying DIBs or BMPs. However, there are a number of sample
applications that illustrate just how to do this.
The first sample is the MFC sample application DIBLOOK. The
MULTDOCS sample uses the same source code provided by DIBLOOK to read
and display DIBs and BMPs.
Two other examples provided with Visual C++ are the SDK samples
DIBVIEW and SHOWDIB.
- Question posted on comp.lang.c++, 6/5/95, found this in MS FAQ, 6/25/95
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
6. Window, Control, and Dialogs Class Questions
===============================================
6.1. Windows
============
6.1.1. How can I use a custom icon for a window?
-------------------------------------------------
The Microsoft Foundation Class Library stores icons for the main
frame window and the MDI frame window as resources. The icon with
resource ID AFX_IDI_STD_MDIFRAME is the icon for the MDI frame
window, and the icon with resource ID AFX_IDI_STD_FRAME is the icon
for the main frame window. To replace these icons in your
application, add an icon to your resources file with the
appropriate ID.
The application specifies the icon for a view in an MDI child
window when it creates the template. The application uses the icon
with the specified resource ID when the user minimizes the MDI
child window that contains the corresponding view.
This technique allows you to specify one icon for the application
to associate with these windows. Windows also supports dynamically
painting a minimized window. To do this with MFC, use
AfxRegisterWndClass() to register a window class with a NULL icon
handle. Override the PreCreateWindow() function in the window class
for the dynamically painted icon and copy the name returned by
AfxRegisterWndClass() into the lpszClassName member of the
CREATESTRUCT. This creates the window using the class that has a
NULL icon. When the user minimizes this window, the icon receives
WM_PAINT messages that it can process to display information
appropriately. To do so, override the OnPaint() message handler and
call the IsIconic() function to see if the window is minimized. If
so, create a CPaintDC object and use it to draw on the icon. If the
window is not minimized, call the base class version of OnPaint()
to update the window normally.
-MSVC Knowledge Base 6/4/94
...........................................................................
6.1.2. How do I change the styles for a window that's created by MFC?
---------------------------------------------------------------------
To change the default window attributes used by a framework
application created in AppWizard, override the window's
PreCreateWindow() virtual member function. PreCreateWindow()
allows an application to access the creation process normally
processed internally by the CDocTemplate class. The framework
calls PreCreateWindow() just prior to creating the window. By
modifying the CREATESTRUCT structure parameter to
PreCreateWindow(), your application can change the attributes
used to create the window.
The CTRLBARS sample application, provided with the Microsoft
Foundation Class Library version 2.0, demonstrates this
technique to change window attributes. Note that depending on
what your application changes in PreCreateWindow(), it may be
necessary to call the base class implementation.
For more information, see MSVC knowledge base article Q99847.
-MSVC Knowledge Base 6/7/95
............................................................................
6.1.3. How do I get the minimal size of a window using MFC?
------------------------------------------------------------
Write a handler for WM_GETMINMAXINFO.
-blaszczak@BIX.com, Mike Blaszczak, 6/12/95 via programmer.misc
............................................................................
6.1.4. How do I change a Window's title?
-----------------------------------------
AfxGetApp()->m_pMainWnd->SetWindowText("My Window Title");
-or-
AfxGetMainWnd()->SetWindowText ( "My Own Title" ) ;
-aj536@freenet.toronto.on.ca, mfc-l, 7/9/95
............................................................................
6.1.5. How do I get rid of 'Untitled' in my main window caption?
-----------------------------------------------------------------
Override the PreCreateWindow function in your MainFrame class and
do the following in it..
cs.style &= ~FWS_ADDTOTITLE ;
You can also set the initial window position (cs.x, cs.y, cs.cx,
cs.cy) this way and change your class (cs.lpszClass) this way!
Remember to call CFrameWnd::PreCreateWindow at the end...
-netninja@svpal.org, programmer.misc, 7/29/95
----------------------------------------------------------------------------
6.2. Controls
=============
6.2.1. How do I get a CControl from a Dialog Template?
-------------------------------------------------------
You can get a pointer to a control from a already created dialog
control by doing a simple typecast of the results from GetDlgItem.
Here's an example that creates a CButton from a checkbox with ID
IDC_CHECK1.
void my_function(CDialog * pDialog)
{
CButton * pButton = (CButton *)pDialog->GetDlgItem(IDC_CHECK1);
ASSERT(pButton != NULL);
pButton->SetCheck(m_bShowState);
}
Note that it's always safer to check for the validity of the
results from GetDlgItem.
-scot_wingo@msn.com, 6/1/95
............................................................................
6.2.2. How do I subclass a control using MFC?
----------------------------------------------
Read the documentation on SubClassDlgItem. Here's an example of
how to call it:
BOOL CMyDialog::OnInitDialog()
{
//Do your subclassing first.
m_MyControl.SubClassDlgItem(ID_MYCONTROL, this);
//Let the base class do its thing.
CDialog::OnInitDialog();
// Perhaps do some more stuff
// Be sure to call Ctl3d last, or it will cause
// assertions from multiple subclassing.
Ctl3dSubclassDlg(m_hWnd, CTL3D_ALL);
}
-Mike Williams, mikew@marlin.ssnet.com, mfc-l 6/1/95
...........................................................................
6.2.3. Why do I get an ASSERT when I subclass a control?
---------------------------------------------------------
Make sure that you subclass the control BEFORE you call
Ctl3dSubclassDlg, if the 3-d control DLL is loaded first, it will
already have subclassed your controls and you will get an assert.
- Mike Williams, mikew@marlin.ssnet.com, mfc-l 6/1/95
...........................................................................
6.2.4. How do I validate the contents of a control when it loses focus?
------------------------------------------------------------------------
NOTE: This is in the Microsoft Software Library.
The FCSVAL sample application was created to show how an
application can do control-by-control validation in a dialog box.
The application itself is just a modal dialog box displayed by the
CWinApp::InitInstance(). After displaying the dialog box,
InitInstance() simply quits the application.
The important part of the sample takes place in the dialog-box
class implementation: There are two edit controls. The first takes
input of an integer between 1 and 20. The second takes a character
string as input with length less than or equal to 5. When you Tab or
mouse-click from control to control within the displayed dialog box,
the contents of the control that is losing focus are validated.
The CFocusDlg Class
The application's functionality centers around the CFocusDlg class
and its implementation of four message handlers (discussed below).
Normal data exchange (DDX) and validation (DDV) using the routines
provided by MFC take place in OnInitialUpdate(), when the dialog box
is first displayed, and when the user chooses the OK button to accept
the input. This is default behavior provided by ClassWizard when
member variables are connected to dialog-box controls and can be
examined in the dialog class DoDataExchange() function.
Validating control contents when switching focus from one control
to the next is done by handling the EN_KILLFOCUS notification sent by
the edit control that is losing focus. The idea here is to check the
contents and, if they are not valid, to display the message box,
inform the user, and then set the focus back to the control from which
it came. Unfortunately, some difficulties arise when trying to set the
focus (or display the message boxes) within a killfocus message
handler. At this point, Windows is in an indeterminate state as it is
moving focus from one control to the other. This is a bad place to do
the validation and SetFocus() call.
The solution here is to post a user-defined message to the dialog
box (parent) and do the validation and SetFocus() there, thus waiting
for a safer time to do the work. (See "CFocusDlg::OnEditLostFocus()"
in the file FOCUSDLG.CPP and "WM_EDITLOSTFOCUS user-defined message"
in the file FOCUSDLG.H.)
Another thing you will notice about this function is that it uses
TRY/CATCH to do the validation. The provided DDX/DDV routines throw
CUserExceptions when failing to validate or load a control's data. You
should catch these and do the SetFocus() in the CATCH block.
Note: This sample has other cool stuff, but this is the major one
I've seen asked about on the net.
-MS FAQ, 6/25/95
...........................................................................
6.2.5. How do I enable/disable a bank of checkboxes?
-----------------------------------------------------
I don't know about a magic way to do this using a single HWND, but there
is a simple and self-documenting technique that I've been using for a
long time. You can make a routine that accepts an array of UINTs (your
control IDs) and a visibility flag.
This function can be a stand-alone function, or you can put it inside a
class. I have been collecting little utility functions like this and keep
them in a CDialogBase class -- when I create a new dialog box in ClassWizard,
I fix up the code to derive from CDialogBase instead of CDialog.
For example, the function might look like this:
void CDialogBase::ShowControls(UINT* pControls, UINT cControls, BOOL fVisible)
{
for (UINT uIndex = 0; uIndex < cControls; uIndex++)
{
CWnd* pwnd = GetDlgItem(pControls[uIndex]);
if (pwnd)
{
pwnd->ShowWindow(fVisible ? SW_SHOW : SW_HIDE);
pwnd->EnableWindow(fVisible);
}
}
}
Then later, often in your OnInitDialog handler, you can call this
function with your control group:
#define SIZEOF_ARRAY(a) (sizeof(a) / sizeof(a[0]))
{
static UINT aGroup1[] = { DLG_CHBOX1, DLG_CHBOX2, DLG_STATIC1 };
static UINT aGroup2[] = { DLG_LABEL2, DLG_LABEL7 };
ShowControls(aGroup1, SIZEOF_ARRAY(aGroup1), TRUE);
ShowControls(aGroup2, SIZEOF_ARRAY(aGroup2), FALSE);
}
You can find many uses for these control arrays later too...
(Changing fonts in a series of controls, etc...) Good luck,
-jmccabe@portage1.portup.com, mfc-l, 7/18/95
...........................................................................
6.2.6. How do I change the background color of a control?
----------------------------------------------------------
Your dialog can trap the WM_CTLCOLOR message, look up the MFC help
file notes for CWnd::OnCtlColor(). Before a control is about to paint
itself, the parent window receives a chance to set its own default
text color and background brush.
-jmccabe@portage1.portup.com, mfc-l, 7/18/95
Also check out the MS KB article ID: Q117778
TITLE: Changing the Background Color of an MFC Edit Control
-Ramesh, MSMFC, 7/19/95
---------------------------------------------------------------------------
6.3. Dialogs
============
6.3.1. How do I center my dialog?
---------------------------------
Use the CWnd::CenterWindow method accomplish this. I usually put
it in my OnInitDialog overloaded function. Since CDialog is an
ancestor of CWnd, you can call the method directly->
BOOL CMyDialog::OnInitDialog()
{
//Perform any other dialog initialization up here.
CenterWindow();
return TRUE;
}
- scot_wingo@msn.com, 6/1/95.
...........................................................................
6.3.2. How do I get the 'old style' common dialogs on win95?
-------------------------------------------------------------
MFC detects if it is running on Win95, and if so, replaces the
standard FileOpen Dialog with an explorer version of the FileOpen
Dialog. You can prevent MFC from using this "explorer" version by
adding the following line to your CFileDialog derived class
constructor: m_ofn.Flags &= ~OFN_EXPLORER;
-andyd@andyne.on.ca (Andy DeWolfe), via programmer.win32, 5/10/95
...........................................................................
6.3.3. How do I subclass a win95 common dialog?
------------------------------------------------
You can do it but Microsoft has made it much more difficult in
Win95. You need to create a "child dialog template" (with the
WS_CHILD style) and set it to m_ofn.lpTemplateName (making sure
m_ofn.hInstance is set to your app instance). This template must
*only* contain the controls that you are adding to the dialog (ie. NOT
the whole dialog with the standard controls duplicated as in Win3.x).
When the dialog is invoked, your template will appear (by default)
below the regular file dialog controls. If you put a static control
with id stc32 (defined in include\dlgs.h), the common dialog code will
rearrange things so that the original controls will appear wherever
your put the stc32 control (you don't have to size it to match - the
common dlg code will do that for you).
You will need to supply m_ofn.lpfnHook and handle your additional
controls through the hook proc. Note that since the system puts your
dialog template ON TOP of the normal dialog, MFC message routing won't
get to your controls so you can't code them through a message map in
your CFileDialog derivative. If anybody has found a way around this,
I'd love to hear it!!
This is very messy and Microsoft knows it. They promise a fix in
MFC 4.0.
-joej@golddisk.com, Joe Janakovic, via programmer.win32, 6/10/95
...........................................................................
6.3.4. CDialog::Create fails, what could be wrong?
---------------------------------------------------
- Invalid HWND passed as a parent
- Invalid dialog resource ID passed (be careful about numeric IDs
vs. string IDs -- be careful with #define ID_MYDIALOG 0x1234 -- it is
a "string" ID to the resource compiler).
- one or more controls on your dialog could not be created, usually
because of the use of a custom control that was not registered.
- calling EndDialog during the OnInitDialog message (or some other
handler called early in the game)!
- NULL HWND passed as parent when dialog has WS_CHILD style
That's about all I can think of right now,
-Dean McCrory, MSMFC, 6/16/95
...........................................................................
6.3.5. How do I create a toolbar/statusbar in a dialog?
--------------------------------------------------------
There's a sample in the Microsoft Software Library, DLGCBR, that
demonstrates how to do this.
Basically there's four steps, outlined and then coded below->
To add a control bar to a dialog, you must create the control bar
as usual, and then make room for the control bar within the client
area of the dialog. For the control bar to function properly, the
dialog must duplicate some of the functionality of frame windows. If
you want ON_UPDATE_COMMAND_UI handlers to work for the control bars,
you also need to derive new control bar classes, and handle the
WM_IDLEUPDATECMDUI message. If your dialog is not the main window of
your application, you will also need to modify its parent frame window
to pass the WM_IDLEUPDATECMDUI message on to the dialog's control
bars.
To make room for a control bar within the client area of the dialog,
follow these steps in your dialog's OnInitDialog() function:
1. Create the control bars.
2. Figure out how much room the control bars will take by using the
reposQuery option of RepositionBars():
CRect rcClientStart;
CRect rcClientNow;
GetClientRect(rcClientStart);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,
0, reposQuery, rcClientNow);
3. Move all the controls in your dialog to account for space used
by control bars at the top or left of the client area. If your dialog
contains a menu, you also need to account for the space used by the
menu:
CPoint ptOffset(rcClientStart.left - rcClientNow.left,
rcClientStart.top - rcClientNow.top);
ptOffset.y += ::GetSystemMetrics(SM_CYMENU);
CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD);
while (pwndChild) {
pwndChild->GetWindowRect(rcChild);
rcChild.OffsetRect(ptOffset);
pwndChild->MoveWindow(rcChild, FALSE);
pwndChild = pwndChild->GetNextWindow();
}
4. Increase the dialog window dimensions by the amount of space used
by the control bars:
CRect rcWindow;
GetWindowRect(rcWindow);
rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
MoveWindow(rcWindow, FALSE);
5. Position the control bars using RepositionBars().
To update the first pane of a status bar with menu item text, you
must handle WM_MENUSELECT, WM_ENTERIDLE, and WM_SETMESSAGESTRING in
your dialog class. You need to duplicate the functionality of the
CFrameWnd handlers for these messages. See the CModelessMain class in
the sample program for examples of these message handlers.
To allow ON_UPDATE_COMMAND_UI handlers to work for other status bar
panes and for toolbar buttons, you must derive new control bar classes
and implement a message handler for WM_IDLEUPDATECMDUI. This is
necessary because the default control bar implementations of
OnUpdateCmdUI() assume the parent window is a frame window. However,
it doesn't do anything but pass the parent window pointer on to a
function which only requires a CCmdTarget pointer. Therefore, you can
temporarily tell OnUpdateCmdUI() that the parent window pointer you
are giving it is a CFrameWnd pointer to meet the compiler
requirements. Here's an example:
LRESULT CDlgToolBar::OnIdleUpdateCmdUI(WPARAM wParam,LPARAM lParam)
{
if (IsWindowVisible()) {
CFrameWnd* pParent = (CFrameWnd*)GetParent();
if (pParent)
OnUpdateCmdUI(pParent, (BOOL)wParam);
}
return 0L;
}
To pass WM_IDLEUPDATECMDUI messages on to dialogs other than the
main window, save dialog pointers in your frame window class and
create a WM_IDLEUPDATECMDUI handler in that class. The handler should
send the WM_IDLEUPDATECMDUI message on to the dialog child windows by
using CWnd::SendMessageToDescendants(). Then perform default
processing for the message within the frame window.
-MS FAQ 6/25/95
...........................................................................
6.3.6. Why isn't my CDialog::PreCreateWindow getting called?
-------------------------------------------------------------
PreCreateWindow does not get called when you create a dialog box.
If you would like to init some data/controls for a dialog box you have
to trap the OnInitDialog message and do you stuff there.
PreCreateWindow is use to modify params for a window that you are
creating.
-ewalker@tezcat.com, mfc-l, 7/12/95
...........................................................................
6.3.7. How do I embed a common dialog in a property page?
-----------------------------------------------------------
This question comes up frequently on the "MFC" forum of CompuServe
and the simple answer - unfortunately - is that there is no way to do
it :-(
-chris@chrism.demon.co.uk, programmer.win32, 7/12/95
...........................................................................
6.3.8. Why can't I DDX/DDV to initialize my CDialog controls?
--------------------------------------------------------------
You can't do anything with the dialog controls until your dialog is
created - which doesn't happen until DoModal(). The standard way of
overcoming the problems is to create member variables for the data,
initialise them before calling DoModal and then transfer the values
in OnInitDialog. Or perhaps in UpdateData(). Much like the
ClassWizard member variables does it.
So have your dialog include a CStringList or CStringArray, put the
values for the listbox in that and transfer them to the listbox in
OnInitDialog. [etc...]
-null@diku.dk, programmer.controls, 7/11/95
Init your dialog in OnInitDialog. If neccessary pass a pointer to
your document to the constructor of your dialog (and save it in a
private/protected m_pDoc member).
-jhasling@gascad.co.at, programmer.controls, 7/11/95
---------------------------------------------------------------------------
6.4. Control bars, status bars, toolbars, dialog bars.
=======================================================
6.4.1. How do I add a combobox to my toolbar?
----------------------------------------------
You can do this using the CToolBar::SetButtonInfo method.
The MFC sample ctrlbars shows how to do this. Basically you call
SetButtonInfo with the resource ID of your combobox. You might
want to throw some separators in there too.
-scot_wingo@msn.com, 6/1/95
...........................................................................
6.4.2. How do I update the text of a pane in a status bar?
-----------------------------------------------------------
By default, a CStatusBar pane is not enabled when the pane is
created. To activate a pane, you must call the
ON_UPDATE_COMMAND_UI() macro for each pane on the status bar and
update the panes. Because panes do not send WM_COMMAND messages,
you cannot use ClassWizard to activate panes; you must type the
code manually. For example, suppose one pane has ID_INDICATOR_PAGE
as its identifier and that it contains the current page number in a
document. To make the ID_INDICATOR_PAGE pane display text, add the
following to a header file (probably the MAINFRM.H file):
afx_msg void OnUpdatePage(CCmdUI *pCmdUI);
Add the following to the application message map:
ON_UPDATE_COMMAND_UI(ID_INDICATOR_PAGE, OnUpdatePage)
Add the following to a source code file (probably MAINFRM.CPP):
void CMainFrame::OnUpdatePage(CCmdUI *pCmdUI)
{
pCmdUI->Enable();
}
To display text in the panes, either call SetPaneText() or call
CCmdUI::SetText() in the OnUpdate() function. For example, you
might want to set up an integer variable m_nPage that contains the
current page number. Then, the OnUpdatePage() function might read
as follows:
void CMainFrame::OnUpdatePage(CCmdUI *pCmdUI)
{
pCmdUI->Enable();
char szPage[16];
wsprintf((LPSTR)szPage, "Page %d", m_nPage);
pCmdUI->SetText((LPSTR)szPage);
}
This technique causes the page number to appear in the pane during
idle processing in the same manner that the application updates
other indicators.
- MSVC Knowledge Base 6/4/94
...........................................................................
6.4.3. How do I make my CToolBar customizable at run-time?
-----------------------------------------------------------
You might consider reading article "CToolBarCtrl :Handling
Customization Notifications" in the Product Documentation of VC++
2.1.
Here is the relevant extract :
"A Windows toolbar common control has built-in customization
features, including a system-defined customization dialog box, which
allow the user to insert, delete, or rearrange toolbar buttons. The
application determines whether the customization features are
available and controls the extent to which the user can customize the
toolbar. These customization features are available in the
CToolBarCtrl class but not in the current CToolBar class.
You can make these customization features available to the user by
giving the toolbar the CCS_ADJUSTABLE style. The customization
features allow the user to drag a button to a new position or to
remove a button by dragging it off the toolbar. In addition, the user
can double-click the toolbar to display the Customize Toolbar dialog
box, which allows the user to add, delete, and rearrange toolbar
buttons. The application can display the dialog box by using the
Customize member function."
- R.Rajendran (NetQuest), 76041.2245@compuserve.com,
MSMFC Forum, May-9-95
...........................................................................
6.4.4. How do I turn off the toolbar or status bar?
----------------------------------------------------
You can turn the status bar off in any of your views (i.e. in the
OnViewStatusBar() method you describe above) with the following code:
if( ((CMainFrame*)GetParent())->m_wndToolBar.IsWindowVisible() )
GetParent()->SendMessage(WM_COMMAND, ID_VIEW_TOOLBAR, 0L);
if( ((CMainFrame*)GetParent())->m_wndStatusBar.IsWindowVisible() )
GetParent()->SendMessage(WM_COMMAND, ID_VIEW_STATUS_BAR, 0L);
Use 1L instead of 0L for the SendMessage's lParam to turn the bars on.
-JKBenjamin@aol.com via mfc-l, 5/16/95
...........................................................................
6.4.5. How do I create a toolbar/statusbar in a dialog?
--------------------------------------------------------
See section 6.3.5. of this FAQ
---------------------------------------------------------------------------
6.5. Menus
=======================================================
---------------------------------------------------------------------------
6.5.1. How do I get a pointer to the menu bar in a MDI app?
------------------------------------------------------------
Q>I'm writing a MDI application and I have problems to get a pointer to the
actual menu bar. The normal construction doesn't seem to work in MDI:
CMenu *menu;
menu = GetMenu()->GetSubMenu(0);
How can I get a pointer to the menu bar to update the menu?
A> AfxGetApp()->m_pMainWnd->GetMenu()->GetSubMenu(n)
-mlinar@pollux.usc.edu, Mitch Mlinar, 6/8/95
...........................................................................
6.5.2. How do I implement a right-mouse popup-menu?
----------------------------------------------------
//////////////////////////////////////////////////////////////////////
// WM_RBUTTONDOWN handler.
//
// Trap this message and display the button properties popup menu.
// The main frame receives the popup menu messages. This allows the
// status bar to be updated with the help text.
//
///////////////////////////////////////////////////////////////////////
void CAppButton::OnRButtonDown(UINT flags, CPoint point)
{
CMenu menu;
CMenu *submenu;
// load the menu
menu.LoadMenu(IDR_LAUNCH);
// get the popup menu
submenu = menu.GetSubMenu(0);
// convert to screen coordinates
ClientToScreen(&point);
// post the menu
submenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,
point.x,
point.y,
AfxGetApp()->m_pMainWnd,NULL);
}
-johnm@unipalm.co.uk, programmer.win32, 7/12/95
...........................................................................
6.5.3. How do I dynamically change the mainframe menu?
-------------------------------------------------------
CMenu newMenu;
newMenu.LoadMenu (IDR_MENU1);
AfxGetMainWnd()->SetMenu( &newMenu );
AfxGetMainWnd()->DrawMenuBar();
newMenu.Detach ();
-Arun Rao, MSMFC, 6/27/95
...........................................................................
6.5.4. How do I 'attach' a menu to a window's creation/destruction?
--------------------------------------------------------------------
{Note the original question talked about dialogs, but you can
interpolate this code to any kind of window that you want to have
change the menu.}
One of the ways to do this is as follows -
1. Declare a variable CMenu pNewMenu in one of the dialog class.
2. Handle the WM_INITDIALOG and WM_CLOSE messages in the
dialog class as follows.
3. BOOL CMydlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Load the IDR_MYFRAME menu
pNewMenu = new CMenu;
pNewMenu->LoadMenu(IDR_MYFRAME);
// Set the mainframe menu to mainframe.
((CMainFrame *)AfxGetMainWnd())->SetMenu(pNewMenu);
return TRUE;
}
And
void CMydlg::OnClose()
{
// Detach the previous HMenu handle from the object.
pNewMenu->Detach();
pNewMenu->LoadMenu(IDR_MAINFRAME);
// Restore the mainframe menu.
((CMainFrame *)AfxGetMainWnd())->SetMenu(pNewMenu);
CDialog::OnClose();
}
4. If there are other methods of closing the dialog (example-
By clicking a button in the Dialog), then The code given
above in OnClose handler, must be put in the button click
handler.
-Sanjeev Kumar, MSMFC, 6/23/95
---------------------------------------------------------------------------
6.6. Windows Common Controls (a.k.a. Windows 95 controls)
=======================================================
---------------------------------------------------------------------------
6.6.1. Can I use these controls under NT or Win32s?
------------------------------------------------------------
The version of Win32s now in beta supports the common controls.
Windows NT 3.50 does not support the common controls, and will not
in the future. You must use Windows NT version 3.51 to gain the
common controls.
-blaszczak@BIX.com, mfc-l, 7/6/95
TODO: Get Win32s version number!
6.6.2. Where's a demo of this wickedly cool controls?
------------------------------------------------------
Check out the MFC sample, fire, it features most of the controls in
action: MSVC20\samples\mfc\fire.
-scot_wingo@msn.com, 7/27/95
...........................................................................
6.6.3. How do you handle NM_DBLCLK for a CListCtl?
---------------------------------------------------
BEGIN_MESSAGE_MAP(CListView, CView)
ON_NOTIFY( NM_DBLCLK,ID_LISTCTRL,OnDblClick )
END_MESSAGE_MAP()
void CListView::OnDblClick(NMHDR* /*k*/, LRESULT* /*j*/)
{
int nItem, nFlags;
char szTest[80];
nFlags = LVNI_SELECTED;
nItem = m_ListCtrl->GetNextItem(-1, nFlags );
if ( nItem != -1 )
{
sprintf( szTest, "Selected Item %d", nItem);
AfxMessageBox(szTest);
}
}
-spolyak@interaccess.com, mfc-l, 7/21/95
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
7. Documents, Views and Frame Class Questions
=============================================
---------------------------------------------------------------------------
7.1. Views
===========
7.1.1. How do I size a view?
----------------------------
Normally, you can change the size of a window by calling
MoveWindow(). In an application developed with the Microsoft
Foundation Class (MFC) Library, the view window is a child window of
the frame window that surrounds the view. To change the size of the
view window, retrieve a pointer to the frame window of the view by
calling GetParentFrame(), then call MoveWindow() to change the size of
the parent. When the parent frame window changes size, it
automatically changes the size of the view window to fit in the parent
frame.
-MSVC Knowledge Base. 6/4/94
...........................................................................
7.1.2. How do I size a CFormView?
---------------------------------
See MS Knowledge Base article Q98598 for a very long answer.
Basically, you need to override OnInitialUpdate() in a CFormView
derived class. There's other details to deriving from CFormView
that the article goes into.
-MSVC Knowledge Base. 6/7/95
...........................................................................
7.1.3. How do I use new views with a doc template?
--------------------------------------------------
In an application created with AppWizard, you have two options:
change the derivation of the current view, or create a new view
and use the new view in your MDI application along with the
original view.
To create a new view, use ClassWizard to create a new class
derived from CView. After the class has been created, the steps
to use the new view or to modify the view provided by App
Wizard are the same.
1. Modify the header file for the view class to change all
references to CView to the name of the desired view class.
In this example, the class is derived from CScrollView.
Usually, this step involves changing the class the view
class is derived from as follows:
class CMyView : public CScrollView
2. Modify the implementation file for the view class to change
all references to CView to the name of the desired view
class. This involves changing the IMPLEMENT_DYNCREATE line
as follows:
IMPLEMENT_DYNCREATE(CMyView, CScrollView)
changing the BEGIN_MESSAGE_MAP as follows:
BEGIN_MESSAGE_MAP(CMyView, CScrollView)
and changing any other references to CView to CScrollView.
3. No further modifications are required if you are modifying a
view created by App Wizard. If you create a new view, find
the AddDocTemplate() call in the CWinApp::InitInstance()
function. The third parameter to AddDocTemplate() is
RUNTIME_CLASS(CSomeView). To replace the current view with
the new view class, change CSomeView to CMyView. In an MDI
application, you can use multiple view types by adding a
second AddDocTemplate() call that changes
RUNTIME_CLASS(CSomeView) to RUNTIME_CLASS(CMyView).
For more information, please see Knowledge Base article Q99562.
-MSVC Knowledge Base 6/7/95
...........................................................................
7.1.4. How do I change the background color of a view?
------------------------------------------------------
To change the background color for a CView, CFrameWnd, or CWnd
object, process the WM_ERASEBKGND message. The following code shows how:
BOOL CSampleView::OnEraseBkgnd(CDC* pDC)
{
// Set brush to desired background color
CBrush backBrush(RGB(255, 128, 128));
// Save old brush
CBrush* pOldBrush = pDC->SelectObject(&backBrush);
CRect rect;
pDC->GetClipBox(&rect); // Erase the area needed
pDC->PatBlt(rect.left, rect.top, rect.Width(),
rect.Height(), PATCOPY);
pDC->SelectObject(pOldBrush);
return TRUE;
}
...........................................................................
7.1.5. How do I get the current View?
-------------------------------------
The best thing to do is to pass the view along as a parameter.
If this is impractical, you can get the view if you KNOW, that it is
the currently active document and the currently active view. For
details, see Microsoft KB, article Q108587, "Get Current CDocument or
CView from Anywhere". In brief, use
(CFrameWnd*)(AfxGetApp()->m_pMainWnd)->GetActiveDocument()
and
(CFrameWnd*)(AfxGetApp()->m_pMainWnd)->GetActiveView()
to get the document and the view. It might be a good idea to wrap them
in static functions in your CMyDoc and CMyView and check that they are
of the correct RUNTIME_CLASS.
If the view isn't the currently active view or if you can run OLE
in-place, this won't work however.
-null@diku.dk, Niels Ull Jacobsen, programmer.misc, 6/8/95
...........................................................................
7.1.6. How do I create multiple views on one document?
-------------------------------------------------------
The CDocTemplate::CreateNewFrame() function creates additional
views of a document in an MDI application written with MFC.
To call this function, specify a pointer to a CDocument object (the
document for which the function will create a view) and a pointer to a
frame window that has the properties to duplicate. Typically, the
second parameter of this function is NULL.
When an application calls CreateNewFrame(), the function creates a
new frame window and a view in the frame window. The frame window type
and view type depend on the document template (CDocTemplate)
associated with the document specified in the CreateNewFrame() call.
The CHKBOOK MFC sample application that ships with Visual C++ also
demonstrates creating additional frames and views for documents.
Check out CHKBOOK.CPP, the CChkBookApp::OpenDocumentfile() function.
Another example of using CreateNewFrame() is the MULTVIEW sample
application. Also, Dale Rogerson's article, "Multiple Views for a
Single Document" located on the Microsoft Developer Network
Development Library CD-ROM, which explains in detail how to add
additional views to an existing document, is an excellent source of
information.
CreateNewFrame() creates both a frame and a view; not only a view.
If, for some reason, CreateNewFrame() does not quite address your
situation, the source code for CreateNewFrame() is quite useful to
demonstrate the steps required to create frames and views.
-MS FAQ with mods, 6/25/95
...........................................................................
7.1.7. How do I get all the views in an MDI app?
-------------------------------------------------
You need to use some functions which are undocumented:
CDocument::GetFirstViewPosition(); // DOCCORE.CPP
CDocument::GetNextView(); // DOCCORE.CPP
CMultiDocTemplate::GetFirstDocPosition(); // DOCMULTI.CPP
CMultiDocTemplate::GetNextDoc(); // DOCMULTI.CPP
You'll also need to mess with the m_templateList member of CWinApp.
-blaszczak@Bix.com, mfc-l, 7/11/95
----------------------------------------------------------------------
7.2. Documents
---------------
7.2.1. Do I have to use the Document/View architecture?
----------------------------------------------------
MFC does not force you to use document/views. Check out hello,
mdi, and helloapp samples, they don't use it at all. Most MFC
features can be used in non-document/view applications. You do
lose features like print preview and of many OLE features when you
don't go document/view.
-scot_wingo@msn.com 6/7/95
...........................................................................
7.2.2. How do I get the current Document?
-----------------------------------------
See section 7.1.5. for the details.
...........................................................................
7.2.3. When are documents destroyed?
-------------------------------------
In SDI applications, the document is deleted when the application
exits. In MDI applications, the document is deleted when the last
view on the document is closed. To help keep your document SDI/MDI
compatible, you should delete the document's data in the virtual
DeleteContents() function, not in the destructor.
-Richard Hazenberg, drmcode@euronet.nl, programmer.misc, 6/24/95
...........................................................................
7.2.4. How do I create multiple documents?
-------------------------------------------
To add support for additional document types, you can create and
register additional CMultiDocTemplate objects with your CWinApp
derived object. This technique is illustrated in the MULTDOCS sample
application. The general steps needed to add an additional document
type to an MFC application are listed below:
1. Use AppWizard to create a new document class and a new view class.
2. Use the Resource Editor to add a new resource string to support
the new document class. For more information on the format of the
document template string resource, see the topic How to Interpret a
Document Template String.
3. Use the Resource Editor to add an additional icon and menu
resource to the application. Note, the ID for each of these resources
needs to be the same ID as the resource ID used for the document
template string created in step 2. This ID is used by the
CMultiDocTemplate class to identify the resources associated with the
additional document type.
4. In the applications InitInstance() function, create another
CMultiDocTemplate object and register it with the
CWinApp::AddDocTemplate() function. For example:
CMultiDocTemplate* pDocTemplate2 = new CMultiDocTemplate(
IDR_DOC2TYPE, RUNTIME_CLASS(CDoc2),
RUNTIME_CLASS(CMDIChildWnd), RUNTIME_CLASS(CView2));
AddDocTemplate(pDocTemplate2);
5. And finally, add the custom serialization and painting code to
your new document and view classes.
-MS FAQ, 6/25/95
...........................................................................
7.2.5. How do I get a list of open documents?
----------------------------------------------
The code below demonstrates how to retrieve a list of pointers to
all CDocuments that were created using a CDocTemplate object.
In the code below, CMyApp is derived from CWinApp. The variable
m_templateList is a CPtrList object that is a member of CWinApp, and
it contains a list of pointers to all of the document templates
(CDocTemplates). The CDocTemplate functions GetFirstDocPosition() and
GetNextDoc() are used to iterate through the list of documents for
each document template.
Sample Code
void CMyApp::GetDocumentList(CObList * pDocList)
{
ASSERT(pDocList->IsEmpty());
POSITION pos = m_templateList.GetHeadPosition();
while (pos){
CDocTemplate* pTemplate =
(CDocTemplate*)m_templateList.GetNext(pos);
POSITION pos2 = pTemplate->GetFirstDocPosition();
while (pos2) {
CDocument * pDocument;
if ((pDocument=pTemplate->GetNextDoc(pos2)) != NULL)
pDocList->AddHead(pDocument);
}
}
}
There are two public member functions of the CDocTemplate class that
are not documented in the reference manual or the online help.
However, these are public member functions defined in the CDocTemplate
class and provide simple functionality for traversing the list of open
documents. These functions operate as follows:
Function: virtual POSITION GetFirstDocPosition() const;
Remarks: Call this function to get the position of the first
document in the list of open documents associated with
the template.
Return Value: A POSITION value that can be used for iteration with
the GetNextDoc member function.
Function: virtual CDocument* GetNextDoc(POSITION& rPosition) const;
rPosition: A reference to a POSITION value returned by a previous
call to the GetNextDoc or GetFirstDocPosition member
function. This value must not be NULL.
Remarks: Call this function to iterate through all of the
document template's open documents. The function
returns the document identified by rPosition and then
sets rPosition to the POSITION value of the next
document in the list. If the retrieved document is the
last in the list, then rPosition is set to NULL.
Return Value: A pointer to the view identified by rPosition.
-MS FAQ, 6/25/95
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
8. OLE Class Questions
======================
8.1. Structured Storage/Compound Files
======================================
8.1.1. When I upgraded, I could not read my files generated by
the old version of MFC. What do I do?
---------------------------------------------------------------
There may be an easier way, but here is how I did it:
Use VERSIONABLE_SCHEMA and GetObjectSchema to identify the version.
If old version, then it is stored in OLE 1.0 format. To read this
format, first read a WORD and a CString (type and name info). Next is
the OLE data itself (the hard part). Use the following steps:
1) use StgCreateDocfile to create a temporary Compound File.
2) use OleConvertOLESTREAMToIStorage to copy the data to the Compound
file, converting to OLE 2 format.
3) call OleLoad using the IStorage to get an IUnknown pointer, then call
QueryInterface to set the COleClientItem::m_lpObject member, and set
m_nDrawAspect to DVASPECT_CONTENT.
4) release the IUnknown pointer and the IStorage pointer
5) The OleConvertOLESTREAMToIStorage code requires an OLESTREAM
implementation. Copy the code from MSVC 1.0 MFC code.
This actually works. Theres some issues with messing with the schema
parameter, and I have not implemented writing OLE 1/MFC files.
Code available on request.
-ronjones@xnet.com, Ron Jones, via programmer.tools, 5/9/95
--------------------------------------------------------------------------
8.2. OLE Controls (previously called OCX's)
============================================
8.2.1. What is an OLE control?
-------------------------------
OLE controls are the 32-bit successor to 16-bit VBX controls.
Instead of being stored in a plain DLL and having functional
interfaces, OLE controls rely on OLE automation. Hopefully this
will make the interface more flexible and easier to use than VBXs.
-scot_wingo@msn.com, 6/25/95
...........................................................................
8.2.2. How do I write OLE controls?
------------------------------------
In VC++ 2.x, Microsoft released the CDK (OLE control developer
kit), you use that kit and it's tools to write OLE controls.
-scot_wingo@msn.com, 6/25/95
...........................................................................
8.2.3. What versions of MFC support OLE control containment?
-------------------------------------------------------------
To clarify the situation:
VC++ 2.x can create OCX controls.
VC++ 2.x does NOT yet have built-in "OCX container" support. That will
be added in VC++ 4, due out this autumn. The only popular application
I'm aware of which currently supports OCXs (albeit in only a limited
way) is Access 2.
The problem is that obviously the place you want OCX container support in
MFC is in classes like "CDialog" and (possibly) "CWnd" or "CView". As I'm
sure you know, OCX controls have to implement a LARGE number of OLE2
interfaces, which makes the support code large.
At present, OLE2 support in MFC happens in the "CCmdTarget" class, which
is the base class from which ALL "application architecture" classes are
derived. I guess the choice is to extend the OLE2 support in this class
to include OCX support (which would make ALL apps using OLE2 a LOT larger),
or to add OCX-specific support to certain specific classes such as
CDialog. Either way, it's a major undertaking!
-Chris Marriott, chris@chrism.demon.co.uk, programmer.tools, 6/24/95
TODO: Find out more about OLE control limitations/support in 4.0
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
9. WOSA Class Questions
=======================
9.1. CRecordSet
---------------
9.1.1. When I add a CRecordSet class, I get tons of linker errors..
--------------------------------------------------------------------
If you haven't told the AppWizard to use Database Support when you
created your project, the AppWizard doesn't include the database
headers. If you add "#include <afxdb.h>" in your stdafx.h,
CRecordSet will be "legalized".
Then open the Linker Options window and add the library: "odbc".
This avoids tons of linker errors.
-bessler@highland.swb.de (Wolfgang Bessler) 06/05/95, comp.lang.c++
--------------------------------------------------------------------------
9.2. WinSock
=============
9.2.1. I'm having problems with CSocket blocking, what's up?
-------------------------------------------------------------
I've worked around this by creating a dialog box that I pop up after
calling Connect()... ie:
CMySocket MySocket;
MySocket.Create();
MySocket.Connect("mysmtphost",25);
CDummyDlg DummyDialog;
MySocket.m_pDialog=&DummyDialog;
DummyDialog.DoModal();
This suspends the thread until MySocket sends a WM_CLOSE message to
DummyDialog.
I'd rather it look like:
MySocket.m_hEvent=CreateEvent(...);
WaitForSingleObject(MySocket.m_hEvent,INFINITE);
But that stops all processing of MySocket.
-Cynthia Jennings (idlewild@is.net), programmer.win32, 6/19/95
TODO: Find better answer.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
10. DLL and Build Questions
===========================
If you have questions about extension and user DLLs, be sure to read
technical notes 11 and 33. Volume 2 of the documentation has more
info too. Finally, try searching on the sample names dllhusk
(extension DLL) and dlltrace (user DLL) in books on-line.
--------------------------------------------------------------------------
10.1. Do I need a CWinApp object in a DLL?
------------------------------------------
The Microsoft Foundation Class Library supports two types of DLLs:
_USRDLL and _AFXDLL. The _USRDLL model requires one CWinApp object
to perform the initialization and cleanup of the Microsoft
Foundation Class Library Windows classes that the DLL uses. This
requirement is described in MFC Tech Note 11; the DLLTRACE sample
demonstrates a _USRDLL that contains a CWinApp object.
An _AFXDLL does not require a CWinApp object. Because it shares the
Microsoft Foundation Class Library classes with the application, it
does not require a CWinApp to provide initialization and cleanup.
Instead, an _AFXDLL requires a special version of LibMain() and a
DLL initialization function.
-MSVC Knowledge Base 6/4/95
---------------------------------------------------------------------------
10.2. How should I define the WEP in a MFC DLL?
------------------------------------------------
In a dynamic-link library (DLL) built with Microsoft Foundation
Class Library version 2.0, the _USRDLL model uses the WEP()
(Windows exit procedure) function provided in the C run-time
library. Because the code uses the C library WEP() function,
the destructors for static and global objects in the DLL are
called and the CWinApp::ExitInstance() function for the DLL
application object is called.
See MSVC Knowledge Base article Q98374 and Tech notes 11 and 33.
-MSVC Knowledge Base 6/7/95
---------------------------------------------------------------------------
10.3. How do I build an 'extension DLL'?
------------------------------------------------
1. When you're building a 32-bit extension DLL, define _AFXEXT on the
compiler command line. If you look in AFXVER_.H, you'll see that this forces
_AFXDLL to also be defined. So an "AFXEXT" DLL is an AFXDLL.
2. When _AFXDLL is defined, AfxGetResourceHandle returns a value stored in
MFC's global data, which is shared by the EXE, the extension DLL and the MFC
DLL. The handle returned identifies the module which will be searched first
when looking for a resource.
(See the source code for AfxFindResourceHandle() if you're curious about the
order of the search.)
3. Strictly speaking, what we need to load a resource is a module handle
rather than an instance handle. (Instances share modules --- e.g., code and
resources --- but have different data.) A DLL has a module handle which is
distinct from the handle of the EXE.
4. You can use ::GetModuleHandle to get the handle for your DLL, then pass it
to AfxSetResourceHandle so that your DLL is the first place searched for
resources. But note that this removes the EXE module from of modules
searched. You'll probably want to save a copy of the handle returned by
AfxGetResourceHandle before calling AfxSetResourceHandle, then restore it
once you're done loading the DLL resource.
-Charlie Kester, Microsoft Developer Support, MSMFC, 7/19/95
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
11. MFC Tips Tricks and Caveats
===============================
11.1. What's the best way to convert my C Windows App to MFC?
=============================================================
Microsoft and Symantec have jointly developed a tool that helps you
make the move from a C Windows application to MFC. It's called the
MFC migration kit. You can find it on the MSVC 2.x CDROM in the MFCKIT
directory. The kit is also available from the Microsoft Software
Library (See section 2.1.4) and from Symantec.
---------------------------------------------------------------------------
11.2. Why is my MFC application running slow?
=============================================
MFC Apps should be nice and snappy. Make sure you are not building
the debug version and that you have the trace options off
(MFCTRACE.EXE). If your application continues to be slow, try
doing some quick profiling to see if you are making any redundant
calls.
-scot_wingo@msn.com, 5/31/95
---------------------------------------------------------------------------
11.3. How can I create an application that is initially maximized?
===================================================================
For new applications, this can be done with AppWizard during Step
4. During Step 4, choose Advanced..., and then select the Main
Frame tab. Check the Maximized option.
For an MDI application, in the CWinApp::InitInstance() function,
set CWinApp::m_nCmdShow to SW_SHOWMAXIMIZED before calling
pMainFrame->ShowWindow(m_nCmdShow). In an application generated by
AppWizard, the code is as follows:
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_nCmdShow = SW_SHOWMAXIMIZED; // ADD THIS LINE!
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
m_pMainWnd = pMainFrame;
In an SDI application, in the CWinApp::InitInstance() function, set
CWinApp::m_nCmdShow to SW_SHOWMAXIMIZED before calling OnFileNew().
For example, in an application generated by AppWizard, the code is
as follows:
m_nCmdShow = SW_SHOWMAXIMIZED;
// create a new (empty) document
OnFileNew();
- MSVC Knowledge Base, 6/4/95
--------------------------------------------------------------------------
11.4. How do I enable TRACE macros in my app?
=============================================
If you use Visual C++ 1.0, run the TRACER application from your
Microsoft Visual C++ program group (its icon has the title "MFC
Trace Options"). Select "Enable Tracing," then choose OK.
If you use Microsoft C/C++ 7.0, you must copy the AFX.INI file
from the Microsoft Foundation Class Library source directory
(by default, C:\C700\MFC\SRC) to your Windows directory (by
default, C:\WINDOWS). This file should contain a section such
as the following:
[Diagnostics]
TraceEnabled = 1
TraceFlags = 0
As long as TraceEnabled is set to 1, tracing is enabled.
This AFX.INI file is the same for both C/C++ 7.0 and Visual C++ 1.0.
In MSVC 2.x, the TRACE output automatically goes to the 'Debug'
window when you run in the debugger.
-VC+ Knowledge Base, 6/7/95
--------------------------------------------------------------------------
11.5. How do I perform background processing in my application?
===============================================================
Many applications perform lengthy processing "in the
background" during intervals that the user is not otherwise
interacting with the application. In an application developed
for the Microsoft Windows operating system, an application can
perform background processing by splitting a lengthy process
into many small fragments. After processing each fragment, the
application yields execution control to Windows using a
PeekMessage() loop.
An application developed with the Microsoft Foundation Class
Library can perform background processing either by using the
PeekMessage() loop in the library code's main message loop or
by embedding another PeekMessage() loop in the application.
See MSVC Knowledge Base Q99999 for more info.
-MSVC Knowledge Base 6/7/95.
--------------------------------------------------------------------------
11.6. How do I send a message to another thread?
================================================
Try using SendNotifyMessage() to send messages to another thread.
null@diku.dk, Neils Ull Jacobsen via programmer.misc, 6/18/95
--------------------------------------------------------------------------
11.7. Does Microsoft use MFC in their products? Which ones?
============================================================
There are many Microsoft apps written in MFC. Sometimes its just
not obvious... (to name a few: Bookshelf, Bob!, WordArt OLE server,
Visual C++ (of course), Win95 paint, Win95 WordPad, some portions of
Win95 FAX software, some Win95 games I know of...).
In the future, there are more apps coming out using MFC. I don't
have a way to track all of these uses, so there is certainly more that
I'm not aware of or can't remember.
I don't expect Word or Excel to ever use MFC -- they have way too
much legacy code and they don't see any customer benefit to rewriting
to MFC.
But my point is -- definitely for new code, Microsoft is using MFC.
Even some "old" code is taking advantage of MFC in future versions.
-Dean McCrory, MSMFC, 6/8/95
--------------------------------------------------------------------------
11.8. How do I limit my MFC application to one instance?
=====================================================
Look at the Microsoft sample ONETIME.ZIP, (MSDN CD or
ftp.microsoft.com). In brief:
const char* MyMainWndClassName = "MyMainWndXQW"
BOOL CMyApp::InitApplication()
{
//Call base class. Default version does nothing.
CWinApp::InitApplication();
WNDCLASS wndcls;
memset(&wndcls, 0, sizeof(WNDCLASS)); // start with NULL defaults
// Get class information for default window class.
::GetClassInfo(AfxGetInstanceHandle(),"AfxFrameOrView",&wndcls);
// Substitute unique class name for new class
wndcls.lpszClassName = MyMainWndClassName;
//Register new class and return the result code
return ::RegisterClass(&wndcls);
}
BOOL CMyApp::FirstInstance()
{
CWnd *PrevCWnd, *ChildCWnd;
// Determine if another window with our class name exists...
PrevCWnd = CWnd::FindWindow(MyMainWndClassName, NULL);
if (PrevCWnd != NULL)
{
// if so, does it have any popups?
ChildCWnd=PrevCWnd->GetLastActivePopup();
// Bring the main window to the top
PrevCWnd->BringWindowToTop();
// If iconic, restore the main window
if (PrevCWnd->IsIconic())
PrevCWnd->ShowWindow(SW_RESTORE);
// If there are popups, bring them along too!
if (PrevCWnd != ChildCWnd)
ChildCWnd->BringWindowToTop();
// Return FALSE. This isn't the first instance
// and we are done activating the previous one.
return FALSE;
}
else
// First instance. Proceed as normal.
return TRUE;
}
CMyApp::InitInstance()
{
if (!FirstInstance()) return FALSE;
...
}
-Niels Ull Jacobsen (null@diku.dk), programmer.tools, 6/19/95
--------------------------------------------------------------------------
11.9. How do I get my MFC app to use the Registry on Win32 platforms?
======================================================================
Just make a call to SetRegistryKey("MyCompany") in your CWinApp
class and pass it a string (typically your company name). This string
will define where in the registry the data goes:
HKEY_CURRENT_USER\Software\MyCompany\<application name>\<section
name>\<value name>
After making this call just use the normal WriteProfilexxx()
routines and the data will go to the registry instead of to an INI
file. It works well and is simple!
-Brett Robichaud, brett_robichaud@tallysys.com, 6/23/95, programmer.win32
--------------------------------------------------------------------------
11.10. How do I programmatically terminate my MFC application?
===============================================================
MFC does not provide a public function to gracefully exit an application.
A method for dealing with this is to create a function in your application like the following:
void ExitApp()
{
// same as double-clicking on main window close box
ASSERT(AfxGetApp()->m_pMainWnd != NULL);
AfxGetApp()->m_pMainWnd->SendMessage(WM_CLOSE);
}
As you can see, this is implemented as a global function, which can
be called from anywhere in your application. It simply sends a
WM_CLOSE message to your application's mainframe window. This
initiates an orderly shutdown of the application.
If you are using MFC, version 2.5 or later, you can take advantage
of a new global MFC function, "AfxGetMainWnd", to simplify the code:
void ExitMFCApp()
{
// same as double-clicking on main window close box
ASSERT(AfxGetMainWnd() != NULL);
AfxGetMainWnd()->SendMessage(WM_CLOSE);
}
NOTE: Always call CDocument::SetModifiedFlag() after changing your
document data. This will ensure that the framework prompts the user to
save before shutdown. If you need more extensive control over the
shutdown procedure, you can override CDocument::SaveModified().
-MS FAQ, 6/25/95
--------------------------------------------------------------------------
11.11. What's the difference between IMPLEMENT_DYNAMIC,
IMPLEMENT_DYNCREATE and IMPLEMENT_SERIAL?
===============================================================
IMPLEMENT_DYNAMIC provides run time type information to support
macros such as IsKindOf and GetRuntimeClass.
IMPLEMENT_DYNCREATE adds the ability to allow MFC to create
the type on the fly. This is required for any concrete data
type that will be serialized to a file.
IMPLEMENT_SERIAL also provides a version number for the class
and adds the ability to use the >> operator to read the
type from a file.
As an example, if a derived class Dog uses IMPLEMENT_DYNCREATE and a
base class Animal uses IMPLEMENT_SERIAL, then a Dog can be written
with a pointer to either but can only be read by a pointer to Animal.
MFC 3.x provides a constant called VERSIONABLE_SCHEMA to
be used with IMPLEMENT_SERIAL to support multiple versions
at the same time. The implementation in MFC is broken and
fails at runtime.
-jimb@turningpoint.com, email, 7/11/95
--------------------------------------------------------------------------
11.12. How can I declare an abstract base class to be
IMPLEMENT_SERIAL?
=======================================================
You need a special form of IMPLEMENT_SERIAL that looks like this:
Use the regular DECLARE_SERIAL but use IMPLEMENT_SERIAL_ABC shown
below instead of IMPLEMENT_SERIAL.
#define IMPLEMENT_SERIAL_ABC(class_name, base_class_name, wSchema) \
_IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, \
NULL) \
CArchive& AFXAPI operator>>(CArchive& ar, class_name* &pOb) \
{ pOb = (class_name*) ar.ReadObject(RUNTIME_CLASS(class_name)); \
return ar; }
-anonymous
--------------------------------------------------------------------------
11.13. What is afx.inl and afxwin1.inl, etc..?
=======================================================
These files live in the msvcXX\mfc\include directory and include
inline functions. These functions are only 'inline' during non-debug
(_DEBUG is not defined) builts of MFC. They are prefaced with a
special _AFX_INLINE derective which gets turned into 'inline' for
non-debug builds and '' for debug builds.
MFC does this so you can debug into the functions in debug mode, but
get the benefits of inlining during release builds. That's one of the
reasons the library shrinks so much in release build mode.
-scot_wingo@msn.com, 7/20/95
--------------------------------------------------------------------------
11.14. Is MFC available on the Macintosh?
=======================================================
Yes! Microsoft has something called the Visual C++ cross-platform
edition. This product lets you cross-compile for the 68000 based Macs
and I think they have a PowerPC version coming out soon. Contact
Microsoft directly for more info.
-scot_wingo@msn.com, 7/27/95
TODO: Comments on this anyone?
--------------------------------------------------------------------------
11.15. Is MFC available on OS/2?
=======================================================
No!
--------------------------------------------------------------------------
11.16. Is MFC available on UNIX/Motif?
=======================================================
Yes, contact one of the following (or all):
Bristol Technology Inc.
(203) 438-6969
Wind/U - Windows to UNIX toolkit
info@bristol.com
http://www.bristol.com
Software Uno
WM_MOTIF - Windows to UNIX (and DOS) toolkit
jalvarez@uno.com
--------------------------------------------------------------------------
11.17. How should I learn/start learning MFC?
==============================================
I see this posted lots. To start with, check out section 2.4.2 of
this FAQ, books always help. Another good point is that you can't
really get down and dirty in MFC without knowing and understanding the
underlying Windows API, so you might want to start with an overview
of that. (The 'Petzold' book is the classic here) At the very
least get a feel of what windows does and what it's capable of.
Another hint I have is don't rely too much on the Wizards, these
are great, but they sometimes shield the newbie too much. Take a
look at what AppWizard/ClassWizard has done from you, run the debugger
through a mainfrm.cpp, etc.. You won't understand what the heck is
going on until you understand what your magically generated code is
doing.
I thought the 'writing windows apps with MFC' book was a good merge
between Petzold and intro MFC stuff. 'Inside Visual C++' may move
too fast for someone that doesn't know Windows already..
-scot_wingo@msn.com, 7/27/95
* There's no substitute for paying your dues.
* Unfortunately MFC is set up so that you're never done paying your dues.
(HAHAHAHA!!!)
-raymond@btw.com, mfc-l, 7/23/95
Start with the VC++ User's Guide and work your way through the
Scribble Tutorial. You get an intro to VC++ and MFC and see how they
work together. Then there are numerous articles on the MSDN CD to
help with basic concepts. Try searching on MFC and Architecture.
Don't shy away from reading the MFC Encyclopedia articles (they take
more of a 'how-to' approach) and by all means become familiar with the
MFC Technical Notes. Also (hint), stay focused on the 32-bit stuff if
you're just starting out. There are also a number of excellent
journals out there to help.
-billb@microsoft.com, mfc-l, 7/23/95
The important points (of the top of my head) are:
If you're a windows programmer don't worry about graphics the CDC
member functions are an almost direct encapsulation of the Windows
functions. Also CWnd encapsulates much of the window manipulation functions.
Learn the Document-View architecture: document templates, the
interaction between the application, the documents and views
(AfxGetApp, GetDocument, UpdateAllViews etc).
Learn serialisation (scribble makes a good intro to it).
DDX and DDV for dialog boxes: there is a good tech note on this.
WM_COMMAND handlers, COMMAND_UI handlers (which allow you to
enable/disable menu items as well as applying check mark and radio
button marks on menu items, it also gives you one way to use status bars).
During all this you'll also learn how to use ClassWizard and see
how it is integrated with the editor and resource editor.
Perhaps as part of the MFC FAQ we could create a list of topics
(ordered in terms of importance) to learn?
{Sure, this is a good start, no? -Scot}
-grimes@parallax.co.uk, mfc-l, 7/24/95
--------------------------------------------------------------------------
11.18. What DLLs should I distribute with my MFC app?
======================================================
You should review the file REDISTRB.WRI on your Visual C++ CD.
This file explains what files are necessary for different kinds of
applications; it explains what to do about both Windows files and MFC files.
-blaszczak@BIX.com, programmer.tools, 7/9/95
dumpbin /imports myapp.exe dll_one.dll dll_two.dll | grep -i dll
And recurse through the dll's you find. Won't find dll's loaded
by LoadLibrary() however.
-null@diku.dk, programmer.tools, 7/10/95
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
12. Wizard Questions
====================
12.1. How can I change the AppWizard options I selected for my application?
----------------------------------------------------------------------------
Unfortunately, AppWizard will not modify already created and
modified applications. You need to generate a new skeleton
application using AppWizard and either merge your code into that or
compare that skeleton with your original to see what's different.
The good news is that it's mostly just a minor tweak to add/remove
OLE support or MDI or something like that. It usually is just
changing your CWinApp derivate, your frame window, or something
like that.
- scot_wingo@msn.com, 5/31/95
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
13. Visual C++ Questions
========================
I'm trying to keep these as generic as possible, but these types of
questions tend to be very release-specific, so where possible, I've
included the version that's being questioned.
13.1. Windows 95 questions
===========================
13.1.1. I'm running MSVC 2.0 and I can't get Windows 95 look and feel in
my dialogs, what's wrong?
-------------------------------------------------------------------------
In MSVC 2.0, go to the Project/Options dialog, select "Linker" and
change the linker command line to include: /subsystem:windows,4.0
This is the default in MSVC 2.1.
-Chris Marriott, chris@chrism.demon.co.uk, 5/25/95, via programmer.misc
...........................................................................
13.1.2. When I compile under Windows 95, it flashes in and out of
DOS mode.
----------------------------------------------------------------
Remove or rename any dosprmpt.pif files in your win95 and windows
directories. If this doesn't work, do the same with all pif files.
-scot_wingo@msn.com, 5/25/95
In the Win95\system directory there is a pif for Conagent. It is
this pif file that a person has to change to Window screen mode
instead of Full Screen mode. Worked like a charm on mine after
running about a month with the screen blanking...
-RockyMoore@aol.com, email, 7/16/95
...........................................................................
13.1.3. Can MSVC 1.5 or 2.0 be used for Windows 95?
----------------------------------------------------------------
You can run both versions under Windows 95. Visual C++ 1.5x can
ONLY generate 16-bit applications. You 'can' run these on Windows
95, but it's more desirable to have true 32-bit applications,
which MSVC 2.0 generates. These same rules apply to NT.
-scot_wingo@msn.com 6/5/95
----------------------------------------------------------------------------
13.2. Configuration Questions
==============================
13.2.1. What are the memory requirements of MSVC?
------------------------------------------------
MSVC 1.5.x will work on a 486 class machine with a minimum of 4MB
of RAM. 8MB will make your life much better.
MSVC 2.x needs at least 16MB. Microsoft recommends 20MB on the box.
Note: VC 1.5 takes a big (3x) performance hit under all operating
systems if you have less than 16 Meg. I published an article about
this (and other performance enhancements) in Windows/DOS Developers
Journal in May, 95.
-jimb@turningpoint.com, email, 7/11/95
...........................................................................
13.2.2. How can I get MSVC 2.1, I can't find it in stores?
---------------------------------------------------------
The point releases are part of the MSVC subscription (See section
2.1.1.). Only major releases are sold through retail, so you'll
need to buy a subscription to get the point releases.
Subscriptions are available from Microsoft, Programmer's Paradise
and Programmer's shop. (See section 2.1 for info)
...........................................................................
13.2.3. Should I run under Win 95 or NT?
----------------------------------------
Life is a bunch of trade offs. The trade offs here are if you run
under 95, you won't need as much memory, but the OS is not as
robust as NT, so you will probably crash more. On the flip side,
if you run under NT (a full 32-bit OS), you won't crash as much,
but alas, you will need more memory. Personally, I prefer the NT
route. NT catches all memory problems and handles them nicely for
you without destabilizing the system.
-scot_wingo@msn.com, 6/18/95
...........................................................................
13.2.4. How do I set the include/lib/exe directories?
-----------------------------------------------------
MSVC versions < 2.0 used environment variables INCLUDE/LIBDIR/EXEDIR.
MSVC versions > 2.0 uses settings in the Visual C++ Tools menu.
Select "Tools" and then "Options" menu item.
A dialog opens, and select "Directories" tab button.
There you can set Include directories, Library directories, Executable
directories...
-lee@sam1.info.samsung.co.kr (Lee, Jin Woo), via programmer.win32, 6/10/95
...........................................................................
13.2.5. I can't compile any programs! Help!
---------------------------------------------
Q> I just installed VC1.51 on my system. Installation proceeded smoothly
without any errors.
However, I can't compile any programs! Even when I try to compile the
simplest and shortest programs, I get this error message:
Can't open the compilation response file
A> A common cause of this type of error is having a TMP or TEMP environment
variable which isn't pointing at a valid directory. Eg your AUTOEXEC.BAT
file says:
set TMP=C:\TMP
and you don't have a "C:\TMP" directory.
-Chris Marriott, chris@chrism.demon.co.uk, programmer.misc, 6/18/95
...........................................................................
13.2.6. Can I setup a project to search different paths for source?
--------------------------------------------------------------------
I would like to have my projects first search for the source in a
local directory, and if it can't find it there, search a network
drive.
TODO: Find answer to this one, seems good. Asked on tools 6/21 by
Joe Kinsella, jkinsella@procd.com
...........................................................................
13.2.7. How do I build a browser file for all of MFC?
------------------------------------------------------
It's nice to be able to browse the MFC classes and source code, the
best way to do this is via some Microsoft supplied .BAT files for
the Microsoft Software Library:
BLDBSC15.BAT - for VC++ 1.5
BLDBSC20.BAT - for VC++ 2.0
BLDBSC21.BAT - for VC++ 2.1
Basically, you want invoke the compiler on every file with /Zs as
the option, which means generate the .sbr file and no .obj.
Next, you want to run bscmake.exe on the generated .sbr files to
create your .bsc file. The MFC makefile will complain about the
.obj's being missing, but you can ignore that warning. It will
take significantly longer and more time to create both .sbrs and
.objs.
-scot_wingo@msn.com, 6/25/95
It is worth noting that VC 2.1 has a prebuilt browser file that is
on the CD-ROM but is not installed. It can be loaded at any time
into the IDE with the File/Open command.
-jimb@turningpoint.com, email, 7/11/95
If you are using the 32-bit versions, you can get more information in
the README.TXT file in the \msvc20\mfc\src directory. What is tells
you is to move to that directory and from the dos prompt run:
nmake DEBUG=1 BROWSEONLY=1
-billb@microsoft.com, mfc-l, 7/17/95
---------------------------------------------------------------------------
13.3. Language feature questions
=================================
13.3.1. Does MSVC support templates and exception handling?
---------------------------------------------------------
The 32-bit Visual C++ 2.0 release introduced templates and
exception handling. There is no support for these C++ features in
16-bit versions of the product.
It is worth noting that the 16 bit implementation of THROW and
CATCH are brain-damaged. They do not clean up the stack as it
unwinds.
-jimb@turningpoint.com, email, 7/11/95
...........................................................................
13.3.2. Does MSVC support the Standard Template Library?
--------------------------------------------------------
You can not compile the HP freeware version of STL with MSVC 2.x.
There are some problems with templates that keep this from working.
However, several commercial versions of STL are available that work
with Visual C++ 2.x.
-scot_wingo@msn.com, 6/7/95
...........................................................................
13.3.3. Does MSVC support RTTI?
------------------------------
Currently none of the MSVC releases support RTTI (C++ Run Time Type
Information). However, all classes derived from CObject support
CRuntime which does basically the same thing using some clever macros.
-scot_wingo@msn.com, 6/7/95
---------------------------------------------------------------------------
13.4. Religious questions
==========================
13.4.1. Which is better OWL or MFC, BC++ or MS MSVC?
---------------------------------------------------
This is constantly getting asked on Usenet. The answer really
depends on what you are doing. If you demand the latest C++
features such as templates, RTTI, etc.. BC++ usually has these
first. But be careful, when Borland went from OWL 2 to 3 (or was it
1 to 2?) they made everybody completely rewrite their applications.
Applications that were written with MFC 1.0 still work with the
newer versions of MFC today!
The best advice is to get the features from each vendor and see
what's best for your situation.
-scot_wingo@msn.com 6/8/95, comp.lang.c++
...........................................................................
13.4.2. Should I use Visual C++ or Visual Basic?
-------------------------------------------------
(Here's a funny analogy I saw posted->)
Well, the principle is the same (create interface, add code to respond
to events, add code to do something useful).
But programming in VB is like riding a kiddy bike, while programming
in C++ is like driving a Formula 1 racing car - be prepared for accidents.
But seriously, VB is interpreted, MSVC is compiled, therefore MSVC
programs should be much faster (if written well). It's generally
believed that VB is the best way to 'prototype' a user-interface,
but when it comes to code reuse and solving larger problems, VB
breaks down. Visual C++ on the other hand is not as easy to use as
VB, but once you learn it, you can write much more complex programs
than with VB.
The readers digest version of all this is: It depends on the application
you are writing.
-scot_wingo@msn.com, 6/18/95
...........................................................................
13.4.3. MFC philosophy (from a microsoftie!)
---------------------------------------------
Just a note about the classes provided in MFC... keep in mind that
these classes are designed as "general-purpose" classes, not
"all-purpose" classes. No one implementation can have performance
characteristics that are ideal for *all* possible applications. It
is up to you, the programmer, to evaluate a provided implementation
and decide whether it is appropriate for the task at hand. If it is
not, you have several alternatives: modify or subclass the provided
implementation; find a more appropriate class from another source;
or write one from scratch.
-elsbree@nwrain.com, mfc-l, 7/15/95
---------------------------------------------------------------------------
13.5. Advanced Visual C++ tips and tricks
=========================================
13.5.1. How do I see the MSVC 'Easter Eggs'?!
--------------------------------------------
FYI: Easter eggs are hidden screens that usually have
secret initials, development team names, etc..
1. To see the spinning PLUS with the MSVC team members:
In MSVC 2.0 or 2.1->
A. Bring up the about box: help/about
B. Press control-tab and double click in the middle of
the box at the same time.
NOTE: You must have the MSVC CD loaded for this to work, I think.
2. If above does not work, try this->
copy the MSVCCRD.DLL from the CD to msvc\bin
CTRL+Double-click the picture in the dialog
note: release the CTRL key at the same time as the second click.
-ohallorj@pwc-tpc.ca, Jeff O'Halloran
...........................................................................
13.5.2. What are the command line options to MSVC?
--------------------------------------------------
* MSVC /V - Runs the compiler in a dos box (version 1.5 only?)
-mark@techop.demon.co.uk
* MSVC /NOLOGO - Runs MSVC without the about box, saves second
or 2.
* MSVC /bppassc:yes - Enables a cool breakpoint counter in the
'breakpoints' dialog (under the Debug menu).
-jimb@turningpoint.com, email 7/11/95
* MSVC -p <pid> - attatches VC++ to a process.
...........................................................................
13.5.3. How to change the color of ClassWizard generated code!
---------------------------------------------------------------
The default color for text modified by the ClassWizard is black
print on a white background. Visual C++ is aware of the code that the
ClassWizard modifies and can highlight these changes for you using a
different color.
Highlighting the text ClassWizard modifies makes the new
modifications very obvious and easy to find. To do this, from the
Tools menu, choose Options. Then select the Colors tab in the Options
dialog box. From the Set Colors For listbox, select Wizard-Modified
Code. Then define the colors for text and the background.
NOTE: Only applies to VC++ 2.x, but it's waaaay cool!
-MS FAQ, 6/25/95
...........................................................................
13.5.4. Ten cool things you can do in the VC++ editor!
-------------------------------------------------------
10. CTRL+ALT+T shows your tab characters
9. SHIFT+ESC closes the active dockable window
8. CTRL+F3 finds the next occurrence of the current word
7. CTRL+M finds the matching bracket
6. CTRL+> and CTRL+< find the next/prev matching #ifdef/#else/#endif
5. CTRL+SHIFT+R starts/stops macro recording
4. CTRL+SHIFT+P plays recorded macro
3. Right-click #includes to open the header file
2. TAB/SHIFT+TAB indent or unindent selected lines
1. Hold ALT key down to select columns
-Jeff Henshaw, borrowed of MFC PDC slide, 6/25/95
---------------------------------------------------------------------------
13.6. Miscellaneous Visual C++ questions
=========================================
13.6.1. What are all these files that MSVC is creating?!
--------------------------------------------------------
Here's a table that explains the common extensions and what MSVC
uses them for:
Extension Use Notes
------------------------------------------------------------------
APS App Studio file
BSC Browser file SBR's combined into 1 BSC.
CLW Class Wizard file
ILK Incremental linker file
PCH Pre-compiled header file
PDB Debugging info /Z7 affects this
RES RC 'object' file Linked into EXE
SBR Browser info for 1 file Combined into BSC
VCP Visual C++ state file
TODO: Fill this table in more completely.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
14. Third Party MFC Products
============================
This section lists products that make the MFC developer's life easy.
No OCX/VBX type products are listed here, go check some catalog.
Where possible, I've put a review by someone!
* Premia CodeWright Fusion
(800) 547-9902
(503) 641-6000
Great add-in editor for MSVC, they have both 16 and 32-bit versions.
TODO: Get a review, anyone?
* Nu-Mega Bounds-Checker
(800) 468-6342
(603) 889-2386
Lets you know if you've clobbered memory, has a special MFC feature
so you can see class names and paths through message maps.
TODO: Review?
* Rogue Wave Tools.h++
TODO: Contact info.
* There's been a looong thread on the mfc-l about how hard this
is to use with MFC, people are trying everything and it doesn't
seem to help. Evidently they use a totally different memory model,
internationalization and persistance.
-various, mfc-l 7/18/95 - 7/27/95
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
15. MFC FAQ Revision History
============================
* 1.0 Beta 5/25/95
-Did heavy work on TOC, more info, history. Not many FAQs yet.
* 1.0 Final Beta 6/2/95
-Put in some FAQs I keep seeing. Integrated feedback from mfc-l posting.
-Posted one last time to mfc-l for final feedback before FCS...
* 1.0 FCS! 6/8/95
-Put in some FAQs from MSVC KB
-Got lots of good feedback from mfc-l
-Got some new FAQs from Usenet
-Integrated news from MFC Conference, MSVC 4/2.2, etc..
-Posted to Usenet and CompuServe for first time.
* 1.1 6/25/95
- Lot's of new stuff from MFC PDC
- Lot's of cserve and usenet FAQs too
- redid VC++ section
- Lots of good book reviews coming out.
- Grabbed some stuff from new MS FAQ too.
* 1.2 7/30/95
- Updated from 1.1
* Lots of book reviews got emailed and added.
* Windows common controls section added.
* 11.x - probably needs new hierarchy soon.
- Introducing "Instant-FAQ (TM)"
- Added article section to complement book section
- Updated VC++ 2.2 information.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
=-=-=-=-THE END-=-=-=-=-=