MSM-Workstation Tutorial (part 3/5) Window Main Menu Weve been talking about menus since the very beginning of this series on MSM-Workstation. Today we revisit this topic and offer some tips on making working with menus easier. When working with menus we can have a number of objects which do practically the same thing. They are:
Therefore in reality a particular something may be called up from various places. As developers we do not want to code the same thing three times (think about maintaining the stuff). One method of tackling this is to place (for example, in Common Code) a routine or function and call it up from the various locations. The method we present here is the %%Perform macro method. When the menu item is selected we trigger a button press event. This is the same as pressing the button. The %%Perform can also be used in other events. For example, a close button can be made to trigger a save event. In eCheques, the DCS Run button Finalize, offers to print and create the necessary output files using this method. MSM-Workstation also provides various macros (all of which have MWAPI equivalents) that allow one to %%Disable and %%Enable components. A pre defined macro called %%EnableMenu can be used to do the same for menu items. The syntax is %%EnableMenu(<AppId> ,<value>). This macro handles both enabling and disabling of menus. If you supply a <value> of 1 (TRUE) it is enabled, a <value> of 0 disables it. If you take a peek at the diagram on top, we have highlighted the application ID for this menu. Replace <AppId> with this name. Window CommonCode ; Changes the title colour of MenuTitle The routine above changes the color of the Title. Color is made up of Red,Green,Blue each ranging from 0 to 64k. This gives an astonishing number of colors but on many displays (e.g. 256 colors) minor increments will not reflect on the monitor. StopTimer %%Set(Timer1.Active,0) StartTimer %%Show(@%%CurrWin.) Besides stopping and starting the timer, our two routines also hide and show the current window. Observe how we use the MSM defined macro %%CurrWin and indirection to reference the window. Routine StartTimer also uses the %%SetFocus macro to force the menu into visibility. You may encounter a situation in which your user will click on an object other than your application. When you maintain extension window closes, focus will not return to the main menu. This addresses this scenario. Window Create N OutParam,SizeW,PosL,WinW The chunk above arranges the window so that it is will display correctly irrelevant of Windows 95 display changes. Observe how we set the title of the text box TITLE so that it reads from the information from the EXE. Control Exit Push %%Return Control MntExt Push Do StopTimer Control Timer1 timer Do ColorTitle Window MntExt Window CommonCode Init S (cExt,cName,cDept)="" When %%Disabling and %%Enabling objects, focus transfers to the next enabled object if there is one available. In our case we start off with only two objects enabled, the Extension and the Close button. The ExtChg flag variable, will become TRUE whenever a value is entered in the extension field. Try changing the %%Set(..Message null string and observe what happens. This can prove useful to display additional information about a record. ; Reads any existing entries into Array, displays them and highlights the first entry Do you recall the moniker, MWMdb? When we want to refer to a global residing on a particular database (be it local, remote or in memory) you should add the moniker. The ^GLB format will attempt to access a global in your application. These are read only and are normally used when you have a list of constants. UpdScrn N Buf,I You can store procedures and functions within library routines. These must be packaged into your application. Reference them as you would a normal library. While on the issue of libraries, note that MSM-Workstation does not incorporate in the EXE file all the %Routines that are actually available. This reasoning is more than justified because in the majority of occasions many of the %Routines are not used, so why increase the size of the EXE? In the System Browser, besides your development database, you have a %%App area under System. If your exe will call up an application listed here you must include it in your application. If while testing within MSM-Workstation everything works fine, while the EXE stops at the point it is invoking %routines, this could be your problem.
Window Create D Init Window Destroy ;Kill all variables used within module In this window, we permanently associate M variables to certain objects. Killing off the variables that are no longer needed when the window is being destroyed helps encapsulate your application even more. Control Clear Push N Changed,Buf Do Init Demonstrates has-record-been-changed logic. Control Close Push I cExt'="" I $$YN^%msgbox("Are you sure?","Exit
Program")="N" Q Control Close gotFocus ;This object gets focus when a valid entry is typed into A few paragraphs above we mentioned the ExtChg flag variable. Here is the position at which it is evaluated. When a valid extension is typed in, even though Name and Department are %%Enabled and one attempts to %%SetFocus on Name (the desired next object), focus would already have been pre-set and jumps to (in our case) Close. As we want the visual aspect to be correct, we have enabled an event for close so that when it gains focus it repositions itself correctly.
|