Errors with resource bitmaps....HELP PLEASE!

This is a discussion on Errors with resource bitmaps....HELP PLEASE! within the Windows Programming forums, part of the Platform Specific Boards category; Ok here's some code: I first declared: static HBITMAP loadLogo ; static int cxClient, cyClient, cxSource, cySource; BITMAP bitmap ; ...

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

    Question Errors with resource bitmaps....HELP PLEASE!

    Ok here's some code:

    I first declared:

    static HBITMAP loadLogo ;
    static int cxClient, cyClient, cxSource, cySource;
    BITMAP bitmap ;
    HDC hdc, hdcMem ;
    HINSTANCE hInstance ;
    PAINTSTRUCT ps;

    Then:

    case WM_CREATE:
    loadLogo=LoadBitmap(hInst, MAKEINTRESOURCE(402));

    if(!loadLogo)
    {
    MessageBox(hwnd, "Error", "Error", 1);
    }

    GetObject(loadLogo, sizeof(loadLogo), &bitmap);
    cxSource=bitmap.bmWidth;
    cySource=bitmap.bmHeight;
    break;
    case WM_PAINT:
    hdcMem=CreateCompatibleDC(hdc);
    SelectObject(hdcMem, loadLogo);
    BitBlt(hdc, 1, 1, 50, 50, hdcMem, 0, 0, SRCCOPY);
    break;
    case WM_DESTROY:
    DeleteObject(loadLogo);

    PostQuitMessage(0); /* send a WM_QUIT to the message queue */
    break;

    But it shows the error message that is used for if(!loadLogo), and it shows up, and then my BMP doesn't load. What do I do?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    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 The15th's Avatar
    Join Date
    Aug 2001
    Posts
    125
    >>loadLogo=LoadBitmap(hInst, MAKEINTRESOURCE(402));
    402???
    is that what you called your bitmap inside the reource. thats all i can think of. try renaming your bitmap to IDB_BITMAP1 and then call loadLogo=LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1)); and see what happens.
    arrh, i got nothing good to say.
    http://www.praxis1.vic.edu.au/home/dcola/

  3. #3
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    on my program with my resource bitmap, when I minimize the program and I pop it back up the Bitmap dissapears. Could anyone help?

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    Put this in your code:
    Code:
    case WM_PAINT:
    {
         // draw bitmap to window
    }
    break;
    the WM_PAINT message is sent to your window every time your window needs repainting.

  5. #5
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    howbout we pretend you didn't say that.

  6. #6
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    > on my program with my resource bitmap, when I minimize the program and I pop it back up the Bitmap dissapears. Could anyone help? <

    Where is the code that puts the bitmap on the window? If it is in WM_PAINT, then it should repaint the picture right on the client area when you maximize it.

    Or, you know what might help, is set the WNDCLASS's style property to CS_HREDRAW | CS_VREDRAW. This tells the window to repaint every time that the height and/or width is changed.

    Try this out and tell me if it works.

    --Garfield
    1978 Silver Anniversary Corvette

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Xterria
    Sounds like you need to invoke a paint msg with InvalidateRect() or UpdateWindow() after the maximise.
    It could also be that the BMP was drawn to the HDC but when the screen minimised, then a new blank HDC is drawn on maximise (in the paint function). Check that on maximise you are coping your framebuffer back to the screen HDC.

    SyntaxBubble
    Not exactly the way to do paint calls. OK unless it is not the area that needs paint. Look in the help for BeginPaint(), GetUpdateRect(), IsRectEmpty(), EndPaint() and in particular the PAINTSTRUCT.
    You create a DC compat with HDC, where do you get HDC from? Try GetDC() (look it up) and creatcompat with that DC. Remember each Object you create/get MUST be released/deleted or you will loose memory.
    Any HDC MUST be put back EXACTLY as you found it before you Delete/release it.

    HDC's declared in the callback are also a very bad idea as they will loose their value as soon as the callback is left and get a new one when it returns. Each time this costs memory. Try putting a break point on the main switch to see how many times the callback function is called.

    Try
    Code:
    case WM_CREATE: 
    loadLogo=LoadBitmap(hInst, MAKEINTRESOURCE (ID_OFMYBITMAP)); 
    if(!loadLogo) 
    { 
        sprintf(sBuffer,"LoadBitmap failed in MainCallback with error#%d.",GetLastError());
        MessageBox(hwnd, sBuffer, "Error", MB_ICONERROR|MB_OK); 
    }
    At least this will tell you where in your code the error occured, what the error was and so give you a chance to fix it.
    "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

  8. #8
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    Sounds like you need to invoke a paint msg with InvalidateRect() or UpdateWindow() after the maximise.
    What means that?
    How do I do updatewindow() AFTER the maximize?
    Last edited by Xterria; 11-11-2001 at 10:11 PM.

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Process your WM_SIZE, or WM_SIZEING ect, msg and look for the WPARAM==SIZE_MAXIMISED

    If you 'wipe' the area with another window does the BPM reappear? Before you minimise if you 'wipe' the BMP with another window so it needs to be repainted does it?
    By 'wipe' I mean get another small window, say your resource meter, volume control ect and drag it over the BMP. If your paint is working it should redraw.
    Last edited by novacain; 11-11-2001 at 10:44 PM.
    "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

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Here is a function to use in WM_PAINT

    Code:
    void   RePaint(HWND hDlg,HDC hdcScreen)
    {
    RECT                  Rect;
    PAINTSTRUCT           ps;
    
    GetUpdateRect(hWnd, &Rect, 0);
    if (IsRectEmpty(&Rect))
       {
       GetClientRect(hWnd,&Rect);
       }
    BeginPaint(hWnd, &ps);
    BitBlt(ps.hdc, Rect.left, Rect.top, Rect.right - Rect.left, Rect.bottom - Rect.top, hdcScreen, Rect.left, Rect.top, SRCCOPY);
    EndPaint(hWnd, &ps);
    }
    I have another HDC, exactly the same as the hdcScreen called hdcBuffer.
    All drawing is done to the hdcBuffer. When it is ready it is BitBlt'ed to the hdcScreen. The area draw is known and this is sent for painting using InvalidateRect(), calling the paint function above.
    I keep the HWND, HDC's(screen and Buffer) ect in an array of structures. I use defined values to navigate thru the array. I set the initial values to NULL. I set them up in WM_CREATE for the dlg as needed and then check on close if they have been allocated and so free the resources.
    "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

  11. #11
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    nevermind, nothings working. I'll just get rid of the bitmap...

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    To create your DC's
    HWND hWnd;//the HWND of the ctrl or dlg you want to repaint
    HDC hdc;//temp HDC
    HDC hdcBuffer;//the hdc to draw to
    HDC hdcScreen;//the hdc drawn finally to the screen
    //iWidth & iHeight are calculated from the ClientRect of the ctrl or dlg (GetClientRect (hWnd, &CientRect); )
    Code:
    hdc=GetDC(hWnd);
    hdcScreen=CreateCompatibleDC(hdc);
    hBitmap=CreateCompatibleBitmap(hdc, iWidth, iHeight );
    //save the bitmap already in the hdc to be returned at close 
    hSysBitmap=SelectObject(hdcScreen,hBitmap);
    ReleaseDC(hWnd,hdc);
    //paint it white
    BitBlt(hdcScreen, 0, 0, iWidth, iHeight, hdcScreen, 0, 0, WHITENESS);
    //Repeat for hdcBuffer.
    //Load your bitmap and draw/select to the hdcBuffer
    //BitBlt hdcBuffer onto hdcScreen
    InvalidateRect(hWnd,&ClientRect,FALSE);
    //Use the RePaint() under the WM_PAINT in your callback

    Clean up the hdc's by putting the system bitmaps back at close with SelectObject() (catch the returns). Then DeleteObject() the comp bitmaps and finally DeleteDC() the two hdc's.

    Simple huh?
    "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

  13. #13
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    XTerria
    Your your home page is not working with Netscape 4.7.

    The HTML for the popup works but not much else.

    I went to the tute index and first tute, got the page from your HTML, but again no display.
    "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

  14. #14
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    Yeah I know, it only works with Internet Explorer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting out a resource manager
    By psychopath in forum Game Programming
    Replies: 1
    Last Post: 11-10-2008, 07:12 PM
  2. unmanaged resource
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2008, 04:23 AM
  3. Winsock compilation errors
    By jmd15 in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-03-2005, 09:00 AM
  4. MFC: Multiple clicks shows multiple bitmaps - how?
    By BrianK in forum Windows Programming
    Replies: 0
    Last Post: 06-20-2004, 08:25 PM
  5. Loading Resource Bitmaps
    By Xterria in forum Windows Programming
    Replies: 10
    Last Post: 11-11-2001, 01:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21