flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Where is my mistake? (fasmg) (solved)

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 24 Jul 2017, 20:28
I tryed to port examples from fasm1 to fasmg, from old resource sintax to new one (and at same time to test my understanding of resource internals)/
I don`t looking for macro that does it correctly. I wish to write that macro myself. I need just to know where I make mistake?
Code:
;include 'FUNDAMENTALS\MACROS\symbols.inc'
include 'ABI\WIN\win32a.inc'

format PE GUI ;rename binary as 'MINIPAD.EXE'
entry start   ;launch CMD line '%OUTPUT%'

IDR_ICON = 1
IDR_GICON = 17
IDR_MENU = 37

IDM_NEW   = 101
IDM_EXIT  = 102
IDM_ABOUT = 901
NULL = 0
FALSE = 0
TRUE = 1

section '.text' code readable executable

  start:

        invoke  GetModuleHandle,0
        mov     [wc.hInstance],eax

        invoke  LoadIcon,eax,IDR_ICON
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClass,wc
        test    eax,eax
        jz      error

        invoke  LoadMenu,[wc.hInstance],IDR_MENU
        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_OVERLAPPEDWINDOW,144,128,256,256,NULL,eax,[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,0

proc WindowProc uses ebx esi edi, hwnd,wmsg,wparam,lparam
        mov     eax,[wmsg]
        cmp     eax,WM_CREATE
        je      .wmcreate
        cmp     eax,WM_SIZE
        je      .wmsize
        cmp     eax,WM_SETFOCUS
        je      .wmsetfocus
        cmp     eax,WM_COMMAND
        je      .wmcommand
        cmp     eax,WM_DESTROY
        je      .wmdestroy
  .defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .finish
  .wmcreate:
        invoke  GetClientRect,[hwnd],client
        invoke  CreateWindowEx,WS_EX_CLIENTEDGE,_edit,0,WS_VISIBLE+WS_CHILD+WS_HSCROLL+WS_VSCROLL+ES_AUTOHSCROLL+ES_AUTOVSCROLL+ES_MULTILINE,[client.left],[client.top],[client.right],[client.bottom],[hwnd],0,[wc.hInstance],NULL
        or      eax,eax
        jz      .failed
        mov     [edithwnd],eax
        invoke  CreateFont,16,0,0,0,0,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_RASTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH+FF_DONTCARE,NULL
        or      eax,eax
        jz      .failed
        mov     [editfont],eax
        invoke  SendMessage,[edithwnd],WM_SETFONT,eax,FALSE
        xor     eax,eax
        jmp     .finish
      .failed:
        or      eax,-1
        jmp     .finish
  .wmsize:
        invoke  GetClientRect,[hwnd],client
        invoke  MoveWindow,[edithwnd],[client.left],[client.top],[client.right],[client.bottom],TRUE
        xor     eax,eax
        jmp     .finish
  .wmsetfocus:
        invoke  SetFocus,[edithwnd]
        xor     eax,eax
        jmp     .finish
  .wmcommand:
        mov     eax,[wparam]
        and     eax,0FFFFh
        cmp     eax,IDM_NEW
        je      .new
        cmp     eax,IDM_ABOUT
        je      .about
        cmp     eax,IDM_EXIT
        je      .wmdestroy
        jmp     .defwndproc
      .new:
        invoke  SendMessage,[edithwnd],WM_SETTEXT,0,0
        jmp     .finish
      .about:
        invoke  MessageBox,[hwnd],_about_text,_about_title,MB_OK
        jmp     .finish
  .wmdestroy:
        invoke  DeleteObject,[editfont]
        invoke  PostQuitMessage,0
        xor     eax,eax
  .finish:
        ret
endp

section '.data' data readable writeable

  _title TCHAR 'MiniPad',0
  _about_title TCHAR 'About MiniPad',0
  _about_text TCHAR 'This is Win32 example program created with flat assembler.',0
  _error TCHAR 'Startup failed.',0

  _class TCHAR 'MINIPAD32',0
  _edit TCHAR 'EDIT',0

  wc WNDCLASS style:0, lpfnWndProc:WindowProc, hbrBackground:COLOR_BTNFACE+1, lpszClassName:_class

  edithwnd dd ?
  editfont dd ?

  msg MSG
  client RECT

section '.idata' import data readable writeable

  ;dd 0,0,0,RVA kernel_name,RVA kernel_table
  ;dd 0,0,0,RVA user_name,RVA user_table
  ;dd 0,0,0,0,0

  ;kernel_table:
  ;  ExitProcess dd RVA _ExitProcess
  ;  dd 0
  ;user_table:
  ;  MessageBox dd RVA _MessageBoxA
  ;  dd 0

  ;kernel_name db 'KERNEL32.DLL',0
  ;user_name db 'USER32.DLL',0

  ;_ExitProcess dw 0
  ;  db 'ExitProcess',0
  ;_MessageBoxA dw 0
  ;  db 'MessageBoxA',0
    library kernel32,'KERNEL32.DLL',\
            user32,'USER32.DLL',\
            gdi32,'GDI32.DLL'

  include 'ABI\WIN\API\kernel32.inc'
  include 'ABI\WIN\API\user32.inc'
  include 'ABI\WIN\API\gdi32.inc'

section '.reloc' fixups data readable discardable       ; needed for Win32s

macro menuitem string,id,resinfo,status,type
   dd MFT_STRING or type+0,status+0,id
   dw resinfo+0
   du string,0
   align 4
   match any,resinfo
    if resinfo and MFR_POPUP
     dd 0
    end if
   end match
end macro


macro menuseparator resinfo
   dd MFT_SEPARATOR,0,0
   dw resinfo+0,0
end macro

section '.rsrc' resource data readable

  resource_directory

    resource_data RT_MENU,IDR_MENU,LANG_ENGLISH+SUBLANG_DEFAULT
      dw 1,4,0,0
       menuitem '&File',0,MFR_POPUP
                menuitem '&New',IDM_NEW
                menuseparator
                menuitem 'E&xit',IDM_EXIT,MFR_END
       menuitem '&Help',0,MFR_POPUP + MFR_END
                menuitem '&About...',IDM_ABOUT,MFR_END
    end resource_data

    resource_data RT_ICON,IDR_ICON,LANG_NEUTRAL
      virtual at 0
       file 'minipad.ico':6,16
       load size:dword from 8
       load position:dword from 12
      end virtual
      file 'minipad.ico':position,size
    end resource_data

    resource_data RT_GROUP_ICON,IDR_GICON,LANG_NEUTRAL
      dw 0,1,1
      file 'minipad.ico':6,12
      dw IDR_ICON
    end resource_data
  end resource_directory     


menu goes correctly, app not crashed, even in explorer icon of app displayed correctly in explorer and in taskbar, but....

..Icon not goes to window header. I can`t localize mistake: it is in resources or in code? upper picture - how window header looks after compile from fasm1 examples, down picture is mine in fasmg with mistake.

I tryed to see difference in tool of MiTek named exe.exe (freeware) in both "minipad.exe"`s present same resources for icon, menu, group icon - they looks binary identic on first sight.


Description:
Filesize: 1.65 KB
Viewed: 4251 Time(s)

minipadorig.JPG


Description:
Filesize: 7.86 KB
Viewed: 4251 Time(s)

minipad.JPG



_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.


Last edited by ProMiNick on 24 Jul 2017, 21:40; edited 1 time in total
Post 24 Jul 2017, 20:28
View user's profile Send private message Send e-mail Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 24 Jul 2017, 21:34
I found solution there was no mistakes.

OS shows only group icon with ID = 1 in win header.

changing definition from
IDR_ICON = 1
IDR_GICON = 17
to
IDR_ICON = 17
IDR_GICON = 1
solves all
Post 24 Jul 2017, 21:34
View user's profile Send private message Send e-mail 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.