flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > resource '.rsrc' issue

Author
Thread Post new topic Reply to topic
Ali.A



Joined: 08 Jan 2018
Posts: 126
whenever i try to compile i get this error:

Fasm 1 wrote:
Error: undefined symbol 'size?05Q'.
main_menu dd RVA data?05P,size?05Q,0,0


Code:
directory RT_MENU,menus

  resource menus,\
           IDM_MAIN,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu

  IDM_MAIN      = 101
  IDM_FIND      = 102

  menu main_menu
       menuitem '&Edit',0,MFR_POPUP
                menuitem '&Find' ,09, 'Ctrl+F',IDM_FIND,MFR_END    


im just trying to learn some gui stuff lol. (got bored from making console programs)

_________________
Asm For Wise Humans
Post 03 Oct 2018, 19:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16057
Location: 112 Ocean Avenue, Amityville
You are missing the "directory".

And how have you defined the underscore character there? Perhaps you need to add this:
Code:
  _ equ ,09h,    


Edit: since you have edited your post by manually replacing the underscore with ,09, then you will need to do this:
Code:
menuitem <'&Find' ,09, 'Ctrl+F'>,IDM_FIND,MFR_END    
Post 03 Oct 2018, 19:43
View user's profile Send private message Visit poster's website Reply with quote
Ali.A



Joined: 08 Jan 2018
Posts: 126
Code:
section '.rsrc' resource data readable

  directory RT_MENU,menus

  resource menus,\
           IDM_MAIN,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu

  IDM_MAIN      = 101
  IDM_FIND      = 102

  _ equ ,09,

  menu main_menu
       menuitem '&Edit',0,MFR_POPUP
                menuitem '&Find' _ 'Ctrl+F',IDM_FIND,MFR_END    


still, getting same error. (but this time 'size?05H' wtf!)

and it opens resource.inc (shipped with fasm)
it highlights this line:
resource.inc wrote:
macro menu label
{ local data,size
label dd RVA data,size,0,0
data dw 1,4,0,0
menu_size equ size = $ - data
menu_level = 1 }


am i missing something?

_________________
Asm For Wise Humans
Post 04 Oct 2018, 01:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16057
Location: 112 Ocean Avenue, Amityville
Please post a minimal source that we can compile that shows the error.
Post 04 Oct 2018, 01:41
View user's profile Send private message Visit poster's website Reply with quote
Ali.A



Joined: 08 Jan 2018
Posts: 126
i know i need to handle the message for IDM_FIND, but i dont care i just want to see a menu. (i would be very happy to see my code working)

i might ask later how to handle specific messages, or what actions require specific window_messages.

as i mentioned above, i just started learning gui stuff (from examples provided by fasm) and i really wanna make my first gui program. (instead of consoles)

Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

section '.text' code readable executable

start:

    invoke      GetModuleHandle,0
    mov         [wc.hInstance],eax
    invoke      LoadIcon,0,IDI_WINLOGO
    mov         [wc.hIcon],eax
    invoke      LoadCursor,0,IDC_IBEAM
    mov         [wc.hCursor],eax
    xor         eax,eax
    mov         [wc.style],CS_DBLCLKS+CS_GLOBALCLASS
    mov         [wc.lpfnWndProc],MainWindow
    mov         [wc.cbClsExtra],eax
    mov         [wc.cbWndExtra],eax
    mov         [wc.hbrBackground],COLOR_WINDOW
    mov         [wc.lpszMenuName],eax
    mov         [wc.lpszClassName],_class
    invoke      RegisterClass,wc
    invoke      LoadMenu,[wc.hInstance],IDM_MAIN
    invoke      CreateWindowEx,0,_class,_caption,WS_OVERLAPPED+WS_THICKFRAME,25,25,244,152,NULL,eax,[wc.hInstance],NULL
    mov         [hwnd_main],eax
    invoke      ShowWindow,eax,SW_SHOWNORMAL
    invoke      UpdateWindow,[hwnd_main]

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 MainWindow hwnd,umsg,wparam,lparam
    cmp         [umsg],WM_DESTROY
    jz          wmdestroy
    invoke      DefWindowProc,[hwnd],[umsg],[wparam],[lparam]
    jmp         finish
  wmdestroy:
    invoke      PostQuitMessage,0
    xor         eax,eax
  finish:
    ret
endp

section '.data' data readable writeable

  _class db 'main',0
  _caption db 'gui window',0

  wc WNDCLASS
  msg MSG
  pt POINT

  hwnd_main dd ?

section '.idata' import data readable

  library kernel32,'kernel32.dll',\
          user32,'user32.dll',\
          advapi32,'advapi32.dll',\
          shell32,'shell32.dll',\
          gdi32,'gdi32.dll',\
          comctl32,'comctl32.dll',\
          comdlg32,'comdlg32.dll'

  include 'api\kernel32.inc'
  include 'api\user32.inc'
  include 'api\advapi32.inc'
  include 'api\shell32.inc'
  include 'api\gdi32.inc'
  include 'api\comctl32.inc'
  include 'api\comdlg32.inc'

section '.rsrc' resource data readable

  directory RT_MENU,menus

  resource menus,\
           IDM_MAIN,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu


  IDM_MAIN      = 101
  IDM_FIND      = 102

  _ equ ,09,

  menu main_menu
       menuitem '&Edit',0,MFR_POPUP
                menuitem '&Find' _ 'Ctrl+F',IDM_FIND,MFR_END

section '.reloc' fixups data readable discardable    

_________________
Asm For Wise Humans
Post 04 Oct 2018, 14:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16057
Location: 112 Ocean Avenue, Amityville
Maybe this:
Code:
  menu main_menu
       menuitem '&Edit',0,MFR_POPUP + MFR_END
                menuitem '&Find' _ 'Ctrl+F',IDM_FIND,MFR_END    
Post 04 Oct 2018, 14:25
View user's profile Send private message Visit poster's website Reply with quote
Ali.A



Joined: 08 Jan 2018
Posts: 126
it wooooorked, thanks revvv.

finally i saw a menu, man im so f*cking happy ... my first steps to learn and write gui program. (byebye consoles)

but hey, these messages WM_?... where can i find a guide on how to use them and what they are for?
there is also FM_?... i dont understand such things, all what i need is a little bit of reading to get the basic things/concept.

but failed searching/getting anything useful about them and about WndProc procedure (MainWindow - callback)

_________________
Asm For Wise Humans
Post 04 Oct 2018, 16:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16057
Location: 112 Ocean Avenue, Amityville
The best place for information on the messages Windows generates is the MS website. Or the MSDN docs if you have those.

For example a random message:
https://docs.microsoft.com/en-us/windows/desktop/winmsg/wm-destroy
Post 04 Oct 2018, 16:33
View user's profile Send private message Visit poster's website Reply with quote
Ali.A



Joined: 08 Jan 2018
Posts: 126
WM_DESTROY
WM_DESTROY wrote:
Sent when a window is being destroyed. It is sent to the window procedure of the window being destroyed after the window is removed from the screen.

Result:
If an application processes this message, it should return zero.

Code:
invoke PostQuitMessage,0 ; but why i have to call 'PostQuitMessage'
xor eax,eax
ret    




WM_CLOSE
WM_CLOSE wrote:
Sent as a signal that a window or an application should terminate.

A window receives this message through its WindowProc function.


Result:
If an application processes this message, it should return zero.

Remarks:
An application can prompt the user for confirmation, prior to destroying a window, by processing the WM_CLOSE message and calling the DestroyWindow function only if the user confirms the choice.

By default, the DefWindowProc function calls the DestroyWindow function to destroy the window.

Code:
invoke DestroyWindow,hwnd_main ; handle to main window
; question: do i need postquitmessage here?
xor eax,eax
ret    

so according to what i understood from MS-Docs, even if i didnt write in window procedure "cmp [umsg],WM_CLOSE" it will be closed just like WM_DESTROY ... but i can use it to confirm the process termination.
(show a messagebox or dialog box saying do you wanna quit [yes]/[no] in case yes then terminate otherwise continue)



WM_QUIT
WM_QUIT wrote:
Indicates a request to terminate an application, and is generated when the application calls the PostQuitMessage function. This message causes the GetMessage function to return zero.

Parameters:
wParam
The exit code given in the PostQuitMessage function.

Result:
This message does not have a return value because it causes the message loop to terminate before the message is sent to the application's window procedure.

Remarks:
The WM_QUIT message is not associated with a window and therefore will never be received through a window's window procedure. It is retrieved only by the GetMessage or PeekMessage functions.

Do not post the WM_QUIT message using the PostMessage function; use PostQuitMessage.


by just writing here, i got my answer.
i asked:
but why i have to call 'PostQuitMessage'
asnwer:
because WM_QUIT is sent to GetMessage ONLY and according to my code if eax = 0 then jump to exit process.

but what confuse me now is:

do i have to write:
Code:
invoke PostQuitMessage,0 ; or ; invoke PostQuitMessage,[wparam]    


and what i said about WM_CLOSE and WM_DESTROY are true/right?

_________________
Asm For Wise Humans
Post 04 Oct 2018, 19:57
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 419
Location: Belarus
Ali.A wrote:
but what confuse me now is:

do i have to write:
Code:
invoke PostQuitMessage,0 ; or ; invoke PostQuitMessage,[wparam]    


and what i said about WM_CLOSE and WM_DESTROY are true/right?

The PostQuitMessage function adds a WM_QUIT message to the message queue of the calling thread with wParam set to its parameter. The message will eventually be retrieved from the queue by GetMessage function which will then return 0. Since the return value of GetMessage is usually used as the message handling loop condition, this will cause the message handling loop termination and the program execution will proceed further where it’ll usually reach program termination. Depends on the code you actually write but you usually write the code recommended by MSDN until you understand what you’re doing.
Post 04 Oct 2018, 21:07
View user's profile Send private message Visit poster's website Reply with quote
Ali.A



Joined: 08 Jan 2018
Posts: 126
how to use these for menu items:

MF_GRAYED
MF_DISABLED
MFS_GRAYED
MFS_DISABLED

_________________
Asm For Wise Humans
Post 05 Oct 2018, 17:20
View user's profile Send private message Reply with quote
Ali.A



Joined: 08 Jan 2018
Posts: 126
ok got it working, opened resource.inc and found the macro saying:
macro menuitem string,id,resinfo,status,type

string = menu_item
id = ID_EXIT
resinfo = MFR_END
status = MFS_GRAYED
type = MFT_? ... ; currently '0'
Code:
menu main_menu
       menuitem '&Menu',0,MFR_POPUP+MFR_END
                menuitem '&New' _ 'Ctrl+N',IDM_NEW
                menuseparator
                menuitem '&Exit' _ 'Ctrl+X',IDM_EXIT,MFR_END,MFS_GRAYED,0    




anyhow i have a new question about dialogs, found only two things i dont understand: (in resource.inc)

there is:
BUTTON -> button to click on
EDIT -> edit box
STATIC -> string
SCROLLBAR -> to scroll up/down the text

LISTBOX -> ???
COMBOBOX -> ???

any help!

_________________
Asm For Wise Humans
Post 05 Oct 2018, 21:08
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-2018, Tomasz Grysztar.

Powered by rwasa.