hi,
i was wondering if it's possible to load bitmaps using strings(ie user input)
for example my resource file would have:

IDB_MAIN BITMAP ?


.data would be:
thebmp dd "whatever.bmp"


how can i get thebmp into IDB_MAIN?

thanks
Posted on 2003-02-27 13:02:42 by Homer
I'm not sure that I understand your question. If you are looking to load a bitmap that already resides in your resource file you can use the user-input to identify it then LoadImage or LoadBitmap to give it a handle.

invoke LoadImage,hInst,lpszName,IMAGE_BITMAP,cx,cy,NULL

OR

invoke LoadBitmap,hInst,lpBitmapName

Sorry my Win2K crashed half way through this post.

If you want to move a bitmap from memory into your resource section you can use UpdateResource:

invoke UpdateResource,hFile,RT_BITMAP,lpResName,wLanguage,lpData,cbData

You should note that lpData point to the data to be stored in the resource file, it only points to the raw data, a handle will not do. You have to convert the handle to a memory position then use that to point to the data.

BTW this topic should be in the MAIN section

Donkey
Posted on 2003-02-27 14:55:50 by donkey
does the resource have to exist to be updated?

edit: because i can't do IDB_MAIN BITMAP ?

i get "file not found" =<

Right now I'm trying to get input from an editwindow and button such as mypic.bmp and have LoadBitmap display the inputed .bmp

but i'm afraid i don't really understand what i'm doing. I'm a total newb who discovered masm32, the win32 api (i didn't know asm could program windows!) and Izcelion's Tut's, after registering for First Semester Assembly.:stupid:
Posted on 2003-02-28 01:51:18 by Homer
I'm not sure if you can create a resource this way, i've never tried but i doubt it. When you used UpdateResource did you get the file handle from BeginUpdateResource and close it with EndUpdateResource ? Also a program can't update itself, you need write access to the executable file in order to update it. Once your running a file you can no longer gain the proper access.

invoke BeginUpdateResource, lpFileName, bDeleteExistingResources

mov eax,hFile
invoke UpdateResource, hFile, RT_BITMAP, lpResName, wLanguage ,lpData,cbData
invoke endUpdateResource,hFile,fDiscard


Post your code, maybe I can help a little more if you show exactly what you want to do. If it's a simple matter of loading a bitmap, why are you changing the resource file ?

Donkey

EDIT: You should know that when you load a bitmap from a file you use LoadImage, not LoadBitmap. LoadBitmap is only for resource based bitmaps, with LoadImage you can load a bitmap directly from a BMP file and select it into a DC. Or alternatively if you are displaying the bitmap in an imagebox (Static) you use the STM_SETIMAGE message.

PS: This sounds alot like homework to me
Posted on 2003-02-28 02:02:42 by donkey
it pretty much goes like this:

.data
...
ImageName db "C:\masm32\BIN\louis.bmp"
...

.data?
...
hBitmap dd ?
...

.code
start:
...
WinMain endp

WndProc...
LOCAL hdc:HDC
LOCAL ps:PAINTSTRUCT
LOCAL rect:RECT
LOCAL hMemDC:HDC
...
.ELSEIF uMsg==WM_LBUTTONDOWN
invoke LoadImage, hInstance,ImageName,IMAGE_BITMAP,100,100,LR_LOADFROMFILE
mov hBitmap,eax
invoke InvalidateRect,hWnd,NULL,TRUE
...
.ELSEIF uMsg==WM_PAINT

invoke BeginPaint,hWnd, ADDR ps
mov hdc,eax
invoke CreateCompatibleDC,hdc
mov hMemDC,eax
invoke SelectObject, hMemDC,hBitmap
invoke GetClientRect,hWnd,addr rect
invoke BitBlt,hdc,0,0,rect.right,rect.bottom,hMemDC,0,0,SRCCOPY
invoke DeleteDC,hMemDC
invoke EndPaint,hWnd,addr ps
...
WndProc endp
end start
Posted on 2003-02-28 03:08:48 by Homer
Looks OK to me, look for MASM32\Example4\BITBLT, it shows an example of exactly what you want to do. I'd change the wndow proc to have your paint routine seperate. It's good programming practice to select the old object into a device context before you release or delete it. Besides that I can't see anything really wrong with your paintproc. I tested with this proc and it worked fine...
invoke BeginPaint,hDlg, ADDR ps

mov hdc,eax
invoke CreateCompatibleDC,hdc
mov hMemDC,eax
invoke SelectObject, hMemDC,hBitmap
mov OldDC,eax
invoke GetClientRect,hDlg,addr rect
invoke BitBlt,hdc,0,0,rect.right,rect.bottom,hMemDC,0,0,SRCCOPY
invoke SelectObject,hMemDC,OldDC
invoke DeleteDC,hMemDC
invoke EndPaint,hDlg,addr ps
Donkey
Posted on 2003-02-28 09:56:03 by donkey
Sh*t I just noticed...

ImageName db "C:\masm32\BIN\louis.bmp",0

ALWAYS zero terminate your strings

Donkey
Posted on 2003-02-28 10:16:09 by donkey
Well that is for LoadBitmap, and remember i need LoadImage so I can dynamically load images.

the code i showed you


.ELSEIF uMsg==WM_LBUTTONDOWN
invoke LoadImage, hInstance,ImageName,IMAGE_BITMAP,100,100,LR_LOADFROMFILE
mov hBitmap,eax
invoke InvalidateRect,hWnd,NULL,TRUE


returns no errors but when i click the mouse it does not paint the image :confused:
any ideas?

edit: thx for notice the missing ",0" but i'm afraid that didn't solve the puzzle
Posted on 2003-02-28 19:53:18 by Homer
LoadImage and LoadBitmap in this case only differ in the source of the bitmap. A Bmp handle is a Bmp handle no matter where it comes from. If you are getting file not found then I would check the path and filename or your algorithm that generates it. The paint proc you supplied will paint a valid bitmap to the window, that is certain. The only thing that can go wrong at this point is if you return a handle value of NULL, you have not checked for that possibility. If the file is not found or the bitmap is not valid the LoadImage routine will return NULL and you can use GetLastError to find out what happened. Outside of that there is nothing I can really suggest, the routine works here with the LoadImage function as well as with LoadBitmap.
invoke LoadImage,  hInstance, ImageName, IMAGE_BITMAP, 100, 100, LR_LOADFROMFILE

test eax,eax
jz @F
mov hBitmap,eax
invoke InvalidateRect,hWnd,NULL,TRUE
@@:
;Handle you error here
Donkey
Posted on 2003-02-28 20:11:15 by donkey
Thanks I'll take a look at GetLastError.

BTW I've been seeing @@: alot lately. What is that?
Posted on 2003-03-01 09:30:13 by Homer
@@: is an Anonymous Label. If you use alot of labels in your code and they are just there to be part of simple loops or simple jumps you can use anonymous labels that don't have to have unique names and @F and @B to address them. @F refers to the next occurance of @@: and @B refers to the previous one.

Read through the ASMINTRO.HLP in your MASM32\HELP folder, it will explain different loop and branch techniques as well as the various addressing modes. It is a very good introduction for the beginning programmer and only takes a little while to get through.

Donkey
Posted on 2003-03-01 10:23:31 by donkey
Great topic, If you already finish Send me the complete function like this




Invoke MyOwnLoadBitmap,hDC,eX,eY,addr FileName




so Im only have to 'Invoke,hDC,X,Y,addr FIle'. Thanks if you done it.:alright:
Posted on 2003-03-03 09:46:20 by realvampire
OH SHUCKS!
It's so simple!
I forgot to use ADDR to point to the image!
lolz

Posted on 2003-03-04 02:15:53 by Homer