How to recognize "Cancel" pushed with DLG in CMAC?

Home Forums Multi-Edit Support How to recognize "Cancel" pushed with DLG in CMAC?

This topic contains 2 replies, has 2 voices, and was last updated by  HerbJones 9 months, 3 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #23701

    HerbJones
    Participant

    In this simple CMAC macro, how would I set a variable to show that cancel was pressed instead of OK?

    I would like to somehow break, or stop, the macro if cancel is pressed instead of having it continue on.

    I can’t figure out what variable is set, or how to differentiate that Cancel is pressed.
    ————————————————-
    #include WINDOW.SH
    #include DIALOG.SH

    macro RADIO FROM EDIT TRANS {
    #define Radio1_ctrl 1022 //needs any old unique handle
    #define Radio2_ctrl 1023 //needs any old unique handle
    str press_s;
    int dlg;

    DlgCreate(dlg); // used to create the HANDLE of the dialog.

    DlgAddCtrl(dlg, DLG_RadioButton, “Radio &1”, Dlg_PosOffset | 1, Dlg_PosOffset, 0, 0, Radio1_ctrl, 0, “” );
    DlgSetInt(dlg,Radio1_ctrl,1);

    DlgAddCtrl(dlg, DLG_RadioButton, “Radio &2”, Dlg_PosOffset | 13, Dlg_PosOffset, 13, 0, Radio2_ctrl, 0, “” );
    DlgSetInt(dlg, Radio2_ctrl, 0);

    DlgAddCtrl(dlg, DLG_PushButton, “OK”, 9, Dlg_PosOffset | Dlg_Units | 15,Dlg_StanBtnWidth, 0, 101, Dlgf_DefButton, “/R=1”); //101 handle of ok_ctrl, /R=1 tells prompt Oselection is made and exit
    DlgAddCtrl(dlg, DLG_PushButton, “Cancel”, Dlg_PosOffset | Dlg_StanBtnWidth + 1, Dlg_PosOffset, Dlg_StanBtnWidth, 0, 102, Dlgf_DefButton, “/R=3”); //102 handle of cancel_ctl

    // DLGEXECUTE actually invokes the dialog box
    DlgExecute(dlg,101, “Choose One…”,””, “”,0); //101 = ok_ctrl will initially be highlighted

    //Check on which has variable set.
    if(DlgGetInt(dlg,Radio1_ctrl)==1) {press_s=”Radio1″;};
    if(DlgGetInt(dlg,Radio2_ctrl)==1) {press_s=”Radio2″;};

    Make_Message(“Pressed…” + press_s);

    }

    Thanks!

    #23703

    Clay Martin
    Keymaster

    Hi,
    Here is a simple example, a dialog box with a string field, ok and cancel.

    str Program ;
    int dlg,result;
    /*** Get macro Name ***/
    DlgCreate(dlg);
    DlgAddCtrl( dlg, DLG_Static, “Enter macro Name”, 8, 2, 0, 2,101,0, “” );
    // here is the field for the macro name note the 102
    DlgAddCtrl( dlg, DLG_TEXT, “”, 1, 3, 40, 0, 102, 0, “”);
    // here ok button note R=1
    DlgAddCtrl( dlg, DLG_PushButton, “Ok”, 8, 5, DLG_StanBtnWidth,0,110,0, “/R=1” );
    //here is cancel, note r=0
    DlgAddCtrl( dlg, DLG_PushButton, “Cancel”, 20, DLG_PosOffset, DLG_StanBtnWidth,0,111,0, “/R=0″ );
    //show the dialog
    result = DlgExecute( dlg, 102,”Macro Maker”, “”,””, 0 );
    // check to see if cancel hit, if it was kill the dialog and proceed past the processing of the result
    if ( result == 0) {
    DlgKill(dlg);
    goto Quit;
    }
    // if not cancel, get the text value, kill the dialog and proceed with what we are doing note the 102.
    Program = DlgGetStr(dlg,102);
    DlgKill(dlg);

    //processing of positive result below this

    //then at the end of the macro
    Quit:
    REFRESH = oldrefresh;
    // macro ends after this.

    Hope this helps,
    Clay

    #23704

    HerbJones
    Participant

    Took me quite a bit of playing, but I got it figured out just before you sent this.

    You have to do a IntegerVariable=DLGExecute.

    In my code, junki will be the x value in “/R=x”:

    DlgCreate(dlg); // used to create the HANDLE of the dialog.

    DlgAddCtrl( dlg, DLG_RealNumber, “”, Dlg_PosOffset | 0, Dlg_PosOffset, 21, 0, realnum_ctrl, 0, “” );

    DlgAddCtrl(dlg, DLG_PushButton, “&OK”, 7, Dlg_PosOffset | Dlg_Units | 15,Dlg_StanBtnWidth, 0, ok_ctrl, Dlgf_DefButton, “/R=1”); //101 handle of ok_ctrl, /R=1 tells prompt Oselection is made and exit

    DlgAddCtrl(dlg, DLG_PushButton, “&Next Via”, Dlg_PosOffset | 20, Dlg_PosOffset, 30, 0, pushbtn_ctrl, 0, “/R=3” );

    junki=DlgExecute(dlg,realnum_ctrl, “INPUT MATCHING X (xxxx.xxx) or (N)EXT VIA…”,””, “”,0); //1text_ctrl = will initially be highlighted
    //junks=DlgGetStr(Dlg,pushbtn_ctrl); // pressed “Next”

    make_message(“”);
    make_message(str(junki));

    Thanks for the help!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.