• Advertisement
Sign in to follow this  

why i don't get the HBITMAP from file\resource?

This topic is 695 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

HBITMAP bmpBitmap = LoadBitmap((HINSTANCE)GetWindowLong(WindowMain, GWL_HINSTANCE),MAKEINTRESOURCE(strResource));

by some reason, i get NULL on bmpBitmap.

 

on resource.h:

#define songoku 101
#define subzero 102

the resourse ID is correct and the folder name:

#include "resource.h"

MAINICON ICON  "x-7.ico"
songoku ICON "C:\\Users\\Cambalinho\\Documents\\CodeBlocks\\classcontrols\\bin\\Release\\x-7.ico"
subzero bmp "C:\\Users\\Cambalinho\\Documents\\CodeBlocks\\classcontrols\\bin\\Release\\o_5c3b5bae618d9968-2.bmp"

for now, i only get problems with bmp.

can anyone advice me?

i even tryied with LoadImage(), i get NULL too

Share this post


Link to post
Share on other sites
Advertisement

i did that.

 but see these function:

string GetResourceType(DWORD ResourceID)
{
    HRSRC rscFind;
    rscFind=FindResource(GetModuleHandle(NULL),(LPCTSTR)  MAKEINTRESOURCE(ResourceID), "anicur");
    if(rscFind!=NULL)
        return "ANICUR";
    rscFind=FindResource(GetModuleHandle(NULL),(LPCTSTR)  MAKEINTRESOURCE(ResourceID), "aniico");
    if(rscFind!=NULL)
        return "ANIICO";
    rscFind=FindResource(GetModuleHandle(NULL), (LPCTSTR) MAKEINTRESOURCE(ResourceID), "bmp");
    if(rscFind!=NULL)
        return "BMP";
    rscFind=FindResource(GetModuleHandle(NULL), (LPCTSTR) MAKEINTRESOURCE(ResourceID), RT_BITMAP);
    if(rscFind!=NULL)
        return "BMP";
    rscFind=FindResource(GetModuleHandle(NULL),(LPCTSTR)  MAKEINTRESOURCE(ResourceID), "cur");
    if(rscFind!=NULL)
        return "CUR";

    rscFind=FindResource(GetModuleHandle(NULL), (LPCTSTR) MAKEINTRESOURCE(ResourceID), "ico");
    if(rscFind!=NULL)
        return "ICO";
    rscFind=FindResource(GetModuleHandle(NULL), (LPCTSTR) MAKEINTRESOURCE(ResourceID), RT_GROUP_ICON);
    if(rscFind!=NULL)
        return "ICO";
    rscFind=FindResource(GetModuleHandle(NULL), (LPCTSTR) MAKEINTRESOURCE(ResourceID), RT_ICON);
    if(rscFind!=NULL)
        return "ICO";

    rscFind=FindResource(GetModuleHandle(NULL), (LPCTSTR) MAKEINTRESOURCE(ResourceID), "gif");
    if(rscFind!=NULL)
        return "GIF";

    return "OTHER";
}

these function returns 'BMP'. means that the FindResource() found it.

so what i'm doing wrong with LoadBitmap()?

Share this post


Link to post
Share on other sites

FindResource finds a resource of the type you specify.

It can find any type of resource, so it will find your resource of type "bmp"

 

LoadBitmap looks for a resource of type "BITMAP", and will ignore all resources of other types, so it will not find the resource.

Share this post


Link to post
Share on other sites

that's why i had changed that.

resource.rc:

#include "resource.h"

MAINICON ICON  "x-7.ico"
songoku ICON "C:\\Users\\Cambalinho\\Documents\\CodeBlocks\\classcontrols\\bin\\Release\\x-7.ico"
subzero BITMAP "C:\\Users\\Cambalinho\\Documents\\CodeBlocks\\classcontrols\\bin\\Release\\balao.bmp"

on resource.h:

#define songoku 101
#define subzero 102

see these files... what i'm doing wrong?

Share this post


Link to post
Share on other sites

The only thing that can go wrong is the HINSTANCE you pass. In the call to LoadBitmap, you use

(HINSTANCE)GetWindowLong(WindowMain, GWL_HINSTANCE)

By default, that would be the HINSTANCE you passed to WNDCLASS/WNDCLASSEX you registered before you created the HWND via CreateWindow/CreateWindowEx. The association is the class name.

 

With FindResource, you obtain the HINSTANCE via

GetModuleHandle(NULL)

which is used to get the HINSTANCE of the exe that started the process.

 

In the rare case that these two differ (e.g. the code is split between EXE and DLL-s), you should call LoadBitmap with GetModuleHandle(NULL).

Share this post


Link to post
Share on other sites

thanks for all...

i need ask more 1 thing that it's between RC file and FindResource() type consts:

 

FindResource()       ->  RC file

RT_BITMAP            -> BITMAP

RT_GROUP_ICON  -> ICON

 

i'm sorry, can you give me the rest of combination?

(i can't find an information for that.. and not the rest of const's)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement