CFont myFont; myFont.CreateFont(20, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, _T("Arial")); // some code here myFont.DeleteObject();
std::vectorIn this example, we create a vector of font pointers and dynamically allocate memory for the font object using the 'new' operator. We then set its properties to create Arial font of size 20. We store the font pointer in the vector and use it to draw text on the screen. We will loop through the vector at the end and delete the font object using the DeleteObject method and then free the memory used by it using the 'delete' operator. In conclusion, CFont DeleteObject is a member function of the CFont class and is used to delete a previously created font object. It is part of the MFC library. Code examples demonstrate the use of this method to manage fonts in C++.myFonts; // create a vector of font pointers CFont* pFont = new CFont(); pFont->CreateFont(20, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, _T("Arial")); myFonts.push_back(pFont); // Store the font pointer in the vector // some code here for (CFont* font : myFonts) { font->DeleteObject(); delete font; // free the memory used by the font object }