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

Started by
9 comments, last by cambalinho 7 years, 10 months ago

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

Advertisement
This is the same problem you had with icons. The correct resource type is called "BITMAP" not "bmp".

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

but i get the icons, but not the BITMAP

Your resource file specifies your bitmap file as type "bmp" which is not correct. You need to change the bmp here:

subzero bmp


Change it to BITMAP.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

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()?

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.

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?

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).

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)

I don't really get your logic, but for all things Microsoft, you should look it up on MSDN.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms648009%28v=vs.85%29.aspx

This topic is closed to new replies.

Advertisement