Thread: Loading BMP without WM_PAINT?

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001

    Question Loading BMP without WM_PAINT?

    I am making a BMP loader. I have a question. I already have the "Browse..." button, but how do I LOAD the BMP. I need an example for once I get the name of the selected file. Any help is appreciated!


    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  2. #2
    Registered User
    Join Date
    Dec 2001
    421 will answer this question without anyone having to write it out here.

    search first, read someone else's code and give it a go.. when you have problems... post again.

    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  3. #3
    Use LoadImage().

    Tho I'm away from my computer so not totally sure about the arguments being in the right place, in fact it's been several weeks away from the compiler so your going to have to correct the errors with it...

    case WM_CREATE:
    int screenX = GetSystemMetrics(SM_CXSCREEN);
    int screenY = GetSystemMetrics(SM_CYSCREEN);
    HDC dc = GetDC(hwnd);
    HDC hdc = CreateCompatibleDC(dc);
    HBITMAP b = CreateCompatibleBitmap(dc);
    SelectObject(hdc, b);
    PatBlt(hdc, screenX, screenY, PATCOPY);
     HBITMAP bm = (HBITMAP)LoadImage("bmp.bmp", ??, ??, IMAGE_BITMAP, LR_LOADFROMFILE, hThisInstance);
    HDC bmdc = CreateCompatibleDC(dc);
    SelectObject(dc, bmdc);
    PatBlt(bmdc, screenX, screenY, PATCOPY);
    case WM_PAINT:
    hdc = BeginPaint(hwnd, &ps);
    BitBlt(hdc <-- bmdc);  // Obviously not a literal function call...
    EndPaint(hwnd, &ps);
    ...That's the basic idea anyway. Oh and of course don't actually declare the variables in the message loop, I used it for brevity...
    ....good luck!

  4. #4
    train spotter
    Join Date
    Aug 2001
    near a computer
    Don't forget to free, with DeleteDC() / ReleaseDC() / DeleteObject() ect, all that mem you are allocating with the Create??() and CreateCompatible??() functions.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BMP Loading Structs
    By IdioticCreation in forum C++ Programming
    Replies: 4
    Last Post: 07-05-2007, 12:42 PM
  2. how come... (bmp loading)
    By Homunculus in forum Windows Programming
    Replies: 4
    Last Post: 03-21-2006, 09:00 PM
  3. OpenGL, loading BMP Textures?
    By Zeusbwr in forum Game Programming
    Replies: 12
    Last Post: 12-09-2004, 05:16 PM
  4. bmp file loading
    By linuxdude in forum Game Programming
    Replies: 9
    Last Post: 08-06-2004, 01:05 PM
  5. Loading BMP to a DirectDrawSurface
    By phatslug in forum Game Programming
    Replies: 1
    Last Post: 07-18-2002, 04:15 PM