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. C / C++ / MFC
  4. What is wrong with this way of displaying a bitmap on a window?

What is wrong with this way of displaying a bitmap on a window?

Scheduled Pinned Locked Moved C / C++ / MFC
questiongraphicsdata-structures
1 Posts 1 Posters 0 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.
  • R Offline
    R Offline
    Redeemer dk
    wrote on last edited by
    #1

    I'm trying to display a bitmap on my window. Here's my code:

    BITMAPINFO biBitmap = {0};
    BITMAPINFOHEADER bihBitmap = {0};

    bihBitmap.biSize = sizeof(BITMAPINFOHEADER);
    bihBitmap.biWidth = 16;
    bihBitmap.biHeight = 16;
    bihBitmap.biPlanes = 1;
    bihBitmap.biBitCount = 24;
    bihBitmap.biCompression = BI_RGB;
    bihBitmap.biSizeImage = 0;
    bihBitmap.biClrUsed = 0;
    bihBitmap.biClrImportant = 0;

    biBitmap.bmiHeader = bihBitmap;

    PAINTSTRUCT ps;
    HDC hdc = BeginPaint(ghWnd, &ps);
    HDC hdcMem = CreateCompatibleDC(NULL);

    HBITMAP hbm = CreateDIBitmap(hdcMem, &bihBitmap, CBM_INIT, finalrgb, &biBitmap, NULL);
    HBITMAP hbmT = (HBITMAP)SelectObject(hdcMem, (HBITMAP)hbm);

    BitBlt(hdc,60,60,16,16,hdcMem,0,0,SRCCOPY);

    SelectBitmap(hdcMem,hbmT);
    DeleteDC(hdcMem);

    EndPaint(ghWnd,&ps);

    finalrgb is a pointer to an array of unsigned chars containing RGB values for a 16 by 16 pixels picture. What am i doing wrong? Thankyou!

    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