News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

A simple way to create a complex dialog

Started by jj2007, October 13, 2022, 09:30:58 PM

Previous topic - Next topic

jj2007

This dialog scans the current folder and all its subfolders for files of type *.asm, *.asc, *.rc or *.inc and opens them if the user clicks the listbox. You can also drag any file directly on the exe to display its content (caution with big jpgs...).

It will load and display correctly Ansi, Utf-8, Utf-16 and RTF files (the *.asc format is RTF).

On launch, the dialog will be centred, with 50% width and 70% height of your screen. It can be freely sized, but the listbox will not change its width.



So here is the source:

GuiParas equ "Simple dialog", w500, h700, m4, b LiteBlueGreen, icon Printer    ; width+height, margins, background colour
GuiMenu equ @File, &Open, &Save, &Print, -, E&xit, @Edit, Undo, Copy, Paste    ; this adds a menu
include \masm32\MasmBasic\Res\MbGui.asm
  GuiControl MyEdit, "RichEdit", wCL$(), bcol RgbCol(222, 255, 222), font -16, w1000-100
  GetFiles *.as?|*.rc|*.inc     ; put a selection of files into the Files$() array
  GuiControl MyList, "listbox", Files$(), x=1000-100, w=0+100
  GuiControl MyStatus, "statusbar", wRec$("Started "+fTime$())
  ToolTips hMyList, "select a file to open it"  ; assign a tooltip to the listbox

Event Command
  .if NotifyCode==LBN_SELCHANGE                 ; whenever the selection changes,
        SetWin$ hMyEdit=FileRead$(LbSel$)       ; open the file
  .else
        Switch_ MenuID                          ; menu IDs range from 0...last item
        Case_ 0: MsgBox 0, "Open is not implemented", "Hi", MB_OK
        Case_ 2: <MsgBox 0, Str$("%i pages printed", PrintRtf(hMyEdit, 2)), "PrintRtf:", MB_OK>
        Case_ 1 .. 6
                MsgBox 0, Str$("Menu %i: not implemented, add code here", MenuID), "Hello coder", MB_OK
        Endsw_
  .endif
GuiEnd

jj2007

Let's go through the lines:

GuiParas equ "Simple dialog", w500, h700, m4, b LiteBlueGreen, icon Printer ; width+height, margins, background colour
Gives a title/caption, specifies width=50% of screen width, height=70%; a 4 pixels margin, background colour, an icon. If you add x500 somewhere, the window will be right-aligned

GuiMenu equ @File, &Open, &Save, &Print, -, E&xit, @Edit, Undo, Copy, Paste ; this adds a menu
I sincerely hope this is self-explanatory; see also the WM_COMMAND handler above.

include \masm32\MasmBasic\Res\MbGui.asm
The include line comes after GuiParas and GuiMenu

GuiControl MyEdit, "RichEdit", wCL$(), bcol RgbCol(222, 255, 222), font -16, w1000-100
Creates a RichEd20.dll control; if there is a commandline, it loads the file. Background colour is light green, and we use a fairly big font. The width is 100% of the main window's client area, minus 100 pixels.

GetFiles *.as?|*.rc|*.inc
Put a selection of asc, asm, rc and inc files into the Files$() array

GuiControl MyList, "listbox", Files$(), x=1000-100, w=0+100
Creates a listbox control and loads it with the files found. The x position is at 100% of client area width, minus 100 pixels. Width is 0% plus 100 pixels, i.e. fixed (you could play with the variable and fixed part, e.g. as w=150+50: 15% of width, plus 50 pixels).

GuiControl MyStatus, "statusbar", wRec$("Started "+fTime$())
Adds a status bar with text Started 12:34:56 (controls expect text in wide format, therefore the wRec$)

ToolTips hMyList, "select a file to open it"
Just for fun, a tooltip. MyList is the control's ID assigned by the user, hMyList is its handle.

Event Command
The WM_COMMAND handler. At this point, NotifyCode and MenuID are available to the user, as shown above.

...

GuiEnd
End of code, ExitProcess etc. The GuiEnd macro handles most of the complicated stuff, so it does a bit more than end start :azn:

Warning: the Print menu item works perfectly (see PrintRtf). So if you open a major source of yours, don't be surprised if your printer starts rattling.

HSE

 Hi JJ :thumbsup:

1 - Why fcol don't work in rtf?

2 - Because You use diferent font sizes, configuration is a little complex. But perhaps You can make increase/decrease proportional to font size used from menu.

Regards, HSE.
Equations in Assembly: SmplMath

jj2007

Quote from: HSE on October 13, 2022, 11:58:11 PM
Hi JJ :thumbsup:

1 - Why fcol don't work in rtf?

It does, but only for plain text files (txt, asm, inc, rc, ...). Insert fcol Red to see the difference. You can set the global background colour of a rich edit control, but you cannot set a global foreground colour of the rtf file.

Quote2 - Because You use diferent font sizes, configuration is a little complex. But perhaps You can make increase/decrease proportional to font size used from menu.

I didn't want to overload the example, but you can try this:

  MakeFont hFixedFont, Height:20, PitchAndFamily:FIXED_PITCH
Event Command
  .if NotifyCode==LBN_SELCHANGE
invoke SendMessage, hMyEdit, WM_SETFONT, hFixedFont, 0
SetWin$ hMyEdit=FileRead$(LbSel$)

HSE

Equations in Assembly: SmplMath

zedd151

Sounds like a nice little project, Jochen.
Now back to the regularly scheduled replies.

jj2007

For a more complex dialog, go in RichMasm to File/New Masm source and click the red one: console/window/controls/simple MasmBasic templates. That opens \Masm32\MasmBasic\Res\SkelGui.asc

For lazy people, I attach the executable