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

Main Menu


Started by jj2007, May 23, 2012, 10:16:07 PM

Previous topic - Next topic


To all who installed version 7 November: There was a little glitch with SaveImageToFile and Unicode file names. It's fixed, please install version 8 November (thanks to Mike for the inspiration :P).

The update allows also Unicode launches now, e.g. passing Chinese text to a MessageBox.exe in Russian:

include \masm32\MasmBasic\      ; download
  Launch "Окносообщения.exe 您可以将中文文本传递到应用程序。"


Attached two new examples - extract to a new folder, launch
a) LaunchUnicodeExes.exe (should produce what's shown in the screenshot)
b) ImageViewAndRotate.exe
to test them. Grateful for feedback 8)

Sources are included as *.asc files, building requires Masm32 and the latest November 9 MasmBasic.


Download update 26 Nov 16:

Inter alia, GuiImage handles now animated GIFs automatically; search \Masm32\MasmBasic\MbGuide.rtf for .MbGui

Example (attached):

GuiParas equ "GuiImage demo", x100, y100, w540, h180, bnone, m0, deb0  ; no background, margin zero, debug 0
include \masm32\MasmBasic\Res\MbGui.asm                  ; part of MasmBasic
Event Paint
  GuiImageSpeed 200                  ; animation speed 200%
  GuiImage "\Masm32\examples\exampl04\car\car.jpg", fit            ; background
  GuiImage ";attach=6;type=avatar", 300, 64, 40, 40
  GuiImage "\masm32\MasmBasic\icons\Smiley.ico", 118, 40, 32, 32
  GuiImage 48, 170, 56, 64, 64                  ; resID, x y w h
Rsrc            ; **** during assembly, RichMasm exports this section as filename.rc ****
32512 ICON "\\masm32\\MasmBasic\\icons\\Globe.ico"
48 RCDATA "Shooter.gif"

The demo displays
- a static background car.jpg
- an avatar (members only, sorry :biggrin:)
- a smiley (the car needed a little decoration)
- and an animated GIF from the resources


Version 30.11.16 adds a new functionality to the StringToArray command:

include \masm32\MasmBasic\      ; download
  Let esi="Open"      ; just an example: Open "O", #1, "somefile.txt"
  StringToArray 123, mbi$()    ; 123 is the resource ID
  .While 1
      Let esi=Input$("Search for macro: ", esi)
      .Break .if Len(Trim$(esi))==0
      push mbi$(?)      ; #elements on stack
      xor ecx, ecx
            .if Instr_(mbi$(ecx), esi, 1)==1      ; case-insensitive search
                  .Break .if Instr_(mbi$(ecx), "macro", 5)      ; case-insensitive, full word
            inc ecx
      .Until ecx>=stack
      dec ecx
            inc ecx
            PrintLine mbi$(ecx)
      .Until Instr_(mbi$(ecx), "endm", 5)==1 || ecx>=stack
      pop edx
  Print "bye"
  Delay 500

Rsrc      ; when hitting F6, RichMasm exports this section to [filename].rc
123 RCDATA "\\Masm32\\MasmBasic\\"

In this snippet, StringToArray converts an embedded text file ( to a string array.

Project is attached, including the rc file, which is not needed if you build the source with RichMasm.


Update 12 December features an improved handling of toolbars, see an example in the small editor thread.

One new feature, you can extract a file from resources:

  FileWrite "MyFile.txt", "MyString"            ; opens a file and writes a string to file
  FileWrite "MyFile.txt", "MyString", 2         ; same but writes only first 2 bytes
  FileWrite "MyFile.rtf", stream:hRichEdit      ; save contents of the RichEdit control
  FileWrite "MyFile.uctxt", stream:hRichEdit, SF_TEXT or SF_UNICODE  ; same but specify a format
  If_ Not Exist("build.bat") Then FileWrite "build.bat", res:99      ; extract a file from RCDATA resource #99
  FileWrite "MyFile.txt", "MyString", xmm0      ; sets the timestamp in xmm0
Rem      returns Close retval in eax and bytes written in edx


Update 16 December is inspired by Caballero's Ancient DOS sounds thread and uses the new 'get a string array from resources' feature:

include \masm32\MasmBasic\      ; download (needs version 16 December 2016 or later)
  StringToArray 123, music$()      ; get an array from resources
  For_ ct=0 To eax-1
      Sound music$(ct)

32512 ICON      "\\Masm32\\MasmBasic\\icons\\Smiley.ico"
123 RCDATA      "Song4MasmBasic.txt"

The attachment contains a Pelles C source (BeepWC01.asc) based on Caballero's version for Tiny C. The switch #define Export2MasmBasic 0 in line 2 allows to export his sound as a text file with entries meaning pitch:duration:pause:


Please install update 20 December 2016; inter alia, new events Data and DropFiles were added:

      Event Data      ; WM_COPYDATA
            MsgBox 0, CopyData$, "Received:", MB_OK
      Event DropFiles      ; loads the Files$() array; use wRec$() to convert Utf8 file names to true Unicode
            wMsgBox 0, wCat$(wStr$("%i files dropped, first one is\n[", Files$(?))+wRec$(Files$(0))+"], last one is "+CrLf$+"["+wRec$(Files$(Files$(?)-1))+"]"), "Event Dropfiles:", MB_OK or MB_TOPMOST
            Store "~tmpDropped.txt", Files$()      ; write dropped filenames to a text file in Utf8 format

As with GetFiles, file names obtained in the DropFiles Event are in Utf8 format.


MasmBasic update 29 December 2016 is out, please reinstall.

In honour of the "Editor for testing" thread, I've added a new handy macro:

Print "This application uses ComCtl32.dll version ", ComCtl32$()

Output: This application uses ComCtl32.dll version 6.16 (provided your resources and manifests are 100% ok :icon_mrgreen:)


Found a weird bug on the latest (29 December 2016) version:
While RichMasm is opened, if you click the "X" button, RichMasm won't quit, but only minimze itself instead.
Gotta terminate it manually using Task Manager.

Happens on 32-bit Windows 10.


It's not a bug, it's a feature :P

Seriously: MbGuide.rtf is a special document, it will only minimise if you try close it. But if you close it while it is minimised, it will indeed close (besides, it will also close if no other docs are open in RichMasm).

The reason for this special behaviour is that it also serves as "F1 help". Select a keyword, then hit F1:
- if it's a MasmBasic keyword like Print, the paragraph on Print will be displayed in MbGuide.rtf
- if it's not found in MbGuide.rtf, e.g. CreateWindowEx, RichMasm will pass on the request to the program that follows in \Masm32\MasmBasic\Res\menus.ini, i.e. Win32.hlp:


Thus, you get most of the time the help you expect, simply by selecting the keyword and hitting F1.

Note that for the MasmBasic keywords, about 200, RichMasm has another mechanism: Hover over the keyword, e.g. GetFiles, until the mouse cursor turns into a question mark. Then right-click (I'm afraid this is case-sensitive, so getfiles will work only with F1).


Just found a lengthy article on Printing text in Win32 can be a little complicated posted by Paul Brennick over 8 years ago - I wish I had seen it earlier, it would have saved me a lot of work :(

Anyway, here is a simple method to print the content of a RichEdit control. This snippet reads a file from the commandline, and if you hit Ctrl P, its contents get printed - not in the sense of console print, but in the sense of: on real paper. Here is the source:

include \masm32\MasmBasic\Res\MbGui.asm      ; download (version 5 January 2017 or later)
  GuiControl MyEdit, "RichEdit"             ; create a RichEdit control
  If_ wExist(wCL$()) Then <SetWin$(hMyEdit)=wFileRead$(wExist$)>
Event Key
  If_ KeyCtrl && (VKey==VK_P || VKey==-VK_P) Then <MsgBox 0, Str$("%i pages printed", PrintRtf(hMyEdit, 2)), "PrintRtf:", MB_OK>

Full project attached. The PrintRtf() macro needs a handle to a RichEdit control, and takes optional parameters as follows (excerpt from \Masm32\MasmBasic\MbGuide.rtf):

- if text is selected, then only the selection will be printed
- optional second arg: 0=use default printer, 1=use once the printer dialog, 2=use it always
- optional: margins in mm, e.g. void PrintRtf(hMyEdit, 0, 20, 20, 15, 20)       ; left, top, right, bottom
- printer settings like orientation etc are kept for the program's duration


include \masm32\MasmBasic\      ; download (version 11 January 2017 required)
  UnzipInit ""
  .if Sign?
      Print eax            ; print an error message
      For_ ecx=0 To edx-1      ; #files returned in edx
            mov esi, Files$(ecx)
            .if Rinstr(esi, "/")     ; zipfiles use forward slashes
                  xchg eax, esi      ; we don't display the full path
                  inc esi
            PrintLine Str$(GfSize(ecx)), Tb$, GfDate$(ecx), Spc2$, GfTime$(ecx), Tb$, esi
            .if Instr_(esi, ".pdf", 1)
                  UnzipFile(ecx, Cat$(Left$(MbExeFolder$)+":\Masm32\bin\"))
                  ShEx Cat$("\Masm32\bin\"+esi)


With certain types of Unicode text files, Recall added garbage to the last string read. This is fixed with MasmBasic version 27 Jan 2017 - please reinstall. The following will work properly now:

include \masm32\MasmBasic\Res\MbGui.asm      ; download
  Recall "", L$()
Event Paint
  For_ ct=0 To L$(?)-1
      GuiText 7, ct*16+7, Str$("# %i ", ct+1)
      GuiText 90, ct*16+7, L$(ct)

The snippet above downloads the text from my personal website. Here is a variant where Chinese text is used in $Data statements:

GuiParas equ "A Chinese Poem", x300, y70, w300, h125, bRgbCol(255, 255, 222)
include \masm32\MasmBasic\Res\MbGui.asm
$Data 月夜
$Data 霜风呼呼地吹着,
$Data 月光明明地照着。
$Data 我和一株顶高的树并排立着
$Data 却没有靠着  。
Read poem$()            ; translate $Data elements to a string array
Event Paint
  For_ ct=0 To poem$(?)-1
      GuiText 7, ct*16+7, Str$("# %i ", ct+1)      ; display the array elements
      GuiText 60, ct*16+7, poem$(ct)

The screenshot shows how it looks like in RichMasm and in the little window created by the above code.
Projects attached, feedback welcome of course.


Update 1 February fixes two bugs:
1. One minor bug with Chr$("The letter is ", reg32): if reg32 was edi, the displayed letter was wrong. This works now (attached):

GuiParas equ "Key events only", x50, y50, w100, h60, s0
include \masm32\MasmBasic\Res\MbGui.asm
GuiControl MyStatic, "static"
Event Key
  SetWin$ hMyStatic=Chr$("You pressed ", VKey)            ; requires MasmBasic of 1 February 2017

2. Val() and MovVal() returned -127 (error) in edx for the string 0 if there was text after the zero delimiter, e.g. sometext db "0", 0, "more text"


New FindProcess() function:

include \masm32\MasmBasic\      ; download
  .if FindProcess("Explоrer.exe")
      Inkey Str$("FindProcess returned ID %i\n", [eax.PROCESSENTRY32.th32ProcessID])
      Inkey "Process not found, error: ", Err$()

Attached a demo: Extract all files to a folder and launch first Explorer.exe (don't close the MsgBox), then the FindProcessDemo.exe

The macro is still based on Tim's example, although I managed to bring it down to exactly 80 bytes, using three (!) times the extremely old xchg instruction :biggrin:

Don't worry, the explorer.exe won't do any harm to your machine. Really :P
You can see it in Olly if you don't trust me; or look at Jotti's scan results
Sorry, no manifest, no vcb, "0/18 scanners reported malware" ... although, an intelligent AV should indeed shout foul 8)

EDIT: Explorer source added