Hi Charles,
in my little project I use this function (it is derived from BCX_LOADBMP):
function LoadBMP(string F, int ii = 0, int t = 0) as sys
if t then t = LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
if ii then
return LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(ii),IMAGE_BITMAP,0,0,t)
end if
return LoadImage(null,F,IMAGE_BITMAP,0,0,LR_LOADFROMFILE or t)
end function
The function can be used to load a bmp file directly or as a resource of a .res file. I tried to use MAKEINTRESOURCE(II), but this does not work. Using simply the number woud work, but I wonder if I coud use MAKEINTRESOURCE usable too.
I found your macro:
def MAKEINTRESOURCE "#%1"
in winuser.h there is:
#define MAKEINTRESOURCEA(i) ((LPSTR)((ULONG_PTR)((WORD)(i))))
Would this be equivalent to the macro?
I tried to do it similar like in C project files, so in the rc file I use:
#define IDB_HBKGND 1000
#define IDB_FISH_1 1001
...
IDB_HBKGND BITMAP DISCARDABLE "Aquarium.bmp"
IDB_FISH_1 BITMAP DISCARDABLE "Fish_1.bmp"
......
in the .o2bas file I use:
#define IDB_HBKGND 1000
#define IDB_FISH_1 1001
...etc
As mentioned if I use only the number ii in LoadBmp the app will work, but if I print the results with MAKEINTRESOURCE then I get this:
ii = 1000, makeintresource(ii) = #ii
ii = 1001, makeintresource(ii) = #ii
...etc
and the app will fail. Is it possible to use MAKEINTRESOURCE wisely? Otherwise I will ignore this macro.
To handle variables MAKEINTRESOURCE needs to be a function:
function MAKEINTRESOURCE(int i) as string
return "#"+str(i)
end function
Alternatively:
function LoadBMP(string F, int ii = 0, int t = 0) as sys
if t then t = LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
if ii then
string sii="#"+str(ii) 'MAKEINTRESOURCE(ii)
return LoadImage(GetModuleHandle(0),sii,IMAGE_BITMAP,0,0,t)
end if
return LoadImage(null,F,IMAGE_BITMAP,0,0,LR_LOADFROMFILE or t)
end function
Thank you Charles. The function worked perfectly for me. It also worked for function LoadIcon in the WNDCLASSEX wc structure: Somehow this looks a bit like magic to me. MAKEINTRESOURCE makes an int 1000 to a string "#1000" which then can be used like a number in e.g. function LoadImage. I think something is happening behind the scenes?
This is a quirk of early Windows where some functions read low value params as literal integers but also interpret high values as string pointers. It might be an elegant trick but also a source of confusion when some functions can do this and others cannot.