Thread: I know you all must hate me but another ?

  1. #1
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001

    I know you all must hate me but another ? - Loading a BMP

    I'm trying to load a BMP image in. At first I was trying to load an external file but after repeated failures I switched to trying to load a predefined bitmap. All attempts with the predefined return with error 1814 (ERROR_RESOURCE_NAME_NOT_FOUND) when trying to load. When doing my own I get error 1812 (ERROR_RESOURCE_DATA_NOT_FOUND). File I'm trying to load:

    LRESULT CALLBACK WndProcMap (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
        static HBITMAP hBmp;
        int c1,c2, tmp;
        static int x, y;
        HINSTANCE hInstance;
        TCHAR szBuffer[100];
        switch (message)
            case WM_CREATE:
                    if ( SetCurrentDirectory("c:\\game\\wingame\\pic") == 0)
                          {tmp = GetLastError();MessageBoxPrintf( TEXT ("Error"),TEXT ("Set Directory Error Number: %i"), tmp);}
                    hInstance = (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE);
                    if ( (tmp=SearchPath (NULL, TEXT("directions"), TEXT(".bmp"), 100, szBuffer, NULL)) == 0)
                       {tmp = GetLastError();MessageBoxPrintf( TEXT ("Error"),TEXT ("Find File Error Number: %i"), tmp);}
                    MessageBoxPrintf( TEXT ("String"),TEXT ("String %d: %s"), tmp, szBuffer);
                    if ( (hBmp = LoadBitmap(hInstance, szBuffer)) ==NULL)
                         {tmp = GetLastError();MessageBoxPrintf( TEXT ("Error"),TEXT ("Load BMP Error Number: %i"), tmp);}
                    return 0;
            case WM_PAINT:
                    PAINTSTRUCT ps;
                    HDC hdc = BeginPaint (hwnd, &ps);
                    HDC hdcMem = CreateCompatibleDC (hdc);                
                    SelectObject(hdcMem, hBmp);
                    if (BitBlt (hdc, 100, 100, 30, 30, hdcMem, 0, 0, SRCCOPY) == 0)
                        {tmp = GetLastError();MessageBoxPrintf( TEXT ("Error"),TEXT ("Button Error Number: %i"), tmp);}
                    EndPaint (hwnd, &ps);              
                    return 0;
            case WM_DESTROY:
                    PostQuitMessage (0);
                    return 0;
            case WM_SIZE:
                    x = LOWORD (lParam);
                    y = HIWORD (lParam);
                    return 0;
        return DefWindowProc (hwnd, message, wParam, lParam);
    As a side note: I have tried to use LoadImage() but when I try to do something like hBmp = LoadImage (......); I get an error when compiling saying "ANSI C++ forbids implicit conversion from `void *' in assignment"
    Last edited by Thantos; 08-15-2003 at 07:53 AM.

  2. #2
    train spotter
    Join Date
    Aug 2001
    near a computer

    hBmp =(HBITMAP) LoadImage (......);


    Ensure that you have added the bitmap to the exe thru the resource editor and given it an ID. That is it must be contained in the exe not as an external file.

    hImage=(HBITMAP) LoadImage( hInstance, sImage, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    SelectObject(hdcMem, hBmp);
    should be
    hOld= SelectObject(hdcMem,hBmp);
    //yada yada
    SelectObject(hdcMem,hOld);//put the old GDI object back then the DC will delete correctly
    Last edited by novacain; 08-15-2003 at 01:43 AM.
    "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

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    >>I know you all must hate me but another ?<<
    I only hate it when people use stupid thread titles that aren't relevant to the actual subject
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Yea sorry about that Hammer. Edited title to make it clearer. Was on my last legs when posted last night.

    Ok I think 99% of the problem is that I'm not using a Resource file. Tried looking all over my compilier (Dev C++ ver and it doesn't seem to have anything for making them. Is there a third party software that is good for making RC files?

    Edit: Ok just noticed that editing the first post's title doesn't change the thread's title
    Last edited by Thantos; 08-15-2003 at 08:19 AM.

  5. #5
    Registered User
    Join Date
    Oct 2001
    you could just use a text editor to make the resource file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tabbed Windows with MDI?
    By willc0de4food in forum Windows Programming
    Replies: 25
    Last Post: 05-19-2005, 10:58 PM
  2. Pet Peeves
    By Srg Pepper in forum A Brief History of
    Replies: 29
    Last Post: 10-03-2002, 11:34 AM
  3. I hate string parsing with a passion
    By DavidP in forum A Brief History of
    Replies: 2
    Last Post: 03-19-2002, 07:30 PM
  4. Man, I really hate Microsoft...
    By Cheeze-It in forum A Brief History of
    Replies: 34
    Last Post: 09-12-2001, 08:50 AM