News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

A question on dialogs.inc

Started by clamicun, February 22, 2015, 09:02:19 PM

Previous topic - Next topic

clamicun

This is the syntax of Dialog.

Dialog MACRO quoted_text_title,quoted_font,fsize,dstyle,ctlcnt,tx,ty,wd,ht,bsize

e.g.
Dialog  "Title","Verdana",10,WS_VISIBLE+WS_SYSMENU,3,50,50,145,65,1024   

DlgEdit   ...
DlgButton ...
DlgGroup  ...

CallModalDialog xxx,xxx,dlg_xxx,0
;-------------

Now - how to do this ?

.const
MS_Font1     TCHAR 'Verdana',0
MS_Font2     TCHAR 'MS Sans Serif',0
dlg_title_de TCHAR 'Titel',0
dlg_title_en TCHAR 'Title',0
dlg_title_pt TCHAR 'Titulo',0

.data
dlg_fontsize dw 10
dlg_xpos     dw 50
dlg_ypos     dw 50
dlg_width    dw 145
dlg_height   dw 65

Dialog MACRO offset dlg_title_pt,offset MS_Font1,dlg_fontsize,WS_VISIBLE+WS_SYSMENU,3, \
                                           dlg_xpos,dlg_ypos,dlg_width,dlg_height,1024

"
"
"
Call ...
;-------------

Is this somehow possible ?
I don't imagine that multilanguage software uses 25 different dialogboxes.

dedndave

i don't know if the macro can do that

the easy way - don't use the macro
use a resource file, instead
there are many examples in the masm32\examples folders

clamicun

Thank you dedndave,
but I think you did not get me - or I did not express myself correctly.

I am asking if it is somehow possible to use variables in a dialogbox.

I know how to use resource files.
It is not the easy way in this case  because it seems to be simply impossible to insert variables - resource or macro - into a dialogbox. I tried for hours.

I asked the same question in the FASM forum without an answer.
But there must be a method, because otherwise any multilanguage programmer had to write 25 dialogboxes on 25 languages because of totally different fonts, different wordsize and more.

Have a good monday.




 

dedndave

what you may want to do is to examine the contents of the \masm32\include\dialogs.inc file
it's a plain text file

    ; ------------------------------------------------
    ; write unicode string at current location in EDI
    ; ------------------------------------------------
      ustring MACRO quoted_text
        LOCAL asc_txt
      .data
        asc_txt db quoted_text,0
      .code
        invoke MultiByteToWideChar,CP_ACP,MB_PRECOMPOSED,
               ADDR asc_txt,-1,edi,LENGTHOF asc_txt
        add edi, LENGTHOF asc_txt*2
      ENDM

    ; --------------
    ; dialog window
    ; --------------
      Dialog MACRO quoted_text_title,quoted_font,fsize,dstyle,ctlcnt,tx,ty,wd,ht,bsize
        push esi
        push edi
        invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT,bsize
        mov esi, eax
        mov edi, esi
        mov DWORD PTR [edi+0],  DS_SETFONT or dstyle
        mov WORD  PTR [edi+8],  ctlcnt
        mov WORD  PTR [edi+10], tx
        mov WORD  PTR [edi+12], ty
        mov WORD  PTR [edi+14], wd
        mov WORD  PTR [edi+16], ht
        add edi, 22
        ustring quoted_text_title
        mov WORD PTR [edi], fsize
        add edi, 2
        ustring quoted_font
      ENDM

    ; ------------------------------------
    ; create a modal dialog from the data
    ; written to the memory template.
    ; ------------------------------------
      CallModalDialog MACRO Instance,Parent,DlgProc,lpExtra
        invoke DialogBoxIndirectParam,Instance,esi,Parent,
                                      ADDR DlgProc,lpExtra
        push eax                ;; preserve return value
        invoke GlobalFree,esi   ;; free memory
        pop eax                 ;; restore return value
        pop edi
        pop esi
      ENDM


you can see that variables may be used, if you write your own code, rather than using the macros
creating a dialog with DialogBoxIndirectParam is a painful process   :lol:

but, i think it's a good exercise that everyone should try once   :t

dedndave

here is a thread in the old forum, where i was playing with it
i created the structures on the stack using PUSH (i.e. everything is reverse order)

http://www.masmforum.com/board/index.php?topic=17254.msg144816#msg144816

that thread is 5 pages long   :P

the MS docs - follow all the links on this page for further documentation

https://msdn.microsoft.com/en-us/library/windows/desktop/ms645461%28v=vs.85%29.aspx

clamicun

Very nice dedndave,
I'll check this out. As I said -  there must be asolution, because there is always a solution.
Thank you for your help.

dedndave

it's been a while, but as i recall, selecting fonts is a little tricky

and, fitting variable text into a window can be very difficult
if you have fixed text, it's not a problem

jj2007

It is certainly possible, see attachment, but it's not trivial. You need to intercept messages, which is possible with MasmBasic dialogs, but I doubt there is a simple solution for standard Masm32 dialogs. Hutch may correct me on this.

hutch--

Its usually the case if you want multi-lingual support in an OS specified dialog that you set the text dynamically at runtime. The system of building dialog templates in memory only differs from an RC script dialog in the way its loaded into memory. Both are basically a static template that is filled out first then loaded into memory.

If you need to alter the text for the title bar, text boxes or any other control that handles text, then you need to set it dynamically. This involves using the API GetDlgItem() to get the window handle of the control then you use SetWindowText() or WM_SETTEXT to change the text to what you require. This gets a bit more complicated with UNICODE in that you must store it somewhere and use the UNICODE API function to access the text.

clamicun

JJ,
somehow I don't see DlgMultiLanguage.asm, or you don't want us to see it?

http://masm32.com/board/index.php?action=dlattach;topic=4051.0;attach=3826

jj2007

Quote from: clamicun on February 26, 2015, 01:32:41 AM
JJ,
somehow I don't see DlgMultiLanguage.asm, or you don't want us to see it?

http://masm32.com/board/index.php?action=dlattach;topic=4051.0;attach=3826

Just open the *.asc file in WordPad or MS Word. They recognise RTF. Even better is \Masm32\MasmBasic\RichMasm.exe because it will create the rc file in the moment when you hit the F6 key, i.e. asm source and rc file are integrated and can be edited in one source file.