Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A replacement to the native messagebox()

Forms & Screen

A replacement to the native messagebox()

by  Mike Gagnon  Posted    (Edited  )
You can use these classes to completely configure your own messagebox, all you need is to add the appropriate object and the appropriate methods (in the click event for example). Here is an example:
Code:
oForm=CREATEOBJECT("message_box")
oForm.addobject("btg_abort_retry_ignore","btg_abort_retry_ignore")
oForm.show()

Or
Code:
oForm=CREATEOBJECT("message_box")
oForm.addobject("btg_ok_cancel","btg_ok_cancel")
oForm.show()



Code:
DEFINE CLASS btg_container AS container
    top = 60
    left = 30
    Width = 220
    Height = 47
    BackStyle = 0
    BorderWidth = 0
    Name = "btg_container"
    visible = .t.
ENDDEFINE
DEFINE CLASS btg_abort_retry_ignore AS btg_container
    Name = "btg_abort_retry_ignore"
    ADD OBJECT mb_abort1 AS mb_abort WITH ;
        Top = 9, ;
        Left = 7, ;
        Name = "Mb_abort1"
        ADD OBJECT mb_retry1 AS mb_retry WITH ;
        Top = 9, ;
        Left = 80, ;
        Name = "Mb_retry1"
    ADD OBJECT mb_ignore1 AS mb_ignore WITH ;
        Top = 9, ;
        Left = 153, ;
        Name = "Mb_ignore1"
ENDDEFINE
DEFINE CLASS btg_accept_decline AS btg_container
    Name = "btg_accept_decline"
    ADD OBJECT mb_yes1 AS mb_yes WITH ;
        Top = 9, ;
        Left = 19, ;
        Width = 84, ;
        Caption = "I \<Accept", ;
        Name = "Mb_yes1"
    ADD OBJECT mb_no1 AS mb_no WITH ;
        Top = 9, ;
        Left = 117, ;
        Height = 29, ;
        Width = 84, ;
        Caption = "I \<Decline", ;
        Name = "Mb_no1"
ENDDEFINE
DEFINE CLASS btg_cool AS btg_container
    Name = "btg_cool"
    ADD OBJECT mb_ok1 AS mb_ok WITH ;
        Top = 9, ;
        Left = 80, ;
        Caption = "Cool!", ;
        Name = "Mb_ok1"
ENDDEFINE
DEFINE CLASS btg_no_buttons AS btg_container
    Name = "no_buttons"
ENDDEFINE
DEFINE CLASS btg_ok AS btg_container
    Name = "btg_ok"
    ADD OBJECT mb_ok1 AS mb_ok WITH ;
        Top = 9, ;
        Left = 80, ;
        Name = "Mb_ok1"
ENDDEFINE
DEFINE CLASS btg_ok_cancel AS btg_container
    Name = "btg_ok_cancel"
    ADD OBJECT mb_ok1 AS mb_ok WITH ;
        Top = 9, ;
        Left = 42, ;
        Name = "Mb_ok1"
    ADD OBJECT mb_cancel1 AS mb_cancel WITH ;
        Top = 9, ;
        Left = 118, ;
        Name = "Mb_cancel1"
ENDDEFINE
DEFINE CLASS btg_retry_cancel AS btg_container
    Name = "btg_retry_cancel"
    ADD OBJECT mb_retry1 AS mb_retry WITH ;
        Top = 9, ;
        Left = 38, ;
        Name = "Mb_retry1"
    ADD OBJECT mb_cancel1 AS mb_cancel WITH ;
        Top = 9, ;
        Left = 121, ;
        Name = "Mb_cancel1"
ENDDEFINE
DEFINE CLASS btg_sowhat AS btg_container
    Name = "btg_sowhat"
    ADD OBJECT mb_ok1 AS mb_ok WITH ;
        Top = 9, ;
        Left = 71, ;
        Height = 29, ;
        Width = 77, ;
        Caption = "So What!", ;
        Name = "Mb_ok1"
ENDDEFINE
DEFINE CLASS btg_thanks_nothanks AS btg_container
    Name = "btg_thanks_nothanks"
    ADD OBJECT mb_yes1 AS mb_yes WITH ;
        Top = 9, ;
        Left = 19, ;
        Width = 84, ;
        Caption = "\<Thanks", ;
        Name = "Mb_yes1"
    ADD OBJECT mb_no1 AS mb_no WITH ;
        Top = 9, ;
        Left = 117, ;
        Height = 29, ;
        Width = 84, ;
        Caption = "\<No Thanks", ;
        Name = "Mb_no1"
ENDDEFINE
DEFINE CLASS btg_yes_no AS btg_container
    Name = "btg_yes_no"
    ADD OBJECT mb_yes1 AS mb_yes WITH ;
        Top = 9, ;
        Left = 42, ;
        Name = "Mb_yes1"
    ADD OBJECT mb_no1 AS mb_no WITH ;
        Top = 9, ;
        Left = 118, ;
        Name = "Mb_no1"
ENDDEFINE
DEFINE CLASS btg_yes_no_cancel AS btg_container
    Name = "btg_yes_no_cancel"
    ADD OBJECT mb_yes1 AS mb_yes WITH ;
        Top = 9, ;
        Left = 8, ;
        Name = "Mb_yes1"
    ADD OBJECT mb_no1 AS mb_no WITH ;
        Top = 9, ;
        Left = 80, ;
        Name = "Mb_no1"
    ADD OBJECT mb_cancel1 AS mb_cancel WITH ;
        Top = 9, ;
        Left = 152, ;
        Name = "Mb_cancel1"
ENDDEFINE
DEFINE CLASS mb_button AS commandbutton
    Height = 29
    Width = 60
    FontName = "MS Sans Serif"
    Caption = ""
    i_rtnvalue = 1
    Name = "mb_button"
ENDDEFINE
DEFINE CLASS mb_abort AS mb_button
    Caption = "\<Abort"
    i_rtnvalue = 3
    Name = "mb_abort"
ENDDEFINE
DEFINE CLASS mb_cancel AS mb_button
    Caption = "Cancel"
    i_rtnvalue = 2
    Name = "mb_cancel"
ENDDEFINE
DEFINE CLASS mb_ignore AS mb_button
    Caption = "\<Ignore"
    i_rtnvalue = 5
    Name = "mb_ignore"
ENDDEFINE
DEFINE CLASS mb_no AS mb_button
        Caption = "\<No"
    i_rtnvalue = 7
    Name = "mb_no"
ENDDEFINE
DEFINE CLASS mb_ok AS mb_button
    Caption = "OK"
    Name = "mb_ok"
ENDDEFINE
DEFINE CLASS mb_retry AS mb_button
    Caption = "\<Retry"
    i_rtnvalue = 4
    Name = "mb_retry"
ENDDEFINE
DEFINE CLASS mb_yes AS mb_button
        Caption = "\<Yes"
    i_rtnvalue = 6
    Name = "mb_yes"
ENDDEFINE
DEFINE CLASS mb_main AS line
    Height = 67
    Width = 307
    Name = "mb_main"
    PROCEDURE execute
    ENDPROC
ENDDEFINE
DEFINE CLASS message_box AS form
    Height = 110
    Width = 287
    ShowWindow = 1
    DoCreate = .T.
    AutoCenter = .T.
    BorderStyle = 2
    Caption = ""
    ControlBox = .t.
    MaxButton = .F.
    MinButton = .F.
    WindowType = 1
    AlwaysOnTop = .T.
    *-- Return Value from the Messagebox
    i_rtnvalue = 0
    Name = "message_box"

    *-- Array containing settings for messagebox object
    DIMENSION a_settings[1]
    PROTECTED caption
    ADD OBJECT tmrclose AS timer WITH ;
        Top = 73, ;
        Left = 15, ;
        Height = 23, ;
        Width = 23, ;
        Enabled = .F., ;
        Name = "tmrClose"
    ADD OBJECT imgicon AS image WITH ;
        BackStyle = 1, ;
        Height = 32, ;
        Left = 16, ;
        Top = 15, ;
        Visible = .F., ;
        Width = 32, ;
        Name = "imgIcon"
    ADD OBJECT shpcover AS shape WITH ;
        Top = 46, ;
        Left = 10, ;
        Height = 14, ;
        Width = 17, ;
        BorderStyle = 0, ;
        Name = "shpCover"
    ADD OBJECT edit1 AS editbox WITH ;
        FontName = "MS Sans Serif", ;
        BackStyle = 0, ;
        BorderStyle = 0, ;
        Height = 16, ;
        Left = 68, ;
        Margin = 0, ;
        visible = .f.,;
        ScrollBars = 0, ;
        SpecialEffect = 1, ;
        Top = 13, ;
        Width = 207, ;
        IntegralHeight = .T., ;
        Name = "Edit1"
*!*	    *-- Configures the message_box object
    PROCEDURE configure
    ENDPROC
ENDDEFINE
DEFINE CLASS message_box_sdi AS message_box
    ShowWindow = 2
    DoCreate = .T.
    Name = "message_box_sdi"
    tmrClose.Name = "tmrClose"
    imgIcon.Name = "imgIcon"
    shpCover.Name = "shpCover"
    Edit1.Name = "Edit1"
ENDDEFINE

Mike Gagnon
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top