Sometimes you run a program and you don’t want it to show any dialogs or User Interface at all. For example, if a dialog normally occurs in a program, you would rather not have the application show a MessageBox with the error because that could hang the application.

 

SYS(2335) - Unattended Server Mode was designed for this. Just turn off UI and instead of displaying a dialog, an error 1031 will be caused, which can be caught with a TRY..CATCH block and logged with no UI shown. The documentation for this function is not quite correct: it states that this function “applies only to .exe automation servers for which the StartMode property equals two.”. Try the code below to see it work when Startmode = 4 (runtime EXE). Comment out the “Exit” line to run the other test cases once you understand how the sample works.

 

Of course, even with UI disabled, you can call the MessageBox function in the Win32API via DECLARE-DLL  For an example of a multithreaded server calling MessageBox, see Webcrawl a blog to retrieve all entries locally: RSS on steroids

 

 

CLEAR

SET SAFETY OFF  

DIMENSION aTestCase[3]

aTestCase[1]="TestMessageBox"

aTestCase[2]="LocateFileDialog"

aTestCase[3]="SafetyDialog"

 

TEXT TO cstr  TEXTMERGE

      PROCEDURE Temp(UIMode as string,cTestCase as string) && command line parms are strings

            SYS(2335,VAL(UIMode))   && allow or disallow UI

            SET SAFETY OFF

            TRY

                  _screen.Caption="UIMode = "+UIMode+" "+cTestCase+" Startmode="+TRANSFORM(_vfp.StartMode)

                  DO CASE

                  CASE cTestCase="<<aTestCase[1]>>"

                        MESSAGEBOX("UI is allowed. UIMode = "+UIMode,0, cTestCase)

                  CASE cTestCase="<<aTestCase[2]>>"

                        *Try this scenario which will bring up a dialog

                        SELECT * FROM NonExistFile    && VFP will bring up dialog to find file

                  CASE cTestCase="<<aTestCase[3]>>"

                        SET SAFETY ON && Cause "Overwrite existing file dialog to appear"

                        CREATE TABLE temp (name c(10),data m)     && Create table with memo file

                        CREATE TABLE temp (name c(10),data m)     && Create table again to cause Overwrite dialog?

                  OTHERWISE

                        MESSAGEBOX("Unknown test case. UIMode = "+UIMode+" "+cTestCase)

                  ENDCASE

            CATCH TO oEx

                  SYS(2335,1) && Allow UI

                  MESSAGEBOX("Err caught UIMode = "+UIMode+":"+oEx.Message + " " +oEx.details,48,"Exception "+cTestCase)

            ENDTRY

           

ENDTEXT

STRTOFILE(cstr,"temp.prg")

BUILD PROJECT temp FROM temp

BUILD EXE temp FROM temp

FOR nTestCase=1 TO ALEN(aTestCase)

      FOR uiMode=1 TO 0 STEP -1

            ?"UIMode=",uiMode,aTestCase[nTestCase]

            cCmd="temp "+TRANSFORM(uiMode)+" "+aTestCase[nTestCase]

            ! &cCmd

      ENDFOR

      EXIT && comment this to run the other test cases

ENDFOR