flat assembler
Message board for the users of flat assembler.

Index > Windows > For Newbies: Text.asm Iczelion's example FASMW version

Author
Thread Post new topic Reply to topic
imagineer



Joined: 09 Aug 2003
Posts: 14
imagineer 16 Aug 2003, 02:55
Code:

; Text.asm Iczelion's example FASMW version

format PE GUI 4.0
entry start


include '%include%\win32a.inc'

;--------------------------------------------
macro RGB red, green, blue
{
        xor eax, eax
        mov ah, blue
        shl eax, 8
        mov ah, green
        mov al, red
}

;---------------------------------------------
section '.data' data readable writeable

  _title db 'Our First Window',0
  _class db 'SimpleWinClass',0
  _OurText  db 'Win32 assembly is great and easy!',0
  mainhwnd dd ?
  hinstance dd ?
  msg MSG
  wc WNDCLASS
  _hdc dd 0
  _ps PAINTSTRUCT
  _FontName db 'script',0
  _hfont dd 0
;---------------------------------------------
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_WINDOW+1
        mov     [wc.lpszMenuName],0
        mov     [wc.lpszClassName],_class
        invoke  RegisterClass,wc

        invoke  CreateWindowEx,0,_class,_title, WS_OVERLAPPEDWINDOW,\
                               CW_USEDEFAULT, CW_USEDEFAULT , CW_USEDEFAULT, CW_USEDEFAULT,\
                               NULL, NULL, [hinstance], NULL
        mov     [mainhwnd],eax
        invoke  ShowWindow, [mainhwnd], SW_SHOWNORMAL
        invoke  UpdateWindow, [mainhwnd]

  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
        enter
        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:
        invoke  BeginPaint, [hwnd], _ps
        mov     [_hdc], eax
        invoke  CreateFont, 24, 16, 0, 0, 400, 0, 0, 0,\
                           OEM_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,\
                           DEFAULT_QUALITY, DEFAULT_PITCH+FF_SCRIPT, _FontName
        invoke  SelectObject, [_hdc], eax
        mov     [_hfont], eax
        RGB 200,200,50
        invoke  SetTextColor, [_hdc], eax
        RGB 0,0,255
        invoke  SetBkColor, [_hdc], eax
        invoke  TextOut, [_hdc], 0 ,0, _OurText, 33
        invoke  SelectObject, _hdc, _hfont
        invoke  EndPaint, [hwnd], _ps
        jmp     finish
  wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  finish:
        pop     edi esi ebx
        return
;-----------------------------------------------
section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          gdi, 'GDI32.DLL',\
          user,'USER32.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',\
         PostQuitMessage,'PostQuitMessage',\
         ShowWindow,'ShowWindow',\
         UpdateWindow, 'UpdateWindow',\
         BeginPaint, 'BeginPaint',\
         EndPaint, 'EndPaint'

   import gdi,\
         CreateFont, 'CreateFontA',\
         SelectObject, 'SelectObject',\
         SetTextColor, 'SetTextColor',\
         SetBkColor, 'SetBkColor',\
         TextOut, 'TextOutA'
;=============================================
    


Cheers,

The I
Post 16 Aug 2003, 02:55
View user's profile Send private message Reply with quote
hitertan



Joined: 12 Mar 2004
Posts: 15
Location: China
hitertan 17 Mar 2004, 15:22
Oh yeah!I studied Iczelion's source a moment ago and just thinking about this question.Thank you!

_________________
i like assembly language and i study it in my pleasure time
tanshunquan@hotmail.com
Post 17 Mar 2004, 15:22
View user's profile Send private message MSN Messenger Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 17 Mar 2004, 19:08
imagineer,

Nice work; just you should consider using Fasm's standard include files for the API functions:
Code:
include '%fasminc%\win32a.inc'
    

_________________
Code it... That's all...
Post 17 Mar 2004, 19:08
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 26 Aug 2004, 07:53
- use lstrlen instead of hardcoded string length
- use GetCurrentObject to get the default Font object

sincerely,
vbVeryBeginner
http://sulaiman.thefreebizhost.com

Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

macro RGB cR, cG, cB {
     xor  eax,eax   ;clear the eax
     mov  ah,cB
     shl  eax,8
     mov  ah,cG
     mov  al,cR
}

section '.data' data readable writeable
     wHMain         dd   ?
     wHInstance     dd   ?

     wTitle         db   'FASM - Experiment 02',0
     wClsName       db   'EXP02',0

     wMsg      MSG
     wCls      WNDCLASS

     OBJ_FONT       equ  6
     
     expDc     dd   ?
     expTxt1   db   'Win32 assembly with FASM is',0
     expTxt2   db   'great and easy!',0
     expFont   db   'Courier New',0
     expPs     PAINTSTRUCT

section '.code' code readable executable
     start:
          ; +------------------------------+
          ; | registering the window class |
          ; +------------------------------+
          invoke    GetModuleHandle,NULL
                    mov  [wHInstance],eax
                    mov  [wCls.hInstance],eax
                    mov  [wCls.lpfnWndProc],window_procedure
                    mov  [wCls.lpszClassName],wClsName
                    mov  [wCls.hbrBackground],COLOR_BTNFACE+1
          invoke    LoadIcon,0,IDI_APPLICATION
                    mov  [wCls.hIcon],eax
          invoke    LoadCursor,0,IDC_ARROW
                    mov  [wCls.hCursor],eax
          invoke    RegisterClass,wCls

          ; +--------------------------+
          ; | creating the main window |
          ; +--------------------------+
          invoke    CreateWindowEx,\
                         0,\
                         wClsName,\
                         wTitle,\
                         WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,\
                         128,\
                         128,\
                         550,\
                         100,\
                         0,\
                         0,\
                         [wHInstance],\
                         0
                    mov  [wHMain],eax

          ; +---------------------------+
          ; | entering the message loop |
          ; +---------------------------+
          window_message_loop_start:
               invoke    GetMessage,wMsg,NULL,0,0
                         or   eax,eax
                         je   window_message_loop_end
               invoke    TranslateMessage,wMsg
               invoke    DispatchMessage,wMsg
                         jmp  window_message_loop_start

          window_message_loop_end:
               invoke    ExitProcess,0

          ; +----------------------+
          ; | the window procedure |
          ; +----------------------+
          proc window_procedure,hWnd,uMsg,wParam,lParam
               push ebx esi edi    ;even the API would preserved, but play safe :p
               cmp  [uMsg],WM_DESTROY
               je   wmDESTROY
               cmp  [uMsg],WM_PAINT
               je   wmPAINT

               wmDEFAULT:
                    invoke    DefWindowProc,[hWnd],[uMsg],[wParam],[lParam]
                              jmp  wmBYE
               wmPAINT:
                    invoke    BeginPaint,[hWnd],expPs
                              mov  [expDc],eax
                    invoke    GetCurrentObject,[expDc],OBJ_FONT
                              push eax
                    invoke    CreateFont,\
                                   24,\
                                   16,\
                                   0,\
                                   0,\
                                   400,\
                                   0,\
                                   0,\
                                   0,\
                                   DEFAULT_CHARSET,\
                                   OUT_DEFAULT_PRECIS,\
                                   CLIP_DEFAULT_PRECIS,\
                                   DEFAULT_QUALITY,\
                                   DEFAULT_PITCH or FF_MODERN,\
                                   expFont
                    invoke    SelectObject,[expDc],eax
                              RGB  200,200,50
                    invoke    SetTextColor,[expDc],eax
                              RGB  0,0,255
                    invoke    SetBkColor,[expDc],eax
                    invoke    lstrlen,expTxt1
                    invoke    TextOut,[expDc],0,0,expTxt1,eax
                    invoke    lstrlen,expTxt2
                    invoke    TextOut,[expDc],0,26,expTxt2,eax
                              pop  eax
                    invoke    SelectObject,[expDc],eax
                    invoke    EndPaint,[hWnd],expPs
                              jmp  wmBYE

               wmDESTROY:
                    invoke    PostQuitMessage,0
               wmBYE:
                    pop  edi esi ebx
                    return
          endp

section '.idata' import data readable writable
     library   KERNEL32, 'KERNEL32.DLL',\
               USER32,   'USER32.DLL',\
               GDI32,    'GDI32.DLL'

     import    KERNEL32,\
               GetModuleHandle,    'GetModuleHandleA',\
               lstrlen,            'lstrlenA',\
               ExitProcess,        'ExitProcess'

     import    USER32,\
               RegisterClass,      'RegisterClassA',\
               CreateWindowEx,     'CreateWindowExA',\
               DefWindowProc,      'DefWindowProcA',\
               LoadCursor,         'LoadCursorA',\
               LoadIcon,           'LoadIconA',\
               GetMessage,         'GetMessageA',\
               TranslateMessage,   'TranslateMessage',\
               DispatchMessage,    'DispatchMessageA',\
               BeginPaint,         'BeginPaint',\
               EndPaint,           'EndPaint',\
               PostQuitMessage,    'PostQuitMessage'
     import    GDI32,\
               CreateFont,         'CreateFontA',\
               SetTextColor,       'SetTextColor',\
               SetBkColor,         'SetBkColor',\
               TextOut,            'TextOutA',\
               GetCurrentObject,   'GetCurrentObject',\
               SelectObject,       'SelectObject'
    
Post 26 Aug 2004, 07:53
View user's profile Send private message Visit poster's website Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 26 Aug 2004, 11:43
vbVeryBeginner wrote:
- use lstrlen instead of hardcoded string length


Why? For constant strings is better to have it hardcoded instead. It saves processor many cycles to determine a number already known. Wink
Post 26 Aug 2004, 11:43
View user's profile Send private message Yahoo Messenger Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 26 Aug 2004, 14:21
hi pelaillo,
actually, i just wanna introduce that lstrlen function :) coz they got sizeof in MASM :p

i guess i will really count that character one by one if i didn't know this function :p
newbies notepad didn't help them count char once they highlight the text, unlike my textpad (http://www.textpad.com) fully functional trial version :p

what editor u use pelaillo ;?

sincerely,
vbVeryBeginner.
Post 26 Aug 2004, 14:21
View user's profile Send private message Visit poster's website Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 26 Aug 2004, 16:53
hi vbVeryBeginner,
Fasm counts number of chars:
Code:
someText db 'This is some text'
someText.size = $ - someText

invoke  TextOut, [_hdc], 0 ,0, someText, someText.size    


Editor I use is KetilO's RadAsm (radasm.visualassembler.com). I have it already customized for fasm in my homepage.

http://as.modshack.co.uk
Post 26 Aug 2004, 16:53
View user's profile Send private message Yahoo Messenger Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 27 Aug 2004, 08:19
http://as.modshack.co.uk

ye, i remember this site,
still waiting for the ENGLISH tutorial :p
Post 27 Aug 2004, 08:19
View user's profile Send private message Visit poster's website Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 20 May 2005, 14:02
ah that rgb macro was exactly what i was looking for thanks
Post 20 May 2005, 14:02
View user's profile Send private message AIM Address MSN Messenger Reply with quote
NoName



Joined: 28 Jul 2005
Posts: 1
NoName 28 Jul 2005, 08:36
Tutorials 4,5,6,7,8-1,9,12,23 on Fasm Smile Embarassed


Description:
Download
Filename: Ichz.rar
Filesize: 9.73 KB
Downloaded: 587 Time(s)

Post 28 Jul 2005, 08:36
View user's profile Send private message ICQ Number 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.