Projects > MasmBasic & the RichMasm IDE

A simple way to create a complex dialog

(1/2) > >>

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:


--- Code: ---GuiParas equ "Simple dialog", w500, h700, m4, b LiteBlueGreen, icon Printer ; width+height, margins, background colour
--- End code ---
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


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


--- Code: ---include \masm32\MasmBasic\Res\MbGui.asm
--- End code ---
The include line comes after GuiParas and GuiMenu


--- Code: ---GuiControl MyEdit, "RichEdit", wCL$(), bcol RgbCol(222, 255, 222), font -16, w1000-100
--- End code ---
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.


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


--- Code: ---GuiControl MyList, "listbox", Files$(), x=1000-100, w=0+100
--- End code ---
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).


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


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


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

...


--- Code: ---GuiEnd
--- End code ---
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.

jj2007:

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

1 - Why fcol don't work in rtf?
--- End quote ---

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.


--- Quote ---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.
--- End quote ---

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


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

--- End code ---

HSE:

--- Quote from: jj2007 on October 14, 2022, 12:18:08 AM ---I didn't want to overload the example,

--- End quote ---

 :thumbsup:

Navigation

[0] Message Index

[#] Next page

Go to full version