News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Embed an image in an executable

Started by skywalker, January 16, 2006, 01:59:22 PM

Previous topic - Next topic

skywalker

I don't have the code with me but I can remember enuf details.

It embeds an  image file into the .exe.

It used rc simplebitmap.rc or something like that.

I looked thru the masm examples and couldn't find one.

I think the .rc file contained a statement showing the path to the image file.

Thanks.


Tedd

Have a banana

[attachment deleted by admin]
No snowflake in an avalanche feels responsible.

Vortex

skywalker,

You can use Ernst Murphy's image library to display images from memory. Check the BmpFromMem example in the attachment.

http://www.masmforum.com/simple/index.php?action=dlattach;topic=937.0;id=1639

skywalker

Quote from: Vortex on January 16, 2006, 06:31:43 PM
skywalker,

You can use Ernst Murphy's image library to display images from memory. Check the BmpFromMem example in the attachment.

http://www.masmforum.com/simple/index.php?action=dlattach;topic=937.0;id=1639

This compiles with no errors, but it isn't displaying the picture.
I modified some old code which didn't have the .rc file, I probably
messed it up.

Thanks.

This is in bitmap.rc

#define IDB_MAIN 801

IDB_MYBMP BITMAP "jakob.bmp"

Bat file that makes the .exe.

ml /c /coff /Cp jakob.asm
rc bitmap.rc
link /SUBSYSTEM:WINDOWS /LIBPATH:c:\masm32\lib jakob.obj bitmap.res


; jakob.asm 
;
; ml /c /coff /Cp jakob.asm
; rc bitmap.rc
; link /SUBSYSTEM:WINDOWS /LIBPATH:c:\masm32\lib jakob.obj bitmap.res

.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
IDB_MAIN   equ 801

.data
ClassName db "SimpleWin32ASMBitmapClass",0
AppName  db "Jakob at 2 yrs",0

.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hBitmap dd ?

.code
start:
   invoke GetModuleHandle, NULL
   mov    hInstance,eax
   invoke GetCommandLine
   mov    CommandLine,eax
   invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
   invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
   LOCAL wc:WNDCLASSEX
   LOCAL msg:MSG
   LOCAL hwnd:HWND
   mov   wc.cbSize,SIZEOF WNDCLASSEX
   mov   wc.style, CS_HREDRAW or CS_VREDRAW
   mov   wc.lpfnWndProc, OFFSET WndProc
   mov   wc.cbClsExtra,NULL
   mov   wc.cbWndExtra,NULL
   push  hInstance
   pop   wc.hInstance
   mov   wc.hbrBackground,COLOR_WINDOW+1
   mov   wc.lpszMenuName,NULL
   mov   wc.lpszClassName,OFFSET ClassName
   invoke LoadIcon,NULL,IDI_APPLICATION
   mov   wc.hIcon,eax
   mov   wc.hIconSm,eax
   invoke LoadCursor,NULL,IDC_ARROW
   mov   wc.hCursor,eax
   invoke RegisterClassEx, addr wc
   

INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,0,0,1024,768,NULL,NULL,\
           hInst,NULL



;INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
;           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
;           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
;           hInst,NULL
   mov   hwnd,eax
   invoke ShowWindow, hwnd,SW_SHOWNORMAL
   invoke UpdateWindow, hwnd
   .while TRUE
      invoke GetMessage, ADDR msg,NULL,0,0
      .break .if (!eax)
      invoke TranslateMessage, ADDR msg
      invoke DispatchMessage, ADDR msg
   .endw
   mov     eax,msg.wParam
   ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
   LOCAL ps:PAINTSTRUCT
   LOCAL hdc:HDC
   LOCAL hMemDC:HDC
   LOCAL rect:RECT
   .if uMsg==WM_CREATE
      invoke LoadBitmap,hInstance,IDB_MAIN
      mov hBitmap,eax
   .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
   .elseif uMsg==WM_DESTROY
      invoke DeleteObject,hBitmap
      invoke PostQuitMessage,NULL
   .ELSE
      invoke DefWindowProc,hWnd,uMsg,wParam,lParam      
      ret
   .ENDIF
   xor eax,eax
   ret
WndProc endp
end start

Vortex

Did you check Iczelion's Tutorial #25?

Tutorial 25: Simple Bitmap

skywalker

Quote from: Vortex on January 17, 2006, 07:31:33 PM
Did you check Iczelion's Tutorial #25?

Tutorial 25: Simple Bitmap

I only have thru #24.
I got the answer already.


zooba

Quote from: skywalker on January 17, 2006, 11:39:36 AM
Bat file that makes the .exe.

ml /c /coff /Cp jakob.asm
rc bitmap.rc
link /SUBSYSTEM:WINDOWS /LIBPATH:c:\masm32\lib jakob.obj bitmap.res

If that's the MS linker, you'll need to use CVTRES first and link the object file.

Pelle's linker will accept .RES files.

skywalker

Quote from: zooba on January 17, 2006, 09:45:31 PM
Quote from: skywalker on January 17, 2006, 11:39:36 AM
Bat file that makes the .exe.

ml /c /coff /Cp jakob.asm
rc bitmap.rc
link /SUBSYSTEM:WINDOWS /LIBPATH:c:\masm32\lib jakob.obj bitmap.res

If that's the MS linker, you'll need to use CVTRES first and link the object file.

Pelle's linker will accept .RES files.

I made a mistake in bitmap.rc.

A year ago I tried to get help with a jpeg embedded in the file but it didn't get real far.
Reckin not much incentive for MS to support non-BMP stuff. :-)