Announcement

Collapse
No announcement yet.

use ESC key???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    use ESC key???

    hi,

    my main DIALOG , how can i activate/deactivate the ESC key to do certain task? like closing the dialogue. hints?????

    #2
    Ok a hint:
    <Esc> ==> WM_COMMAND/IDCANCEL
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


      #3
      Michael points out the key equate, bu you will still need to set a STATIC (or GLOBAL) flag to do what you want.
      Code:
      #COMPILER PBWIN
      #COMPILE EXE
      #DIM ALL
      #INCLUDE "Win32API.inc"
      
      %IDD_DIALOG1  =  101
      %IDC_BTN_TEST = 1001
      
      CALLBACK FUNCTION MainDlgProc()
          STATIC escflag AS LONG
      
          SELECT CASE AS LONG CB.MSG
              CASE %WM_INITDIALOG
                  escflag = 0
      
              CASE %WM_COMMAND
                  SELECT CASE AS LONG CBCTL
                      CASE %IDC_BTN_TEST
                          IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                              'toggle the STATIC escflag
                              IF escflag = 0 THEN  escflag = 1 ELSE escflag = 0
                              EXIT FUNCTION
                          END IF
                      CASE %IDCANCEL
                          IF escflag = 0 THEN
                              DIALOG SET TEXT CBHNDL,"Hint: Press Test key to set ESC to quit mode"
                              EXIT FUNCTION
                          ELSE
                              DIALOG END CBHNDL
                          END IF
                  END SELECT
          END SELECT
      END FUNCTION
      
      FUNCTION PBMAIN () AS LONG
          LOCAL hDLG AS DWORD
          LOCAL lRslt  AS LONG
          DIALOG NEW PIXELS, 0, "Test This",,, 640, 480, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg
          CONTROL ADD BUTTON, hDlg, %IDC_BTN_TEST, "Test", 500, 10, 100, 100
      
          DIALOG SHOW MODAL hDlg, CALL MainDlgProc TO lRslt
      END FUNCTION
      Rick Angell

      Comment


        #4
        This seems to work without a flag?
        Code:
            Case %WM_COMMAND
              Select Case As Long CbCtl
                ' Built-in. Sent to dialog by Escape and Return keys..
                Case %IDCANCEL          ' Escape Key
                  If CbCtlMsg = %BN_CLICKED Then
                    Dialog End CbHndl
                  End If
                Case %IDOK              ' Return Key
                  If CbCtlMsg = %BN_CLICKED Then
                    WinBeep 800, 50
                  End If
        Oh - I see. Rick's code activates / deactivates.
        Last edited by Dave Biggs; 3 Nov 2008, 10:47 AM.
        Rgds, Dave

        Comment


          #5
          >bu you will still need to set a STATIC (or GLOBAL) flag to do what you want

          Nah, ya don't.

          Remember, you don't have to "de-activate" when you can just "ignore." If the key does nothing, the key does nothing.

          "disable" is a HOW.... the "what" here is "make nothing happen"
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


            #6
            That was not the case. The case was:
            how can i activate/deactivate the ESC key to do certain task?
            (Emphasis added)

            Typically a two state situation requires a state test. The decision to ignore als requires aa test since this is being trapped in the dialog's callback. Without testing a "flag" variable, which could just as well be some other existing program variable, the program does not know to "ignore" the escape key press or act on it. Surely one could pass the "flag", e.g. in a USER memory of say the dialog, but a flag it is and "static" it is none the less.
            Rick Angell

            Comment


              #7
              thank u all for the replies.
              i managed to close app when press ESC.
              but if i remove/comment the part of code responsible for ESC, and press ESC it runs a control (button). why??
              hints
              thanx

              Comment


                #8
                If you could post some code to illustrate the problem we would be able to help more easily.
                Rgds, Dave

                Comment


                  #9
                  Originally posted by Raed Abu-Sanad View Post
                  but if i remove/comment the part of code responsible for ESC, and press ESC it runs a control (button). why??
                  Raed,

                  please take some time to write, maybe it's just me, but If someone posts questions here in "chat-I-don't-have-time-to-write"-slang, It's a lot of harder (for me) to understand them

                  B2T:
                  Do you have in your callback something like
                  Code:
                   CASE %IDC_BUTTON_send
                                         IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                  for every button? All controls can recieve a bunch of messages, maybe you didn't catch the ones, which shouldn't trigger the button?

                  Regards,
                  Marc Giesmann
                  Last edited by Marc Giesmann; 4 Nov 2008, 09:45 AM. Reason: Too goddamn stupid to use codetags ;)

                  Comment


                    #10
                    Make sure you are not using duplicate ID's %IDCANCEL = 2

                    Same effect if I do this...

                    Code:
                    CONTROL ADD BUTTON, hDlg, %IDC_MTP_INPUT_CANCEL_BUTTON, "&Cancel", 75, 53, 40, 16
                     ...
                     
                    %IDC_MTP_CANCEL_BUTTON   = 2   'Cancel button <-allow Esc Key
                     ...
                    
                    CASE %WM_COMMAND
                         SELECT CASE CBCTL
                               CASE %IDC_MTP_CANCEL_BUTTON
                                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                            'cancel, abort changes
                                            DIALOG END CBHNDL, 0
                                        END IF

                    Comment

                    Working...
                    X
                    😀
                    🥰
                    🤢
                    😎
                    😡
                    👍
                    👎