flat assembler
Message board for the users of flat assembler.

Index > Windows > Problem with bitmaps

Author
Thread Post new topic Reply to topic
Defsanguje



Joined: 07 Aug 2006
Posts: 7
Location: Finland
Defsanguje 07 Aug 2006, 02:47
Here's my code:
Code:
; Template for program using standard Win32 headers

format PE GUI 4.0
entry start

include 'win32ax.inc'

section '.data' data readable writeable
  _title           db 'Patcher Template',0
  _class           db 'FASMWIN32',0
  _ButtonClassName db "button",0
  _ButtonText      db "About",0
  _ButtonAbout     db "Random testing by. Defsanguje",0
  _ButtonAboutCap  db "About",0
  _StaticClassName db "static",0
  _StaticText      db "Random testing by. Defsanguje",0

  ID_ABOUT          =  100

  bmpH             dd ?
  ps               PAINTSTRUCT
  hdc              dd ?
  hMemDC           dd ?
  rect             RECT

  wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class

  msg MSG

section '.code' code readable executable

  start:

        invoke  GetModuleHandle,0
        mov     [wc.hInstance],eax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClass,wc

        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,200,200,343,300,NULL,NULL,[wc.hInstance],NULL

  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

             push    ebx esi edi
             cmp     [wmsg],WM_CREATE
             je      wmcreate
             cmp     [wmsg],WM_DESTROY
             je      wmdestroy
             cmp     [wmsg],WM_COMMAND
             je      wmcommand
             cmp     [wmsg],WM_PAINT
             je      wmpaint
             cmp     [wmsg],WM_DESTROY
             je      wmdestroy

        defwndproc:
             invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
             jmp     finish

        wmcreate:
             invoke  LoadBitmap,[wc.hInstance],IDR_LOGO
             mov     [bmpH],eax

             invoke  CreateWindowEx,0,_StaticClassName,NULL,WS_CHILD+WS_VISIBLE+WS_BORDER,5,28,325,235,[hwnd],NULL,[wc.hInstance],NULL
             invoke  CreateWindowEx,0,_StaticClassName,NULL,WS_CHILD+WS_VISIBLE+SS_BITMAP,10,32,600,600,[hwnd],IDR_LOGO,[wc.hInstance],NULL
             invoke  CreateWindowEx,0,_ButtonClassName,_ButtonText,WS_CHILD+WS_VISIBLE+BS_DEFPUSHBUTTON,10,235,80,23,[hwnd],ID_ABOUT,[wc.hInstance],NULL
             invoke  CreateWindowEx,0,_StaticClassName,_StaticText,WS_CHILD+WS_VISIBLE,5,5,350,23,[hwnd],NULL,[wc.hInstance],NULL

             jmp     finish

        wmpaint:
            invoke  BeginPaint,[hwnd],ps
                    mov  [hdc],eax
            invoke  CreateCompatibleDC,[hdc]
                    mov  [hMemDC],eax
            invoke  SelectObject,[hMemDC],[bmpH]
            invoke  GetClientRect,[hwnd],rect
            invoke  BitBlt,[hdc],50,50,[rect.right],[rect.bottom],[hMemDC],0,0,SRCCOPY
            invoke  DeleteDC,[hMemDC]
            invoke  EndPaint,[hwnd],ps
                    jmp  finish

        wmdestroy:
            invoke  DeleteObject,[logo]
            invoke  PostQuitMessage,0

        wmcommand:
            cmp     [wparam],BN_CLICKED shl 16 + ID_ABOUT
            je      wmabout
            jmp     finish

        wmabout:
            invoke  MessageBox,[hwnd],_ButtonAbout,_ButtonAboutCap,MB_OK
            jmp     finish

        wmclose:
            invoke DeleteObject,[bmpH]
            invoke PostQuitMessage,NULL

        finish:
            pop     edi esi ebx
           ret
     endp

section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL',\
          gdi32,'GDI32.DLL'

  include 'apia\kernel32.inc'
  include 'apia\user32.inc'
  include 'apia\gdi32.inc'


section '.rsrc' resource data readable

  IDR_LOGO          =  7

  directory bitmaps

  resource bitmaps,IDR_LOGO,LANG_ENGLISH+SUBLANG_DEFAULT,logo

  bitmap logo,'logo.bmp'    

It compiles perfectly and my .exe becomes 12kb bigger (logo.bmp is 12kb), but It doesn't draw the image... What's wrong?


Last edited by Defsanguje on 06 Dec 2008, 00:04; edited 1 time in total
Post 07 Aug 2006, 02:47
View user's profile Send private message MSN Messenger Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 07 Aug 2006, 07:18
1) you need
Code:
  directory RT_BITMAP,bitmaps 
    

to make it work under FASM 1.66

2) It draws the bitmap behind the
Code:
             invoke  CreateWindowEx,0,_StaticClassName,NULL,WS_CHILD+WS_VISIBLE+WS_BORDER,5,28,325,235,[hwnd],NULL,[wc.hInstance],NULL
    

so very little can be seen.

Try if you can fix it yourself now - I don't know what are you trying to do with that BMP.
Post 07 Aug 2006, 07:18
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Defsanguje



Joined: 07 Aug 2006
Posts: 7
Location: Finland
Defsanguje 07 Aug 2006, 15:15
Madis731 wrote:
1) you need
Code:
  directory RT_BITMAP,bitmaps 
    

to make it work under FASM 1.66

2) It draws the bitmap behind the
Code:
             invoke  CreateWindowEx,0,_StaticClassName,NULL,WS_CHILD+WS_VISIBLE+WS_BORDER,5,28,325,235,[hwnd],NULL,[wc.hInstance],NULL
    

so very little can be seen.

Try if you can fix it yourself now - I don't know what are you trying to do with that BMP.

I just wanted to display it. Thanks,
Code:
  directory RT_BITMAP,bitmaps 
    

worked Wink
Post 07 Aug 2006, 15:15
View user's profile Send private message MSN Messenger Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 07 Aug 2006, 22:33
There are too ways for drawing a bitmap. First is by obtaining device context (dc) when WM_PAINT is sent. Then you draw it in a similar way you posted. But if you create a static with SS_BITMAP style you can do it the other (simplier) way:
Code:
        invoke  CreateWindowEx,0,_StaticClassName,NULL,WS_CHILD+WS_VISIBLE+SS_BITMAP,10,32,600,600,[hwnd],IDR_LOGO,[wc.hInstance],NULL
        mov     [handle_of_static], eax
        ...
        invoke  LoadBitmap, [wc.hInstance], IDR_LOGO
        mov     [handle_of_bitmap], eax
        ...
        invoke  SendMessage, [handle_of_static], STM_SETIMAGE, IMAGE_BITMAP, [handle_of_bitmap]    


EDIT: If you choose the first way (drawing), do not create statics with SS_BITMAP as they're useless then.
Post 07 Aug 2006, 22:33
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.