CBitmap bmp; // Load a bitmap from a file bmp.LoadBitmap(IDB_BITMAP1); // Create a device context CDC* pDC = GetDC(); // Attach the bitmap to the device context pDC->SelectObject(&bmp);
CBitmap bmp; // Load a bitmap from a file bmp.LoadBitmap(IDB_BITMAP1); // Create a CStatic control CStatic* pStatic = new CStatic(); // Create a window using the CStatic control pStatic->Create(_T("Static"), WS_CHILD | WS_VISIBLE, CRect(10, 10, 200, 100), this, IDC_STATIC); // Attach the bitmap to the window using the SetBitmap method pStatic->SetBitmap(bmp);In this example, we first create a CBitmap object and load a bitmap from a file. Then, we create a CStatic control and attach the bitmap to the control using the SetBitmap method. The package library for CBitmap Attach is MFC (Microsoft Foundation Classes). It is a library provided by Microsoft that contains a set of classes used for developing Windows-based applications.