Click here to Skip to main content
15,917,709 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Can someone with VC++ 2008 "Orcas" test this? Pin
dontknowitall31-Aug-07 8:42
dontknowitall31-Aug-07 8:42 
Questionget checked value from menu Pin
barbarini31-Aug-07 6:40
barbarini31-Aug-07 6:40 
AnswerRe: get checked value from menu Pin
Jonathan [Darka]31-Aug-07 7:09
professionalJonathan [Darka]31-Aug-07 7:09 
GeneralRe: get checked value from menu Pin
barbarini31-Aug-07 7:26
barbarini31-Aug-07 7:26 
GeneralRe: get checked value from menu Pin
barbarini31-Aug-07 8:03
barbarini31-Aug-07 8:03 
GeneralRe: get checked value from menu Pin
Hamid_RT31-Aug-07 19:12
Hamid_RT31-Aug-07 19:12 
GeneralRe: get checked value from menu Pin
Anurag Gandhi31-Aug-07 20:19
professionalAnurag Gandhi31-Aug-07 20:19 
Questioninterface programming Pin
Adno31-Aug-07 6:18
Adno31-Aug-07 6:18 
interface IDraw
{
virtual void Draw() = 0;
};
interface IShapeEdit
{
virtual void Fill (FILLTYPE fType) = 0;
virtual void Inverse() = 0;
virtual void Stretch(int factor) = 0;
};

//------------


// C3DRect supports IDraw and IShapeEdit.
class C3DRect : public IDraw, public IShapeEdit
{
public:
C3DRect();
virtual ~C3DRect();
// IDraw
virtual void Draw();
// IShapeEdit
virtual void Fill (FILLTYPE fType);
virtual void Inverse();
virtual void Stretch(int factor);
};

//-----------------------------------

// Here is the global 3D rect.
C3DRect* ptheRect;

// Functions to operate on the 3D rect.
void CreateThe3DRect();
void DestroyThe3DRect();

Implementing CreateThe3DRect() and DestroyThe3DRect() is trivial. Simply use the new and delete keywords to create and destroy the object:

// Creation function.
void CreateThe3DRect()
{
// Create a 3d-rect.
ptheRect = new C3DRect();
}
// Destroy the rectangle.
void DestroyThe3DRect()
{
// See ya!
delete ptheRect;


//--------------------


// This method returns interfaces to the client.
bool GetInterfaceFrom3DRect(INTERFACEID iid, void** iFacePtr)
{
if(ptheRect == NULL){
cout << "You forgot to create the 3DRect!" << endl;
return false;
}
if(iid == IDRAW){ // They want access to IDraw.
// Cast the client's pointer to the IDraw interface of ptheRect.
*iFacePtr = (IDraw*) ptheRect;
return true;
}
if(iid == ISHAPEEDIT) { // They want access to IShapeEdit.
// Cast the client's pointer to the IShapeEdit interface of ptheRect.
*iFacePtr = (IShapeEdit*) ptheRect;
return true;
}
// I have no clue what they want.
*iFacePtr = NULL; // Just to be safe.
cout << "C3DRect does not support interface ID: " << iid << endl<< endl;
return false;
}
//----------------------------------------------------
int main()
{
bool retVal = false;
IDraw* pDraw = NULL;
//IDraw3* pDraw3 = NULL;
IShapeEdit* pShapeEdit = NULL;

CreateThe3DRect();

// Can I get the IDraw interface from object?
retVal = GetInterfaceFrom3DRect(IDRAW, (void**)&pDraw);
if(retVal)
pDraw->Draw();
DestroyThe3DRect();

return 0;
}
//-----




are we simply casting pointers from one type to the next here?
when selecting the interface with GetInterfaceFrom3DRect ,i have iFacePtr which is a void pointer and ptheRect.

*iFacePtr = (IDraw*) ptheRect; <-- i dont get this part.
here iFacePtr is of IDraw type.. now we have ptheRect which is of C3DRect, taking that casting it to IDraw and assigning it to iFacePtr.

does this mean we are working with an instance of C3DRect but of type IDraw?
how did we managed that?
doesn't this mean we can make an instance of an abstract class by type casting it?
As you can see im confused any easy to digest explanation would be great.

thank you
AnswerRe: interface programming Pin
led mike31-Aug-07 6:51
led mike31-Aug-07 6:51 
GeneralRe: interface programming Pin
Adno31-Aug-07 7:09
Adno31-Aug-07 7:09 
Questionhow to implement hotfix function? Pin
lostangels31-Aug-07 5:46
lostangels31-Aug-07 5:46 
AnswerRe: how to implement hotfix function? Pin
Roger Broomfield31-Aug-07 5:55
Roger Broomfield31-Aug-07 5:55 
QuestionRe: how to implement hotfix function? Pin
Hamid_RT31-Aug-07 19:09
Hamid_RT31-Aug-07 19:09 
AnswerRe: how to implement hotfix function? Pin
lostangels31-Aug-07 23:07
lostangels31-Aug-07 23:07 
Questionclistctrl oncustomdraw change row color Pin
Derrick Becker31-Aug-07 5:24
Derrick Becker31-Aug-07 5:24 
QuestionFindWindow Pin
Waldermort31-Aug-07 5:16
Waldermort31-Aug-07 5:16 
AnswerRe: FindWindow Pin
David Crow31-Aug-07 5:19
David Crow31-Aug-07 5:19 
GeneralRe: FindWindow Pin
Waldermort31-Aug-07 5:25
Waldermort31-Aug-07 5:25 
GeneralRe: FindWindow Pin
David Crow31-Aug-07 5:37
David Crow31-Aug-07 5:37 
GeneralRe: FindWindow Pin
Waldermort31-Aug-07 5:44
Waldermort31-Aug-07 5:44 
GeneralRe: FindWindow Pin
Roger Broomfield31-Aug-07 5:52
Roger Broomfield31-Aug-07 5:52 
GeneralRe: FindWindow Pin
Waldermort31-Aug-07 5:57
Waldermort31-Aug-07 5:57 
QuestionRe: FindWindow Pin
David Crow31-Aug-07 5:52
David Crow31-Aug-07 5:52 
QuestionMFC OnInitDialog lengthy process halts screen painting Pin
littleGreenDude31-Aug-07 5:02
littleGreenDude31-Aug-07 5:02 
AnswerRe: MFC OnInitDialog lengthy process halts screen painting Pin
Naveen31-Aug-07 5:11
Naveen31-Aug-07 5:11 

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.