I made a small change in your code: For_ ecx ... ecx gives error.
MB protects ecx, but any WinApi call will trash it. So
push ecx
invoke SendMessage, ...
pop ecxis one option. Or use For_ ct=..., i.e. a global counter.
For the tutorial sake, here are the following questions and remarks I believe are relevant at this point:
1. It´s possible to create your own .data segment. I placed mine right below "include \masm32\MasmBasic\Res\MbGui.asm" and it all seemed to be ok.
Using the lineMax variable as an example, what would you choose: SetGlobals vs .data?
The best option is to use local variables, but if that is not possible:
- SetGlobals is easy to declare and uses the .data? section for frequently used variables with short encodings of the form
mov eax, [ebx+n]. Advantage: compact code. Disadvantage: under the hood, it needs ebx as an index register, so ebx is not available for other things unless you push+pop it.
- "Real" global variables have longer encodings, 5 bytes instead of 3. Good for rarely used variables that must be globally available.
include \masm32\MasmBasic\Res\MbGui.asm MUST go after GuiMenu. WHY JJ??
GuiParas and GuiMenu are equates that are being used by MbGui.asm. So they must be defined before the include.
Still on this topic, You wrote this: SetGlobals lineMax, tvi:TV_INSERTSTRUCT
lineMax has no size. Does MB assumes it´s a dword?
Yes, exactly, but it's not MB-specific. Masm does the same for local variables and args of a proc.
2. Recall "\masm32\AFprojs\__slimViewer\Text.asm", L$()
Is L$() a Global?
When using
Recall "some.txt", some$(), you get an array of strings, and arrays are always global.
How do we release the Recall (or close the file, free the memory, whatever is under the hood)?
No need to release it. If you are short of memory, you may use
Erase$ some$(), but normally it's not needed.
Say we want to Recall another file, Can we use L$ and overwrite the data in there?
Yes, the old array gets automatically heapfree'd, and a new one with the same name gets created.
3. Why MbGui.asm has MasmBasic inside and not the other way around?
4. Do you have plans on expanding GuiControls?
3. MbGui is newer and relies on the full MB library.
4. In principle, GuiControls should already work with all kind of controls, but some are special. Right now I am working on a spreadsheet/table/grid control (the name is not yet decided).
5. I forgot about this one: z$. It´s a porweful and useful one, but no reference in the help, Would explain it for us?
For Print and Let, MB uses an internal buffer for short strings, which allows e.g.
Let esi="Hello, now it's "+fTime$(0)+" on "+fDate$(0, "dd MMM yy")The Let and Print macros have access to the internal structure that registers the order of the strings etc, and can thus produce compact and powerful code.
In rare occasions, you may want a direct pointer, example:
mov eax, z$(Left$("abcde", 3))
PrintLine eax I haven't used z() for years, though. Be careful, check if it really works, and use Olly if in doubt. There is a reason why it is not documented; my advice: Use Cat$() instead, it's safer.