|
1 of 8 people found the following review helpful:
4.0 out of 5 stars
Consist of book Beginning Visual C++ 5/6 from chapter 12-etc, 3 Jul 1999
By A Customer
Consist of book Beginning Visual C++ 5/6 from chapter 12 and on.This the seconf book that I have encountered that has such a comprehensive example on how to use basic windows programming C++ skills. However, from chapter 5 on, which beginning a multi chapter spanning Sketcher project, skills being used in it were not clarified enough. To help other readers who also read this excellent C++ book, I will try to supplement these skills that I have extracted from the coding based on what there are presented in the corresponding chapter related to use of pointers. Beginning MFC Programming Ivor Horton Skills: 1. Object calling another object's function through a pointer. (Ex. pDoc-function( ), m_pTempElement->Draw( ) function.) 2. Object can create another object based on a conditional ID_"event" nested inside the conditional move function. (Ex. switch(pDoc->GetElement( )) {...} 3. Get a pointer to a currently present object and use it to call the object's function. (Ex. CSketcherDoc* pDoc = GetDocument( ) // a function inherited from CView class.) 4. How one object can communicate or pass object or variable to another via a pointer. (Ex. m_pTempElement = CreateElement( ) // a function inside the CSketcherView object.) Page 569 In CsketcherView Object Call OnMouseMove( ) funtion { //Created m_pTempElement pointer to be pointed to selected CElement subclass object base on option selected from CSketcherDoc object's menu ID_event. CreateElement( ) is a function inside CsketcherView objectt hat return a new CElement sublcass pointer and create a new CElement sublcass object based on subclass in the class CElement being selected from CSketcherDoc event passed. { m_pTempElement = CreateElement( ); //This executes. Call CreateElement ( ) function in //CsketcherView object/class. m_pTempElement->Draw(&aDC); } } CElement* CsketcherView::CreateElement( ) { CSketcherDoc* pDoc = GetDocument(); // make call to GetDocument() Function which //return pointer pointing to the current CSketcherDoc //object. This executes. A function inherited from CView //class. switch(pDoc->GetElementType( )) // Then, CSketcherDoc object's GetElementType() //function executes through the pDoc pointer. { case LINE: { //content of LINE block goes here. ;} //The rest of the conditional code here execute based on the return value from GetElementType( ) //function ;} In CSketcherDoc object, the GetElementType( ) funtion executes. Class Csketcher: public Cdocument { ... // some content in page 572. // Operations WORD GetElementType( ) //Then the GetElementType( ) Function executes, { return m_Element; } // thus return the value of m_Element being selected on the //menu bar. Now get back to the CSketcherView object. The CreateElement( ) function receive the value inside the switch( ) function CElement* CsketcherView::CreateElement( ) { CSketcherDoc* pDoc = Getdocument(); // make call to GetDocument() Function which return //pointer pointing to the current CSketcherDoc object. switch(pDoc->GetElementType( )) // The switch ( ) function then executes based on return //from CSketcherDoc object's GetElementType( ) function //from the pDoc pointer. Now executes... { //The rest of the conditional code here execute based on the return value from GetElementType( ) //function case LINE: //***This case executes if returned m_Element is LINE. { return new CLine (m_FirstPoint, m_SecondPoint, pDoc->GetElementColor( )); // This executes. The code returns and creates a new CLine object. To be //passed back to the to CSketcherView object's OnMouseMove( ) function //based on the ID_mouse_move event. } case OTHERS: {... ;} ;} Now, return to the CSketcherView object. Execute the OnMouseMove( ) function. CsketcherView::OnMouseMove( ) //Just received the newly created CLine object { Created m_pTempElement pointer to be pointed to object CElement selected from CSketcherDoc object, CreateElement( ) is a function inside CsketcherView. CreateElement( ) is a function to return a pointer and create a new object based on subclass in the class CElement being selected from CSketcherDoc event passed. { codes before... m_pTempElement = CreateElement( ); //This has executed. CreateElement ( ) function //created the Cline object based on the new CLine object //pointer returned. m_pTempElement->Draw(&aDC); //Now call the new CLine object's Draw( ) function. delete m_pTempElement; //Delete the used CLine object through the CLine object pointer. m_pTempElement = 0; //Reset the pointer to address 0. } }
|