wxBitmap bitmap(500, 500); wxMemoryDC memdc(bitmap); // Use GetTempHDC to get temporary DC handle auto hdc = memdc.GetTempHDC(); // Use SelectObject to set pen and brush auto oldPen = ::SelectObject(hdc, wxThePenList->FindOrCreatePen(wxColour(255, 0, 0), 2)); auto oldBrush = ::SelectObject(hdc, wxTheBrushList->FindOrCreateBrush(wxColour(255, 0, 0))); // Draw some stuff on the memory DC ::Ellipse(hdc, 50, 50, 250, 250); // Blit the data onto a panel wxPaintDC dc(this); dc.Blit(0, 0, 500, 500, &memdc, 0, 0); // Do some cleanup ::SelectObject(hdc, oldPen); ::SelectObject(hdc, oldBrush);In this example, we create a wxBitmap with size 500x500. Then we create a wxMemoryDC from the bitmap, and get a temporary DC handle using GetTempHDC. We also set a red pen and brush using SelectObject to draw an ellipse on the memory DC. Finally, we use wxPaintDC to draw the data onto a panel using Blit. The cleanup is performed by selecting the old pen and brush back to the DC. This example is part of the wxWidgets library, which is a C++ library used for creating cross-platform GUI applications.