Enhancing VX-REXX with macros
The VX-REXX Editor (vrxedit.exe) is itself written in VX-REXX, which means that it can be modified and extended using its own facilities. When the editor starts, and before it loads a project, the file Profile.VRM is executed - this file can be found in the Macros folder inside the VX-REXX installation directory. Basic information on how this works can be found in the VX-REXX Programmer's Guide (progguid.inf) under "VX-REXX design time macros"; this article assumes you have read those pages.
There are a number of handy tricks that are effectively undocumented. Since the editor is an ordinary VX-REXX program, and its objects are ordinary VX-REXX objects, they can be manipulated fairly readily. For instance, the menu bar is called __VREMainMenuBar (internal objects seem all to have the prefix __VRE), so a new menu can be added by simply calling VRCreate.
A simple object enumeration produces a full list of manipulable objects in the development environment.
These are a few macros I've written over the years. If they are of value to you, feel free to use them; acknowledgement would be appreciated but not required.
Check for Numerics
My production code always has properly named objects (PB_Foobar rather than PB_3). A numeric tail on an object either means I forgot to name it, or the object was copied and pasted and never renamed (eg PB_Foobar1). This macro scans all the children of a window or group box, lists the children with numeric names, and optionally opens up their Settings dialogs.
CALL VREMACROADD "Check for numerics...","CHECKNUM.VRM","Window;GroupBox"
Separate file CheckNum.VRM:
/* Find objects with numbers at the end of their names */ PARSE ARG VXWIND,OBJ,WIND /* Normally such macros are window files, and the Main routine removes the first argument. Here there are three args. */ NUMS=0 CALL CHECKNUMBERS OBJ /* Trigger the recursive function */ MSG.0=NUMS IF NUMS=0 THEN CALL VRMESSAGE VXWIND,"No objects have trailing numbers.","Check Numerics" ELSE DO B.0=2 B.1="~OK" B.2="Open ~Settings" IF VRMESSAGESTEM(VXWIND,"MSG.","Objects with trailing numbers:","I","B.",1,1)=2 THEN DO I=1 TO MSG.0 CALL VRMETHOD WIND,"NOTEBOOKOPEN",MSG.I.HANDLE END END EXIT CHECKNUMBERS: PROCEDURE EXPOSE MSG. NUMS /* Recursive function to find all objects with trailing numbers */ PARSE ARG OBJ IF DATATYPE(RIGHT(VRGET(OBJ,"NAME"),1),"N") THEN DO /* This object's a problem! */ NUMS=NUMS+1 MSG.NUMS=VRGET(OBJ,"NAME") MSG.NUMS.HANDLE=OBJ END OBJ=VRGET(OBJ,"FIRSTCHILD") /* Find all children */ DO WHILE OBJ\="" /* While no more children */ CALL CHECKNUMBERS OBJ /* Check this object and all its children */ OBJ=VRGET(OBJ,"SIBLING") /* Next child or "" if last */ END RETURN
Strangely absent from the VX-REXX popup menu is a simple way to select all the children of an object. Fortunately it's not hard to add it.
CALL VREMACROADD "Select All","SELECTALL.VRM","Window;GroupBox"
Separate file SelectAll.VRM:
PARSE ARG VXWIND,OBJ,WIND I=0 O=VRGET(OBJ,"FIRSTCHILD") DO WHILE O\="" I=I+1 O.I=O O=VRGET(O,"SIBLING") END O.0=I CALL VRMETHOD WIND,"SELECTOBJECT","O.",1
Add OK & Cancel
When building standard dialogs, it's common to want OK and Cancel buttons at the bottom. Here's a one-click way to add them both. OK is set as the default button, and Cancel as the Cancel button.
The two objects are created, then selected, so if you'd rather have them over the right, or at the top, or wherever, it's easy to pick them up and move them.
Note that you still need to add code to them.
CALL VREMACROADD "Add OK & Cancel","ADDOKCANCEL.VRM","Window"
Separate file AddOKCancel.VRM:
PARSE ARG VXWIND,OBJ,WIND O.0=0 CALL VRMETHOD WIND,"SELECTOBJECT","O.",0 TOP=VRGET(WIND,"INTERIORHEIGHT")-482 O.1=VRCREATE(WIND,"PushButton","CAPTION","OK","HEIGHT",482,"WIDTH",964,"TOP",TOP,"DEFAULT",1,"NAME","PB_OK") O.2=VRCREATE(WIND,"PushButton","CAPTION","Cancel","HEIGHT",482,"WIDTH",964,"LEFT",964,"TOP",TOP,"CANCEL",1,"NAME","PB_CANCEL") O.0=2 CALL VRMETHOD WIND,"SELECTOBJECT","O." CALL VRMETHOD WIND,"UPDATELAYOUT"
That's all for now. Please add your own!