home *** CD-ROM | disk | FTP | other *** search
/ DOS Wares / doswares.zip / doswares / DATABASE / DBASE5 / CUA_SAMP.ZIP / MSGBOX.PRG < prev    next >
Encoding:
Text File  |  1994-06-24  |  3.8 KB  |  101 lines

  1. ***************************************************************
  2. * FILE MSGBOX.PRG
  3. * Sample program that goes with Chapter 21 of the "Programmer's
  4. * Guide." Displays a message box by using a custom object as a 
  5. * parameter to the procedure that creates the message box. 
  6. ***************************************************************
  7. *
  8. *-------------------------------------------------------------
  9. * Define a custom object to contain a set of memory variables.
  10. *-------------------------------------------------------------
  11. DEFINE OBJECT MsgStruc ;
  12.    CUSTOM ;
  13.       Message     ""        , ; 
  14.       BoxTitle    [Message] , ; 
  15.       DrawBox     .T.       
  16.  
  17. *-------------------------------------------------------------
  18. * Set some of the object's properties, then call the procedure 
  19. * that displays the message box. When DispMsg returns, release
  20. * the custom object and then release its obj. ref. variable.
  21. *-------------------------------------------------------------
  22. MsgStruc.Message = "You've really done it now!"
  23. MsgStruc.BoxTitle = [My Message]
  24. DO DispMsg WITH MsgStruc
  25. lVoid = MsgStruc.Release()
  26. RELEASE MsgStruc
  27.  
  28. *----------------------------------------------------
  29. * DispMsg
  30. * Displays a message using variables set in MsgStruc.
  31. *----------------------------------------------------
  32. PROCEDURE DispMsg
  33. PARAMETER poMsgStruc
  34.    *---------------------------------------------------
  35.    *-- Trim extra spaces on right of message and center 
  36.    *-- it if it's less than 55 characters wide. Use
  37.    *-- #define statements to avoid using variable slots.
  38.    *---------------------------------------------------
  39. #define MaxSpace 55
  40. #define FormWidth 63
  41.    cMsgText = TRIM(poMsgStruc.Message)
  42.    nMsgLen = LEN( cMsgText )
  43.    nMsgLeft = INT( (FormWidth - nMsgLen) / 2 )
  44.    IF nMsgLeft < 1
  45.       nMsgLeft = 1
  46.    ENDIF
  47.    *------------------------------------------
  48.    *-- Define the objects for the message box.
  49.    *------------------------------------------
  50.    DEFINE FORM MsgBox ;
  51.       PROPERTY  Top 5, Left 8, Height 9, Width FormWidth, ;
  52.                 Text poMsgStruc.BoxTitle
  53.    *--------------------------------------------------------------
  54.    *-- If the user did not cancel drawing the box around the text,
  55.    *-- draw the rectangle first so the text will show on top of 
  56.    *-- it. Size the rectangle to fit the length of the message. 
  57.    *--------------------------------------------------------------
  58.    IF poMsgStruc.DrawBox
  59.       IF nMsgLen > MaxSpace
  60.          DEFINE RECTANGLE r OF MsgBox FROM 0,1 TO 2, nMsgLen + 4
  61.       ELSE
  62.          DEFINE RECTANGLE r OF MsgBox FROM 0,1 TO 2, MaxSpace + 4
  63.       ENDIF
  64.    ENDIF
  65.  
  66.    *---------------------------------------------------
  67.    *-- Add the message indicated in the procedure call.
  68.    *---------------------------------------------------
  69.    DEFINE TEXT Msg OF MsgBox ;
  70.       PROPERTY  Top 1, Left nMsgLeft, Text cMsgText, Border .F.
  71.  
  72.    *--------------------------------------------
  73.    *-- Add an OK pushbutton, then give it focus.
  74.    *--------------------------------------------
  75.    DEFINE PUSHBUTTON pbOk OF MsgBox ;
  76.       PROPERTY  Top 5, Left 26, Width 8, Text "OK",;
  77.       OnClick OKHand
  78.  
  79.       lVoid = MsgBox.pbOk.SetFocus()
  80.    
  81.    *--------------------------------------
  82.    *-- Open message box as a modal window.
  83.    *--------------------------------------
  84.    lVoid = MsgBox.ReadModal()
  85.  
  86.    *---------------------------------------------------------
  87.    *-- Release message box and its object reference variable
  88.    *-- after its pushbutton's OnClick handler returns.
  89.    *---------------------------------------------------------
  90.    lVoid = MsgBox.Release()
  91.    RELEASE MsgBox
  92. RETURN
  93.  
  94. PROCEDURE OKHand
  95. *------------------
  96. *  Closes the form.
  97. *------------------
  98.    lVoid = Form.Close()
  99. RETURN
  100. *--End of program msgbox
  101.