flat assembler
Message board for the users of flat assembler.

Index > Windows > Where is my button?

Author
Thread Post new topic Reply to topic
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
windwakr
Topic^
I've modified the template example and had status bar,edit box,menu, button,etc...but when I try to do just a button theres nothing here....wtf?

Code:

; Template for program using standard Win32 headers

format PE GUI 4.0
entry start

include 'win32w.inc'

section '.data' data readable writeable

  _class TCHAR 'FASMWIN32',0
  _title TCHAR 'Win32 program template',0
  _error TCHAR 'Startup failed.',0

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

  msg MSG

  wHInstance dd ?
  btnclsname db 'button',0
  btnid equ 100
  btnhandle dd ?
  btntxt db 'abcdef',0


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
        test    eax,eax
        jz      error

        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_OVERLAPPEDWINDOW,128,128,300,200,NULL,NULL,[wc.hInstance],NULL
        test    eax,eax
        jz      error

  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        cmp     eax,1
        jb      end_loop
        jne     msg_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop

  error:
        invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK

  end_loop:
        invoke  ExitProcess,[msg.wParam]
        invoke  InitCommonControls

proc WindowProc hwnd,wmsg,wparam,lparam
        push    ebx esi edi
        cmp     [wmsg],WM_CREATE
        je      wmcreate
        cmp     [wmsg],WM_COMMAND
        je      wmcommand
        cmp     [wmsg],WM_DESTROY
        je      wmdestroy
  defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     finish
  wmcreate:
        invoke CreateWindowEx,NULL,btnclsname,btntxt,WS_CHILD+WS_VISIBLE+BS_PUSHBUTTON,\
        75,70,140,25,[hwnd],btnid,[wHInstance],NULL
        mov [btnhandle],eax
        jmp finish
  wmcommand:
        mov eax,[wparam]
        cmp ax,btnid
        je wmcommand_button
        jmp finish
     wmcommand_button:
          shr ax,16
          cmp ax,0
          jne finish
          invoke SendMessage,[hwnd],WM_COMMAND,13,0
          jmp finish

  wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  finish:
        pop     edi esi ebx
        ret
endp

section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL',\
          comctl32,'COMCTL32.DLL'

  include 'api\kernel32.inc'
  include 'api\user32.inc'
  include 'api\comctl32.inc'
    

_________________
----> * <---- My star, won HERE
Post 10 Nov 2008, 21:59
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
windwakr
Heres the original with all the stuff, before I tried having just a button....it works. Its a mix of the template, iczelion tutorials and my own stuff.

Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

section '.data' data readable writeable

  ;;
  wHMain dd ?
  wHInstance dd ?
  ;;

  _class TCHAR 'FASM32',0
  _title TCHAR 'Test Program',0
  _error TCHAR 'Startup failed.',0

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

  msg MSG

  ;;
  btnclsname db 'button',0
  btntxt db 'Click Here!',0
  editclsname db 'edit',0
  edittxt db "Wow, I'm inside an edit box!",0
  editbuffer rb 513

  btnhandle dd ?
  edithandle dd ?
  btnid equ 100
  editid equ 200

  sb1 equ 300
  sb1h dd ?
  sb1c dd 0
  sbtext db 'Times MessageBox Created: %u',0
  sbBuffer rb 512
  ;;

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
        test   eax,eax
        jz     error

        invoke CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_OVERLAPPEDWINDOW,128,128,300,200,NULL,NULL,[wc.hInstance],NULL
        test   eax,eax
        jz     error

  msg_loop:
        invoke GetMessage,msg,NULL,0,0
        cmp    eax,1
        jb     end_loop
        jne    msg_loop
        invoke TranslateMessage,msg
        invoke DispatchMessage,msg
        jmp    msg_loop

  error:
        invoke MessageBox,NULL,_error,NULL,MB_OK+MB_ICONERROR

  end_loop:
        invoke ExitProcess,[msg.wParam]

proc WindowProc hwnd,wmsg,wparam,lparam
        push   ebx esi edi
        cmp    [wmsg],WM_COMMAND
        je     wmcommand
        cmp    [wmsg],WM_CREATE
        je     wmcreate
        cmp    [wmsg],WM_DESTROY
        je     wmdestroy

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

  wmcreate:
        invoke CreateWindowEx,WS_EX_CLIENTEDGE,editclsname,NULL,WS_CHILD+WS_VISIBLE+WS_BORDER+ES_LEFT+ES_AUTOHSCROLL,\
        50,35,200,25,[hwnd],editid,[wHInstance],NULL
        mov [edithandle],eax
        invoke SetFocus,eax
        invoke CreateWindowEx,NULL,btnclsname,btntxt,WS_CHILD+WS_VISIBLE+BS_DEFPUSHBUTTON,\
        75,70,140,25,[hwnd],btnid,[wHInstance],NULL
        mov [btnhandle],eax
        cinvoke wsprintf,sbBuffer,sbtext,[sb1c]
        invoke CreateStatusWindow,WS_CHILD+WS_VISIBLE,sbBuffer,[hwnd],sb1
        mov [sb1h],eax
        jmp finish

  wmcommand:
        mov eax,[wparam]
        cmp [lparam],0
        je  wmcommand_menu
        cmp ax,btnid
        je  wmcommand_button
        jmp finish

    wmcommand_menu:
        cmp ax,11
        je  menu_write
        cmp ax,12
        je  menu_clear
        cmp ax,13
        je  menu_messagebox
        cmp ax,14
        je  wmdestroy
        jmp finish
    menu_write:
        invoke SetWindowText,[edithandle],edittxt
        jmp finish
    menu_clear:
        invoke SetWindowText,[edithandle],NULL
        jmp finish
    menu_messagebox:
        inc [sb1c]
        cinvoke wsprintf,sbBuffer,sbtext,[sb1c]
        invoke SendMessage,[sb1h],SB_SETTEXT,0,sbBuffer
        invoke GetWindowText,[edithandle],editbuffer,512
        invoke MessageBox,NULL,editbuffer,_title,MB_OK
        jmp finish

    wmcommand_button:
        shr ax,16
        cmp ax,0
        je  button_clicked
        jmp finish
       button_clicked:
          invoke SendMessage,[hwnd],WM_COMMAND,13,0
          jmp finish

  wmdestroy:
        invoke PostQuitMessage,0
        xor    eax,eax

  finish:
        pop    edi esi ebx
        ret
endp

section '.idata' import data readable writeable
  library kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL',\
          comctl32,'COMCTL32.DLL'

  include 'api/kernel32.inc'
  include 'api/user32.inc'
  include 'api/comctl32.inc'

section '.rsrc' resource data readable
  directory RT_MENU,appMenu

  resource appMenu,\
           30,LANG_NEUTRAL,menuMain

  menu menuMain
       menuitem '&Test Menu',10,MFR_POPUP or MFR_END
       menuitem '&Write Something To Textbox',11,MFT_STRING
       menuitem '&Clear Textbox',12,MFT_STRING
       menuitem '&MessageBox my text',13,MFT_STRING
                menuseparator
       menuitem '&Exit',14,MFR_END
    

_________________
----> * <---- My star, won HERE
Post 10 Nov 2008, 22:01
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
This change fixes the problem...
Code:
include 'win32a.inc'
    
Post 11 Nov 2008, 00:07
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
windwakr
Thank you, I can't believe a single letter was causing me all this frustration!

Ok, does anyone know how to make a list listview, I can't seem to make the iczelion tutorial work at all, even the fasm version.

_________________
----> * <---- My star, won HERE
Post 11 Nov 2008, 00:20
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Also i just noticed...
Code:
end_loop:
        invoke  ExitProcess,[msg.wParam]
        invoke  InitCommonControls     

You should move this call up to the top...
Code:
start:
   invoke InitCommonControls
   ...    
Post 11 Nov 2008, 07:08
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
windwakr,

This one-letter change works because, for example, you define _title as TCHAR and btnclsname as db. Define all string constants as TCHARs, make sure string buffers are big enough and you almost done with Unicode-ready version ("almost" is because SB_SETTEXT = SB_SETTEXTA in COMCTL32.INC).
Post 11 Nov 2008, 08:01
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
windwakr
bitshifter, I read that initcommoncontrols doesn't actually need to be called, just placed anywhere in executable. I think it's only really needed in HLL's.

_________________
----> * <---- My star, won HERE
Post 11 Nov 2008, 13:20
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17253
Location: In your JS exploiting you and your system
revolution
windwakr wrote:
bitshifter, I read that initcommoncontrols doesn't actually need to be called, just placed anywhere in executable. I think it's only really needed in HLL's.
see here also for some discussion.
Post 11 Nov 2008, 13:45
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
I think what it really comes down to is... Did the shell register the common control classes when it was invoked by the kernel.
If you can guarantee this, then you dont need to call InitCommonControls.
But as we all know, we are talking about Windows, so its better to be safe than sorry and make sure these classes are registered BEFORE we use them.
Post 12 Nov 2008, 05:38
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.