Click here to Skip to main content
15,902,869 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Windows Address Book Pin
PJ Arends9-Nov-03 6:59
professionalPJ Arends9-Nov-03 6:59 
Questionhow to find the number of same items in two STL vectors Pin
hesham_16820018-Nov-03 6:47
hesham_16820018-Nov-03 6:47 
AnswerRe: how to find the number of same items in two STL vectors Pin
ZoogieZork8-Nov-03 8:03
ZoogieZork8-Nov-03 8:03 
GeneralSend Sms using visaul c++ 6 Pin
nolanl8-Nov-03 3:04
nolanl8-Nov-03 3:04 
GeneralRe: Send Sms using visaul c++ 6 Pin
Peter Molnar8-Nov-03 5:28
Peter Molnar8-Nov-03 5:28 
GeneralRe: Send Sms using visaul c++ 6 Pin
nolanl9-Nov-03 23:31
nolanl9-Nov-03 23:31 
GeneralCButton declaration Pin
Ahmed Galal8-Nov-03 2:30
Ahmed Galal8-Nov-03 2:30 
GeneralRe: CButton declaration Pin
Antti Keskinen8-Nov-03 12:05
Antti Keskinen8-Nov-03 12:05 
Because of the way MFC works:

1. Construct an object you desire in the application. This can be anything from CButton to CPen, a CEdit or a CListBox, no matter. You can construct it statically (adding a static member to your parent class definition) or dynamically (by using a static pointer with the 'new' operation)

2. When the object is constructed, call it's 'Create' member method to create the underlying Windows object, and bind it to this MFC object.

3. When you no longer need the Windows object, call 'DeleteObject' to destroy it.

4. When you no longer need the MFC object, either let it pass out of scope so it's destructor is called (static members) or call 'delete' to release dynamically reserved memory.

Now, as for the code analysis you posted:

You created a CButton static object in the CView::OnCreate handler. This means that the MFC object is constructed. If you call the 'Create' member function, the underlying Windows object is created as well. When the handler call ends, the CButton destructor gets called, and it's existence straightforwardly ends.

You should go to the local library and pick up an MFC programming book. Knowledge in Windows programming also helps. This book would be able to clarify the functionality of MFC to you in detail, so you can get a better grasp of what it actually is and how it is used.

CodeProject sports a collection of good articles as well:
-Nishant S.'s excellent 'MFC under the hood' article http://www.codeproject.com/cpp/mfcprogflow.asp[^].
-Mehdi Mousavi 'Win32 vs MFC, part I' http://www.codeproject.com/cpp/mfc_architecture.asp[^].
-Joseph M. Newcomer with 'Attaching and Detaching objects' http://www.codeproject.com/cpp/attachdetachobj.asp[^].

You can find more from the 'General' and 'Beginners' sections of General -> C++/MFC area. Happy browsing Smile | :)

-Antti Keskinen

----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
GeneralRe: CButton declaration Pin
Ahmed Galal8-Nov-03 12:11
Ahmed Galal8-Nov-03 12:11 
Generalclass with static functions and variables Pin
Kuniva8-Nov-03 0:00
Kuniva8-Nov-03 0:00 
GeneralRe: class with static functions and variables Pin
ZoogieZork8-Nov-03 2:47
ZoogieZork8-Nov-03 2:47 
GeneralRe: class with static functions and variables Pin
Anonymous8-Nov-03 3:25
Anonymous8-Nov-03 3:25 
GeneralRe: class with static functions and variables Pin
Kuniva8-Nov-03 4:20
Kuniva8-Nov-03 4:20 
GeneralWin32 message window Pin
pranavamhari7-Nov-03 23:33
pranavamhari7-Nov-03 23:33 
GeneralRe: Win32 message window Pin
Antti Keskinen8-Nov-03 12:18
Antti Keskinen8-Nov-03 12:18 
GeneralRe: Win32 message window Pin
Peter Molnar8-Nov-03 13:37
Peter Molnar8-Nov-03 13:37 
GeneralRe: Win32 message window Pin
pranavamhari8-Nov-03 15:05
pranavamhari8-Nov-03 15:05 
QuestionDo streams always have to be passed by reference? Pin
Link26007-Nov-03 22:44
Link26007-Nov-03 22:44 
AnswerRe: Do streams always have to be passed by reference? Pin
Andrew Walker8-Nov-03 13:17
Andrew Walker8-Nov-03 13:17 
General.lib in 6.0 Pin
LOSTTWARE.com7-Nov-03 21:11
LOSTTWARE.com7-Nov-03 21:11 
GeneralRe: .lib in 6.0 Pin
Mike Dimmick7-Nov-03 23:21
Mike Dimmick7-Nov-03 23:21 
GeneralChanging Printer Resolution at Run Time Pin
Tejas H Shah7-Nov-03 20:55
Tejas H Shah7-Nov-03 20:55 
GeneralLooping through all Outlook folders Pin
Anonymous7-Nov-03 20:33
Anonymous7-Nov-03 20:33 
GeneralLooping through all Outlook folders Pin
Anonymous7-Nov-03 20:33
Anonymous7-Nov-03 20:33 
GeneralRe: Looping through all Outlook folders Pin
Amit Dey8-Nov-03 0:43
Amit Dey8-Nov-03 0:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.