flat assembler
Message board for the users of flat assembler.

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

Author
Thread Post new topic Reply to topic
imagineer



Joined: 09 Aug 2003
Posts: 14
imagineer
Code:

; Keyboard.asm Iczelion's example FASMW version

format PE GUI 4.0
entry start


include '%include%\win32a.inc'

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

  _title db 'Keyboard Demo',0
  _class db 'SimpleWinClass',0
  mainhwnd dd ?
  hinstance dd ?
  msg MSG
  wc WNDCLASS
  _hdc dd 0
  _ps PAINTSTRUCT
  _keychar 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_CHAR
        je      wmkeychar
        cmp     [wmsg],WM_PAINT
        je      wmpaint
  defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     finish
  wmkeychar:
        push    [wparam]
        pop     [_keychar]
        invoke  InvalidateRect, [hwnd], NULL, TRUE
        jmp     finish
  wmpaint:
        invoke  BeginPaint, [hwnd], _ps
        mov     [_hdc], eax
        invoke  TextOut, [_hdc], 0 ,0, _keychar, 1
        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',\
         InvalidateRect, 'InvalidateRect'

   import gdi,\
         TextOut, 'TextOutA'
;=============================================
    


Cheers,

The I
Post 18 Aug 2003, 10:04
View user's profile Send private message Reply with quote
boysoledad



Joined: 14 Sep 2003
Posts: 10
boysoledad
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]

Hi Code follow is WinMain yes?
i want to add ico to file asm, how to i do?
Post 17 Sep 2003, 02:51
View user's profile Send private message Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv
Yes.

Throw the icon definition into the .rsrc section

Change invoke LoadIcon,0,IDI_APPLICATION to invoke LoadIcon,[hinstance],IDI_YOURICON You want you can replace hinstance with 400000h.
Post 17 Sep 2003, 03:48
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
imagineer



Joined: 09 Aug 2003
Posts: 14
imagineer
To learn how to define the icon in the rsrc section, you can find a good example minipad.asm in the examples directory.

Cheers,
The I
--
P.S. Is there a tutorial on how to define the rsrc section for all the resources. The resources macro is, IMHO, too complicated for beginners. Smile
Post 17 Sep 2003, 06:14
View user's profile Send private message Reply with quote
Kain



Joined: 26 Oct 2003
Posts: 108
Kain
thanks for these translations of icezelion's tutes. they have been valuable in helping me learn the fasmw interface. now that i am used to interface, it should be smooth sailing.

i had problem trying to figure out how to import the functions from the proper dll (never had to worry about that in java).
Post 28 Oct 2003, 16:37
View user's profile Send private message 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-2020, Tomasz Grysztar.

Powered by rwasa.