DC står for "Device Context" og er en datastruktur indeholdende information om et "device", fx et display eller en printer. Koden CClientDC dc(this); laver en instans af CClientDC og initialiserer dens værdier til vinduets (klientområdet). Det betyder at du kan bruge det til at skrive/tegne på osv. Du kan godt lave flere af slagsen, hvis du vil, men du skal nok beskrive lidt nærmere hvad du vil opnå.
En af de mest brugte anvendelser er at lave et DC i memory, så man kan tegne alle sine objekter herpå først og så kopiere det hele over til skærmens/vinduets DC. Det forhindrer ofte en del flimren...
Fx: // This OnDraw() handler loads a bitmap from system resources, // centers it in the view, and uses BitBlt() to paint the bitmap // bits.
// load IDB_BITMAP1 from our resources CBitmap bmp; if (bmp.LoadBitmap(IDB_BITMAP1)) { // Get the size of the bitmap BITMAP bmpInfo; bmp.GetBitmap(&bmpInfo);
// Create an in-memory DC compatible with the // display DC we're using to paint CDC dcMemory; dcMemory.CreateCompatibleDC(pDC);
// Select the bitmap into the in-memory DC CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);
// Find a centerpoint for the bitmap in the client area CRect rect; GetClientRect(&rect); int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2; int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2;
// Copy the bits from the in-memory DC into the on- // screen DC to actually do the painting. Use the centerpoint // we computed for the target offset. pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory, 0, 0, SRCCOPY);
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.