Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. HElpppppppppppp

HElpppppppppppp

Scheduled Pinned Locked Moved Graphics
tutorialquestion
2 Posts 2 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HassanKU
    wrote on last edited by
    #1

    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ; HDC hdcWindow; static int nScreenWidth, nScreenHeight; switch (message) { case WM_CREATE: nScreenWidth = GetSystemMetrics(SM_CXSCREEN); nScreenHeight = GetSystemMetrics(SM_CYSCREEN); SetTimer( hwnd,0,2000,NULL); return 0 ; case WM_LBUTTONDOWN: { HWND tBarHandle= NULL; return 0; } case WM_PAINT: { hdc = BeginPaint (hwnd, &ps) ; hdcWindow = GetWindowDC( hwnd); HWND hDesktopWnd = GetDesktopWindow(); HDC Source = GetDC(hDesktopWnd); HDC Destination = CreateCompatibleDC(Source); HBITMAP hCaptureBitmap =CreateCompatibleBitmap(Source, nScreenWidth, nScreenHeight); SelectObject(Destination,hCaptureBitmap); BitBlt(Destination,0,0,nScreenWidth,nScreenHeight, Source, 0, 0, SRCCOPY); BitBlt(hdc,0,0 , nScreenWidth, nScreenHeight, Source, 0,0, SRCCOPY); ReleaseDC(hDesktopWnd,Destination); DeleteDC(Source); DeleteObject(hCaptureBitmap); EndPaint (hwnd, &ps) ; } return 0 ; case WM_TIMER: GetClientRect(hwnd,&rect); InvalidateRect( hwnd, &rect, true); return 0; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; } How to convert DDB format to DIB format using GETDIBits() function ????

    M 1 Reply Last reply
    0
    • H HassanKU

      LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ; HDC hdcWindow; static int nScreenWidth, nScreenHeight; switch (message) { case WM_CREATE: nScreenWidth = GetSystemMetrics(SM_CXSCREEN); nScreenHeight = GetSystemMetrics(SM_CYSCREEN); SetTimer( hwnd,0,2000,NULL); return 0 ; case WM_LBUTTONDOWN: { HWND tBarHandle= NULL; return 0; } case WM_PAINT: { hdc = BeginPaint (hwnd, &ps) ; hdcWindow = GetWindowDC( hwnd); HWND hDesktopWnd = GetDesktopWindow(); HDC Source = GetDC(hDesktopWnd); HDC Destination = CreateCompatibleDC(Source); HBITMAP hCaptureBitmap =CreateCompatibleBitmap(Source, nScreenWidth, nScreenHeight); SelectObject(Destination,hCaptureBitmap); BitBlt(Destination,0,0,nScreenWidth,nScreenHeight, Source, 0, 0, SRCCOPY); BitBlt(hdc,0,0 , nScreenWidth, nScreenHeight, Source, 0,0, SRCCOPY); ReleaseDC(hDesktopWnd,Destination); DeleteDC(Source); DeleteObject(hCaptureBitmap); EndPaint (hwnd, &ps) ; } return 0 ; case WM_TIMER: GetClientRect(hwnd,&rect); InvalidateRect( hwnd, &rect, true); return 0; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; } How to convert DDB format to DIB format using GETDIBits() function ????

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Something like this maybe... (warning - I haven't provided for a color table of any kind!! This means this won't work for a palette-based video mode or a non BI_RGB DIB, which is why I force it to BI_RGB)

      int nScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
      int nScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);

      HDC Source = ::GetDC(0);
      HDC Destination = ::CreateCompatibleDC(Source);
      HBITMAP hCaptureBitmap = ::CreateCompatibleBitmap(Source, nScreenWidth, nScreenHeight);
      HGDIOBJ hOldBm = ::SelectObject(Destination, hCaptureBitmap);
      ::BitBlt(Destination,0,0,nScreenWidth,nScreenHeight, Source, 0, 0, SRCCOPY);
      ::SelectObject(Destination, hOldBm);

      BITMAPINFO bmi;
      memset(&bmi, 0, sizeof(BITMAPINFO));
      bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);

      // Fill the BITMAPINFO struct with info from the DDB
      ::GetDIBits(Source, hCaptureBitmap, 0, nScreenHeight, NULL, &bmi, DIB_RGB_COLORS);

      // Normally, you'd want to reallocate the BITMAPINFO struct so there's enough room for
      // any color table or bitfield entries here!!

      // *optional* Adjust the BITMAPINFO struct to the desired DIB format here
      bmi.bmiHeader.biCompression = BI_RGB;

      BYTE *pPixelBytes = new BYTE[bmi.bmiHeader.biSizeImage];

      // Get the DIB pixel bytes from the DDB
      ::GetDIBits(Source, hCaptureBitmap, 0, nScreenHeight, pPixelBytes, &bmi, DIB_RGB_COLORS);

      // Do something with the DIB here

      ::ReleaseDC(0, Source);
      ::DeleteDC(Destination);
      ::DeleteObject(hCaptureBitmap);
      delete[] pPixelBytes;

      Also make sure you use the correct ReleaseDC/DeleteDC calls on the appropriate DCs. Mark

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups