flat assembler
Message board for the users of flat assembler.

Index > Windows > Displaying Bitmaps From Resources

Author
Thread Post new topic Reply to topic
me



Joined: 21 Jun 2003
Posts: 7
me 19 Sep 2003, 10:16
I'm wondering if any one could post an example of how to display bitmaps in a window using a custom pattern in pure fasm. With out the need of any dll or porting of code. This would be help full. Thanks
Post 19 Sep 2003, 10:16
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8434
Location: Kraków, Poland
Tomasz Grysztar 19 Sep 2003, 10:58
What do you mean by "custom pattern"?

There's a small example of displaying bitmap from resource in the attachment.


Description:
Download
Filename: bitmap.zip
Filesize: 114.46 KB
Downloaded: 703 Time(s)

Post 19 Sep 2003, 10:58
View user's profile Send private message Visit poster's website Reply with quote
80286



Joined: 01 May 2015
Posts: 15
80286 05 May 2015, 13:59
Tomasz Grysztar wrote:
There's a small example of displaying bitmap from resource in the attachment.

Should this example work with actual FASM 1.71.39 ?
I get errors and can't yet solve them by myself.

edit:
Same error in another older script ( http://board.flatassembler.net/topic.php?t=180 )
Error says: missing end directive
and points to proc32.inc Line 53


Last edited by 80286 on 05 May 2015, 14:12; edited 1 time in total
Post 05 May 2015, 13:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20685
Location: In your JS exploiting you and your system
revolution 05 May 2015, 14:09
Here is a modified version for the current macro set.
Code:
; template for program using standard Win32 headers

format PE GUI 4.0
entry start

include 'win32a.inc'

section '.data' data readable writeable

  _title db 'BitBlt demonstation',0
  _class db 'FASMWIN32',0

  mainhwnd dd ?
  hinstance dd ?
  hbitmap dd ?

  msg MSG
  wc WNDCLASS

section '.code' code readable executable

  start:

        invoke  GetModuleHandle,0
        mov     [hinstance],eax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        mov     [wc.style],0
        mov     [wc.lpfnWndProc],WindowProc
        mov     [wc.cbClsExtra],0
        mov     [wc.cbWndExtra],0
        mov     eax,[hinstance]
        mov     [wc.hInstance],eax
        mov     [wc.hbrBackground],COLOR_BTNFACE+1
        mov     [wc.lpszMenuName],0
        mov     [wc.lpszClassName],_class
        invoke  RegisterClass,wc

        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,192,192,NULL,NULL,[hinstance],NULL
        mov     [mainhwnd],eax

        invoke  LoadBitmap,[hinstance],IDR_LOGO
        mov     [hbitmap],eax

  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        or      eax,eax
        jz      end_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop

  end_loop:
        invoke  ExitProcess,[msg.wParam]

proc WindowProc, hwnd,wmsg,wparam,lparam
        locals
                paintstruct PAINTSTRUCT
        endl
        push    ebx esi edi
        cmp     [wmsg],WM_DESTROY
        je      wmdestroy
        cmp     [wmsg],WM_PAINT
        je      wmpaint
  defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     finish
  wmpaint:
        lea     ebx,[paintstruct]
        invoke  BeginPaint,[hwnd],ebx
        mov     edi,eax
        invoke  CreateCompatibleDC,edi
        mov     esi,eax
        invoke  SelectObject,esi,[hbitmap]

        invoke  BitBlt,edi,0,0,150,150,\
                       esi,0,0,SRCCOPY

        invoke  DeleteDC,esi
        invoke  EndPaint,[hwnd],ebx
        jmp     finish
  wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  finish:
        pop     edi esi ebx
        ret
endp

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL',\
          gdi,'GDI32.DLL'

  import kernel,\
         GetModuleHandle,'GetModuleHandleA',\
         ExitProcess,'ExitProcess'

  import user,\
         RegisterClass,'RegisterClassA',\
         CreateWindowEx,'CreateWindowExA',\
         DefWindowProc,'DefWindowProcA',\
         GetMessage,'GetMessageA',\
         TranslateMessage,'TranslateMessage',\
         DispatchMessage,'DispatchMessageA',\
         LoadCursor,'LoadCursorA',\
         LoadIcon,'LoadIconA',\
         LoadBitmap,'LoadBitmapA',\
         BeginPaint,'BeginPaint',\
         EndPaint,'EndPaint',\
         PostQuitMessage,'PostQuitMessage'

  import gdi,\
         CreateCompatibleDC,'CreateCompatibleDC',\
         SelectObject,'SelectObject',\
         BitBlt,'BitBlt',\
         DeleteDC,'DeleteDC'

section '.rsrc' resource data readable

  IDR_LOGO = 1

  directory RT_BITMAP,bitmaps

  resource bitmaps,\
           IDR_LOGO,LANG_ENGLISH+SUBLANG_DEFAULT,logo

  bitmap logo,'logo.bmp'    
Post 05 May 2015, 14:09
View user's profile Send private message Visit poster's website Reply with quote
80286



Joined: 01 May 2015
Posts: 15
80286 05 May 2015, 14:14
Thanks, revolution, your source works fine Smile
Post 05 May 2015, 14:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20685
Location: In your JS exploiting you and your system
revolution 05 May 2015, 14:23
The main differences are that "enter" is eliminated, "return" is replaced by "ret", proc needs a closing "endp", and local variables are wrapped in "locals" and "endl".
Post 05 May 2015, 14:23
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.