Advertisement
Guest User

Window OnPaint function

a guest
Sep 24th, 2011
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. void OnPaint(HWND hWnd,WPARAM wParam,LPARAM lParam, HDC hDC, PAINTSTRUCT* ps)
  2. {
  3.     HDC hDCDoubleBuffer = CreateCompatibleDC(GetDC(hWnd));
  4.     BITMAPINFO k;
  5.     BITMAPINFOHEADER bitmapInfo;
  6.     bitmapInfo.biSize           = sizeof(BITMAPINFOHEADER);
  7.     bitmapInfo.biWidth          = 150;
  8.     bitmapInfo.biHeight         = 150;
  9.     bitmapInfo.biPlanes         = 1;
  10.     bitmapInfo.biBitCount       = 24;
  11.     bitmapInfo.biCompression    = BI_RGB;
  12.     bitmapInfo.biSizeImage      = 0;
  13.     bitmapInfo.biXPelsPerMeter  = 0;
  14.     bitmapInfo.biYPelsPerMeter  = 0;
  15.     bitmapInfo.biClrUsed        = 0;
  16.     bitmapInfo.biClrImportant   = 0;
  17.     k.bmiHeader = bitmapInfo;
  18.     HBITMAP bmp2= (HBITMAP)CreateCompatibleBitmap(GetDC(hWnd),bitmapInfo.biWidth,bitmapInfo.biHeight);
  19.     HBITMAP oldBitmap;
  20.     unsigned char a[1000000];
  21.     unsigned char* data = a;
  22.     int i,j,index,width,height;
  23.     width = bitmapInfo.biWidth;
  24.     height = bitmapInfo.biHeight;
  25.     for(i = 0; i < height; i++)
  26.     {
  27.         for(j = 0; j < width; j++)
  28.         {
  29.             index = (width * i + j) * 3;
  30.             data[index]       = 255;  //blue
  31.             data[index + 1]   = 0;    //green
  32.             data[index + 2]   = 0;    //red
  33.         }
  34.     }
  35.     SetDIBits(hDCDoubleBuffer,bmp2,0, height, a, (BITMAPINFO*)&bitmapInfo, DIB_RGB_COLORS);
  36.     oldBitmap = (HBITMAP)SelectObject(hDCDoubleBuffer,bmp2);
  37.     BitBlt(hDC, 10, 10, bitmapInfo.biWidth, bitmapInfo.biHeight, hDCDoubleBuffer, 0, 0, SRCCOPY);
  38.     SelectObject(hDCDoubleBuffer,oldBitmap);
  39.     DeleteObject(bmp2);
  40.     DeleteObject(oldBitmap);
  41.     DeleteDC(hDCDoubleBuffer);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement