CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2013
    Posts
    4

    [RESOLVED] Cannot load bitmap resource onto button, but can do so if I load the filesystem file

    So I'm trying to load a bitmap onto a button, which I can do if I get the bitmap handle like this:

    LoadImage(NULL, _T("C:\\Users\\Luis\\Documents\\Visual Studio 2012\\Projects\\dlltest\\Debug\\status1.bmp"), IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE | LR_CREATEDIBSECTION);

    However, when I attempt to load this same image from a resource as follows it doesn't work:

    LoadImage(hInstance, MAKEINTRESOURCE(IDB_STATUS1), IMAGE_BITMAP, NULL, NULL, LR_CREATEDIBSECTION);

    I had also tried LoadBitmap without success:

    LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_STATUS1));

    None of these lines produces a NULL result, so they seem to succeed, but only the first will actually load a bitmap onto a button on my dialog:

    SendMessage(hBtn1,BM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)hBmp);

    Is it possible that either or both of these last two calls cannot locate the actual requested bitmap and so they returned a valid handle to like, a blank bitmap? Or would a NULL result failure be the only expected alternative to complete success? I do load the dialog from the same resource and it works just fine.

    Having to load these bitmaps from external files makes deployment a little less friendly. Any clues what might be the problem?

  2. #2
    Join Date
    May 2013
    Posts
    4

    Re: Cannot load bitmap resource onto button, but can do so if I load the filesystem f

    Okay, I figured it out. It was because I was destroying the bitmaps after I loaded them to my buttons:

    DeleteObject(hBmp);

    Not doing this causes it to all look right, but I'll have to check to figure out if I have any cleanup responsibility, which I had just assumed I do.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured