Announcement

Collapse
No announcement yet.

Keys Return Escape Delete

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

  • Keys Return Escape Delete

    A few weeks ago I asked how to detect these keys.
    Lots of people sent great advice which I adopted.
    Those methods are working just fine when a text box has the focus.
    But how to detect the keys when the dialog has the focus ?
    I tried to adapt the textbox ideas, but failed.
    Someone out there must have solved this.
    Let's hope he's watching his Forum !

  • #2
    If you search the forums using 'keyboard input" or "key input' or something like that you'll find several posts with key trapping routines. Four names, and there are more, to search under if you wish are Richard Angell, Pierre Belisle, Timm Motl, Elias Montaya(I hope I got those names right.)

    Rod
    Rod
    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

    Comment


    • #3
      Accelerator keys might be the answer.
      Check this thread: http://www.powerbasic.com/support/pb...ad.php?t=22214
      Rgds, Dave

      Comment


      • #4
        Rodney, Yes, I have searched the Forum over and over again. Even so, I can't get the results I want. My code correctly traps the keys which interest me, but does so ONLY ONCE. When any such key has been trapped, and dealt with, the code fails to detect any of the keys ever again. Also, to make my situation as clear as possible; there is just the main dialog, with a menu which works perfectly. There are no other controls on the dialog. My code for the dialogcallbackprocedure is as follows.
        SELECT CASE AS LONG CBMSG
        CASE %WM_KEYUP
        SELECT CASE CBCTL
        CASE %VK_RETURN
        MSGBOX "Return key pressed"
        FUNCTION = 0
        EXIT FUNCTION
        CASE %VK_ESCAPE
        MSGBOX "Escape key pressed"
        FUNCTION = 0
        EXIT FUNCTION
        CASE etc

        Any ideas ?

        Comment


        • #5
          Try this:
          Code:
          PBFORMS CREATED V1.51
          '--------------------------------------------------------------------------------------------------
          ' The first line in this file is a PB/Forms metastatement.
          ' It should ALWAYS be the first line of the file. Other
          ' PB/Forms metastatements are placed at the beginning and
          ' end of "Named Blocks" of code that should be edited
          ' with PBForms only. Do not manually edit or delete these
          ' metastatements or PB/Forms will not be able to reread
          ' the file correctly.  See the PB/Forms documentation for
          ' more information.
          ' Named blocks begin like this:    #PBFORMS BEGIN ...
          ' Named blocks end like this:      #PBFORMS END ...
          ' Other PB/Forms metastatements such as:
          '     #PBFORMS DECLARATIONS
          ' are used by PB/Forms to insert additional code.
          ' Feel free to make changes anywhere else in the file.
          '--------------------------------------------------------------------------------------------------
          
          #COMPILE EXE
          #DIM ALL
          
          '--------------------------------------------------------------------------------------------------
          '   ** Includes **
          '--------------------------------------------------------------------------------------------------
          #PBFORMS BEGIN INCLUDES
          #IF NOT %DEF(%WINAPI)
            #INCLUDE "WIN32API.INC"
          #ENDIF
          #PBFORMS END INCLUDES
          '--------------------------------------------------------------------------------------------------
          
          '--------------------------------------------------------------------------------------------------
          '   ** Constants **
          '--------------------------------------------------------------------------------------------------
          #PBFORMS BEGIN CONSTANTS
          %IDD_DIALOG1 = 101
          #PBFORMS END CONSTANTS
          '--------------------------------------------------------------------------------------------------
          
          '--------------------------------------------------------------------------------------------------
          '   ** Declarations **
          '--------------------------------------------------------------------------------------------------
          DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
          DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
          #PBFORMS DECLARATIONS
          '--------------------------------------------------------------------------------------------------
          
          '--------------------------------------------------------------------------------------------------
          '   ** Main Application Entry Point **
          '--------------------------------------------------------------------------------------------------
          FUNCTION PBMAIN()
            ShowDIALOG1 %HWND_DESKTOP
          END FUNCTION
          '--------------------------------------------------------------------------------------------------
          
          '--------------------------------------------------------------------------------------------------
          '   ** CallBacks **
          '--------------------------------------------------------------------------------------------------
          CALLBACK FUNCTION ShowDIALOG1Proc()
          
            SELECT CASE AS LONG CBMSG
              CASE %WM_INITDIALOG
                ' Initialization handler
          
              CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CBWPARAM THEN
                  ' Save control focus
                  hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                  ' Restore control focus
                  SetFocus(hWndSaveFocus)
                  hWndSaveFocus = 0
                END IF
          
              CASE %WM_COMMAND
                ' Process control notifications
                'SELECT CASE AS LONG CBCTL
                  
              CASE %WM_KEYUP
                  SELECT CASE CBCTL
                    CASE %VK_RETURN
                      MSGBOX "Return key pressed"
                      'FUNCTION = 0
                      'EXIT FUNCTION
                    CASE %VK_ESCAPE
                      MSGBOX "Escape key pressed"
                      'FUNCTION = 0
                      'EXIT FUNCTION
                    CASE %VK_A
                      MSGBOX "A key pressed
          
                  'END SELECT
                END SELECT
            END SELECT
          END FUNCTION
          '--------------------------------------------------------------------------------------------------
          
          '--------------------------------------------------------------------------------------------------
          '   ** Dialogs **
          '--------------------------------------------------------------------------------------------------
          FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
            LOCAL lRslt AS LONG
          
          #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
            LOCAL hDlg  AS DWORD
          
            DIALOG NEW hParent, "testy", 323, 148, 284, 189, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR _
              %WS_SYSMENU OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
              %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
              %WS_EX_RIGHTSCROLLBAR, TO hDlg
          #PBFORMS END DIALOG
          
            DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
          
          #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
          #PBFORMS END CLEANUP
          
            FUNCTION = lRslt
          END FUNCTION
          '--------------------------------------------------------------------------------------------------
          This works in PBWin 8.04

          Rod
          Rod
          I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

          Comment


          • #6
            Thinking a little more on it, if you have a menu with Accelerator keys, the key presses may be being handled in some other fashion that is interfering with what you want to do, what code you showed doesn't indicate.

            Rod
            Rod
            I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

            Comment


            • #7
              Ralph,
              You may want to consider wrapping your code posts with
              [ c o d e ]

              [ / c o d e ]
              (take out the spaces)

              that said you may want to check out my post from the source code forum back in 07' at Virtual Keyboard Routines

              Most of it is my instructions to recreating my keyboard, but the core part I believe will get you the key presses you are after. (keys may vary from keyboard to keyboard, but this was my as generic as I could get concept)
              Engineer's Motto: If it aint broke take it apart and fix it

              "If at 1st you don't succeed... call it version 1.0"

              "Half of Programming is coding"....."The other 90% is DEBUGGING"

              "Document my code????" .... "WHYYY??? do you think they call it CODE? "

              Comment


              • #8
                The following in your callback will capture a few of the keys without subclassing. Most others would need to be subclassed.
                %WM_HELP
                should normally capture function key 1
                under %WM_COMMAND
                the ddt CBCTL of
                CASE %IDCANCEL
                'should capture esc key
                CASE %IDOK
                'should capture Enter key
                Last edited by Fred Buffington; 28 Mar 2008, 07:45 PM.
                Client Writeup for the CPA

                buffs.proboards2.com

                Links Page

                Comment


                • #9
                  Originally posted by Ralph Brereton View Post
                  ...
                  Any ideas ?
                  Post a compilable example of the code that's failing (use Code Tags ).

                  Dialogs behave strangley when there are no controls at all. Try adding something.
                  Just adding a label to Rodney's example causes the %WM_KEYUP messages to disappear!
                  Rgds, Dave

                  Comment


                  • #10
                    >But how to detect the keys when the dialog has the focus ?

                    What are you trying to do?

                    To detect enter and escape, WM_COMMAND/IDOK and WM_COMMAND/IDCANCEL can be used.

                    To detect 'delete' NOT ON A CONTROL makes no sense. In a standard text box, Delete is handled for you and if you need to know the contents of the control have changed there is WM_COMMAND/EN_CHANGED or WM_COMMAND/EN_UPDATE.

                    For that matter, detecting any key other than one of the system control keys (eg Alt+F4) doesn't make any applications sense either.. at least not if your application is supposed to "look and feel" like a Windows' application.

                    FWIW, normally you wouldn't let a window (dialog) keep the keyboard focus... you'd respond to the WM_SETFOCUS notification by setting the focus to one of the controls.
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Rodney suggested commenting-out my FUNCTION = 0
                      I had put it in because SDK for WM_KEYUP said I should.
                      Nevertheless I took Rodney's suggestion.
                      It didn't work for me, though it did for him and we both use PBWin 8.04.
                      Then Dave said "dialogs behave strangely when there are no controls."
                      What's more, he said "adding a label caused Rodney's code to fail".
                      Which reminded me that my dialog once had a label.
                      I hadn't mentioned it because it is deleted before I wanted to trap those keys.
                      Quite possibly the label is at the root of the problem. I shall experiment.
                      Then Michael wanted to know, in the nicest possible way, what the heck was I up to ?
                      The answer really goes back to the VB6 app which I am slowly converting.
                      It has just one window upon which there appears a graphic.
                      This graphic displays a chart of stockmarket prices.
                      The user can navigate to a price (leftarrow, rightarrow, uparrow, downarrow).
                      The user can click on any price (keyup) to launch a popup window giving him options.
                      (Like draw a line from that price, or measure a percentage from that price, etc)
                      The user can abandon all those options with ESCAPE or DELETE.
                      Now somehow I've got it into my head that in PB graphics cannot get the focus.
                      Neither can graphics respond to keyboard messages.
                      So that's why I'm banging on about trapping those keys in the dialog.
                      It worries me that "dialogs behave strangely" when there are labels.
                      Perhaps dialogs will behave strangely when there are graphics.
                      Also, Dave wants me to post the code which is failing.
                      I haven't tried to post code yet.
                      In any case, I'd have to comment-out masses of instructions.
                      Otherwise you'd all get a mountain of code which you wouldn't want.
                      Thank you, friends, gradually we're getting to the bottom of this.
                      Someone, somewhere said, "If VB can do it, so can PB."
                      That's what I cling to !

                      Comment


                      • #12
                        Ah, the old 'Trial and error." routine.
                        I suspected there was considerably more than what you were posting so my comments were somewhat sparse, just too many possibilities. Good luck!
                        PB is a delightfully different way of thinking than VB, IMO.
                        Rod
                        Rod
                        I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                        Comment


                        • #13
                          Here follows my code. It compiles with PBWin 8.04.
                          Necessarily much abbreviated but an honest presentation.
                          Problems:
                          1) Approach the menu with the ALT key and the advertising disappears before clicking a menu item (as it should per SDK WM_MENUSELECT). Approach the menu with the mouse and you have to click a menu item to get the advertising to disappear. This doesn't matter much but it isn't elegant.
                          2) The code traps a mouseclick on the chart, or a mouse bdlclk, but that's all. My users don't like mice. The keyboard is much, much faster in experienced hands. The code does not trap leftarrow, rightarrow, uparrow, downarrow, return, escape, delete. This is so whether or not I set focus to the graphic chart.

                          Code:
                          #PBFORMS CREATED V1.51
                          '------------------------------------------------------------------------------
                          ' The first line in this file is a PB/Forms metastatement.
                          ' It should ALWAYS be the first line of the file. Other
                          ' PB/Forms metastatements are placed at the beginning and
                          ' end of "Named Blocks" of code that should be edited
                          ' with PBForms only. Do not manually edit or delete these
                          ' metastatements or PB/Forms will not be able to reread
                          ' the file correctly.  See the PB/Forms documentation for
                          ' more information.
                          ' Named blocks begin like this:    #PBFORMS BEGIN ...
                          ' Named blocks end like this:      #PBFORMS END ...
                          ' Other PB/Forms metastatements such as:
                          '     #PBFORMS DECLARATIONS
                          ' are used by PB/Forms to insert additional code.
                          ' Feel free to make changes anywhere else in the file.
                          '------------------------------------------------------------------------------
                          
                          #COMPILE EXE
                          #DIM ALL
                          
                          '------------------------------------------------------------------------------
                          '   ** Includes **
                          '------------------------------------------------------------------------------
                          #PBFORMS BEGIN INCLUDES
                          #IF NOT %DEF(%WINAPI)
                              #INCLUDE "WIN32API.INC"
                          #ENDIF
                          #INCLUDE "PBForms.INC"
                          #PBFORMS END INCLUDES
                          '------------------------------------------------------------------------------
                          
                          '------------------------------------------------------------------------------
                          '   ** Constants **
                          '------------------------------------------------------------------------------
                          #PBFORMS BEGIN CONSTANTS
                          %IDD_DIALOG1 =  101
                          %IDC_LABEL1  = 1001
                          %IDC_LABEL2  = 1002
                          %IDC_LABEL3  = 1003
                          #PBFORMS END CONSTANTS
                          '------------------------------------------------------------------------------
                          
                          %IDM_CHART   = 1020
                          %IDM_QUIT    = 1021
                          %IDC_GRAPHICCHART = 1022
                          
                          '------------------------------------------------------------------------------
                          '   ** Declarations **
                          '------------------------------------------------------------------------------
                          DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
                          DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                          #PBFORMS DECLARATIONS
                          '------------------------------------------------------------------------------
                          
                          '------------------------------------------------------------------------------
                          GLOBAL hdlg AS DWORD
                          
                          
                          '------------------------------------------------------------------------------
                          CALLBACK FUNCTION menuquitproc()
                              DIALOG END hDlg
                              FUNCTION = 1
                          END FUNCTION
                          
                          CALLBACK FUNCTION menuchartproc()
                              DIM x AS LONG
                              DIM y AS LONG
                              DIM z AS LONG
                              DIM dlgwidth AS LONG
                              DIM dlgheight AS LONG
                              'create graphic with white background
                              DIALOG GET CLIENT hdlg TO dlgwidth, dlgheight
                              CONTROL ADD GRAPHIC, hdlg, %IDC_GRAPHICCHART, "", 10, 10, dlgwidth-20, dlgheight-20, %SS_NOTIFY
                              GRAPHIC ATTACH hdlg, %IDC_GRAPHICCHART
                              GRAPHIC PAINT (0,0), %WHITE
                              GRAPHIC WIDTH 2
                              'draw an artificial chart
                              z=0
                              DO UNTIL x > dlgwidth-20
                                  x=5+(z*5)
                                  y=5+(z*5)
                                  GRAPHIC LINE (x,y) - (x,y+20)
                                  GRAPHIC LINE (x-2,y+5)-(x,y+5)
                                  GRAPHIC LINE (x+2,y+15)-(x,y+15)
                                  z=z+1
                              LOOP
                              'control set focus hdlg, %IDC_GRAPHICCHART
                              FUNCTION = 1
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          FUNCTION attachmenu() AS DWORD
                              LOCAL hMenu   AS DWORD
                              LOCAL hPopUp1 AS DWORD
                          
                              MENU NEW BAR TO hMenu
                              MENU ADD STRING, hmenu, "Chart", %IDM_CHART, %MF_ENABLED, CALL menuchartproc()
                              MENU ADD STRING, hmenu, "Quit", %IDM_QUIT, %MF_ENABLED, CALL menuquitproc()
                              MENU ATTACH hMenu, hDlg
                          
                              'return code to show function result
                              FUNCTION = hMenu
                          END FUNCTION
                          
                          
                          '------------------------------------------------------------------------------
                          '   ** Main Application Entry Point **
                          '------------------------------------------------------------------------------
                          FUNCTION PBMAIN()
                              ShowDIALOG1 %HWND_DESKTOP
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          
                          '------------------------------------------------------------------------------
                          '   ** CallBacks **
                          '------------------------------------------------------------------------------
                          CALLBACK FUNCTION ShowDIALOG1Proc()
                          
                              SELECT CASE AS LONG CBMSG
                                  CASE %WM_INITDIALOG
                                      ' Initialization handler
                          
                                  CASE %WM_NCACTIVATE
                                      STATIC hWndSaveFocus AS DWORD
                                      IF ISFALSE CBWPARAM THEN
                                          ' Save control focus
                                          hWndSaveFocus = GetFocus()
                                      ELSEIF hWndSaveFocus THEN
                                          ' Restore control focus
                                          SetFocus(hWndSaveFocus)
                                          hWndSaveFocus = 0
                                      END IF
                          
                                  CASE %WM_COMMAND
                                      ' Process control notifications
                                      SELECT CASE AS LONG CBCTL
                                          CASE %IDC_GRAPHICCHART
                                              SELECT CASE CBCTLMSG
                                                  CASE %STN_CLICKED
                                                      MSGBOX "Mouse click on chart"
                                                  CASE %STN_DBLCLK
                                                      MSGBOX "Mouse dblclk on chart"
                                              END SELECT
                          
                                      END SELECT
                          
                                  CASE %WM_KEYUP
                                      'these all work, but only once
                                      SELECT CASE CBCTL
                                          CASE %VK_RETURN
                                              MSGBOX "Return key pressed"
                                              'FUNCTION = 0
                                              'EXIT FUNCTION
                                          CASE %VK_ESCAPE
                                              MSGBOX "Escape key pressed"
                                              'FUNCTION = 0
                                              'EXIT FUNCTION
                                          CASE %VK_LEFT
                                              MSGBOX "Left arrow key pressed"
                                              'FUNCTION = 0
                                              'EXIT FUNCTION
                                          CASE %VK_RIGHT
                                              MSGBOX "Right arrow key pressed"
                                              'FUNCTION = 0
                                              'EXIT FUNCTION
                                          CASE %VK_UP
                                              MSGBOX "Up arrow key pressed"
                                              'FUNCTION = 0
                                              'EXIT FUNCTION
                                          CASE %VK_DOWN
                                              MSGBOX "Down arrow key pressed"
                                              'FUNCTION = 0
                                              'EXIT FUNCTION
                                      END SELECT
                          
                                  CASE %WM_MENUSELECT
                                          CONTROL KILL hdlg, %IDC_LABEL1
                                          CONTROL KILL hdlg, %IDC_LABEL2
                                          CONTROL KILL hdlg, %IDC_LABEL3
                                          FUNCTION = 0
                                          EXIT FUNCTION
                          
                              END SELECT
                          
                          
                          END FUNCTION
                          '------------------------------------------------------------------------------
                          
                          '------------------------------------------------------------------------------
                          '   ** Dialogs **
                          '------------------------------------------------------------------------------
                          FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                              LOCAL lRslt  AS LONG
                          
                          #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
                              'LOCAL hDlg   AS DWORD
                              LOCAL hFont1 AS DWORD
                              LOCAL hFont2 AS DWORD
                              LOCAL hFont3 AS DWORD
                          
                              DIALOG NEW hParent, "Dialog1", 70, 70, 227, 259, %WS_POPUP OR %WS_BORDER _
                                  OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX _
                                  OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK _
                                  OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR _
                                  %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
                              CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "Fast Charts", 40, 55, 150, 15, _
                                  %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR _
                                  %WS_EX_LTRREADING
                              CONTROL ADD LABEL, hDlg, %IDC_LABEL2, "by Ralph Brereton", 35, 75, 155, _
                                  15, %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR _
                                  %WS_EX_LTRREADING
                              CONTROL ADD LABEL, hDlg, %IDC_LABEL3, "Compiled without compromise", 40, _
                                  125, 150, 15, %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR _
                                  %WS_EX_LTRREADING
                          
                              hFont1 = PBFormsMakeFont("MS Sans Serif", 14, 400, %FALSE, %FALSE, _
                                  %FALSE, %ANSI_CHARSET)
                              hFont2 = PBFormsMakeFont("MS Sans Serif", 10, 400, %FALSE, %FALSE, _
                                  %FALSE, %ANSI_CHARSET)
                              hFont3 = PBFormsMakeFont("MS Sans Serif", 10, 700, %FALSE, %FALSE, _
                                  %FALSE, %ANSI_CHARSET)
                          
                              CONTROL SEND hDlg, %IDC_LABEL1, %WM_SETFONT, hFont1, 0
                              CONTROL SEND hDlg, %IDC_LABEL2, %WM_SETFONT, hFont2, 0
                              CONTROL SEND hDlg, %IDC_LABEL3, %WM_SETFONT, hFont3, 0
                          #PBFORMS END DIALOG
                              CALL attachmenu()
                              DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
                          
                          #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
                              DeleteObject hFont1
                              DeleteObject hFont2
                              DeleteObject hFont3
                          #PBFORMS END CLEANUP
                          
                              FUNCTION = lRslt
                          END FUNCTION
                          '------------------------------------------------------------------------------

                          Comment


                          • #14
                            Ralph,
                            Have a play with this example of using 'hot keys' created in an accelerator table.
                            Just add extra items to the table then add ID constants & Dim the AccelTbl() to suit.
                            Code:
                            #PBForms Created V1.51
                            #Compile Exe
                            #Dim All
                             
                            #PBForms Begin Includes
                            #If Not %Def(%WINAPI)
                              #Include "WIN32API.INC"
                            #EndIf
                            #If Not %Def(%COMMCTRL_INC)
                              #Include "COMMCTRL.INC"
                            #EndIf
                            #Include "PBForms.INC"
                            #PBForms End Includes
                             
                            #PBForms Begin Constants
                            %IDCLOSE        =    8
                            %IDD_DIALOG1    =  101
                            %IDR_MENU1      =  103
                            %GFX_GRAPHIC1   = 1001
                            %IDM_FILE       = 1002
                            %IDM_FILE_OPEN  = 1003
                            #PBForms End Constants
                             
                            %HK_Rtn         = 1010 '*
                            %HK_Esc         = 1011 '* - Identifiers for 'Hot' Keys
                            %HK_Del         = 1012 '*
                            '%HK_Key         = 101n
                             
                            Declare CallBack Function ShowDIALOG1Proc()
                            Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long
                            Declare Function AttachMENU1(ByVal hDlg As Dword) As Dword
                            #PBForms Declarations
                            '------------------/
                             
                            Function PBMain()
                              PBFormsInitComCtls (%ICC_WIN95_CLASSES Or %ICC_DATE_CLASSES Or %ICC_INTERNET_CLASSES)
                             
                              ShowDIALOG1 %HWND_DESKTOP
                            End Function 
                            '------------------/
                             
                            CallBack Function ShowDIALOG1Proc()
                             
                              Select Case As Long CbMsg
                                Case %WM_INITDIALOG
                                  Local Res As Long
                                  Dim AccelTbl(2) As ACCELAPI         ' dim array of 'ACCELAPI' type (n)
                                  'Accelerator table..   
                                    AccelTbl(0).FVIRT = %FVIRTKEY     ' flag indicates that key member specifies a virtual-key code
                                    AccelTbl(0).KEY   = %VK_RETURN    ' Return key code
                                    AccelTbl(0).CMD   = %HK_Rtn       ' accelerator ID for %WM_COMMAND / CBCTL {LOWRD(WPARAM)} msg
                             
                                    AccelTbl(1).FVIRT = %FVIRTKEY
                                    AccelTbl(1).KEY   = %VK_ESCAPE
                                    AccelTbl(1).CMD   = %HK_Esc
                             
                                    AccelTbl(2).FVIRT = %FVIRTKEY
                                    AccelTbl(2).KEY   = %VK_DELETE
                                    AccelTbl(2).CMD   = %HK_Del
                             
                            '        AccelTbl(n).FVIRT = %FVIRTKEY
                            '        AccelTbl(n).KEY   = %VK_KEY       ' Whatever
                            '        AccelTbl(n).CMD   = %HK_Key       ' ID for Whatever
                             
                                   Accel Attach CbHndl, AccelTbl() To Res    ' attach table to our dialog
                             
                                Case %WM_COMMAND
                                  Select Case As Long CbCtl
                                    Case %GFX_GRAPHIC1
                                      If CbCtlMsg = %STN_CLICKED Then
                                        MsgBox "Graphic clicked"
                                      End If 
                             
                                    Case %HK_Rtn
                                      MsgBox "Return pressed"
                             
                                    Case %HK_Esc
                                      MsgBox "Escape pressed"
                             
                                    Case %HK_Del
                                      MsgBox "Delete pressed"
                             
                                    Case %IDM_FILE_OPEN
                                      MsgBox "%IDM_FILE_OPEN=" + Format$(%IDM_FILE_OPEN), %MB_TASKMODAL
                             
                                    Case %IDCLOSE
                                      Dialog End CbHndl
                                  End Select
                             
                                Case %WM_DESTROY
                             
                              End Select
                            End Function 
                            '------------------/
                             
                            Function ShowDIALOG1(ByVal hParent As Dword) As Long
                              Local lRslt As Long
                             
                            #PBForms Begin Dialog %IDD_DIALOG1->%IDR_MENU1->
                             Local hDlg  As Dword
                             
                             Dialog New hParent, "Dialog1", , , 201, 157, %WS_POPUP OR %WS_CAPTION Or %WS_SYSMENU To hDlg
                              Control Add Graphic, hDlg, %GFX_GRAPHIC1, "", 5, 5, 190, 110, %WS_CHILD Or %WS_VISIBLE Or _
                              %WS_BORDER Or %SS_NOTIFY
                             AttachMENU1 hDlg
                            #PBForms End Dialog 
                             
                             Dialog Show Modal hDlg, Call ShowDIALOG1Proc To lRslt
                             
                            #PBForms Begin CleanUp %IDD_DIALOG1
                            #PBForms End CleanUp
                             
                              Function = lRslt
                            End Function 
                            '------------------/
                             
                            Function AttachMENU1(ByVal hDlg As Dword) As Dword
                            #PBForms Begin Menu %IDR_MENU1->%IDD_DIALOG1
                              Local hMenu   As Dword
                              Local hPopUp1 As Dword
                             
                              Menu New Bar To hMenu
                              Menu New PopUp To hPopUp1
                              Menu Add PopUp, hMenu, "&File", hPopUp1, %MF_ENABLED
                                Menu Add String, hPopUp1, "&Open", %IDM_FILE_OPEN, %MF_ENABLED
                                Menu Add String, hPopUp1, "E&xit", %IDCLOSE, %MF_ENABLED
                             
                              Menu Attach hMenu, hDlg
                            #PBForms End Menu
                              Function = hMenu
                            End Function 
                            '------------------/
                            For another way to access to keyboard entries see Pierre's example using SetWindowsHookEx():
                            http://www.powerbasic.com/support/pb...ad.php?t=22015
                            Rgds, Dave

                            Comment


                            • #15
                              Ralph,

                              The link in Dave's post is one of the one's that I alluded to in my first response, and of those, I think it is the most appropriate for what you're trying to accomplish.

                              Rod
                              Rod
                              I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                              Comment


                              • #16
                                Thank you both, Dave Biggs and Rodney Hicks. The hot key idea, so clearly explained by Dave, will be tried as soon as possible. My friends are becoming tired of me telling them this Forum is the best thing on the web. Even my wife is impressed - and that doesn't happen often.

                                Comment


                                • #17
                                  One hour or so after seeing Dave Biggs code for hot keys I have the whole thing working properly at last ! The following keys are now correctly trapped: Return, Escape, Delete, Left, Right, Up, Down. Easy when you know how. But what a petty minded thing is this programming in which we all indulge. I've been at it since 1958 and it was just the same then, despite endless claims by Microsoft, and others, "to make programming quicker and easier." It's a lovely day outside and here I am, fiddling away with hot keys. Get a life, man !

                                  Comment


                                  • #18
                                    It has just one window upon which there appears a graphic.
                                    This graphic displays a chart of stockmarket prices.
                                    The user can navigate to a price (leftarrow, rightarrow, uparrow, downarrow).
                                    The user can click on any price (keyup) to launch a popup window giving him options.
                                    (Like draw a line from that price, or measure a percentage from that price, etc)
                                    The user can abandon all those options with ESCAPE or DELETE.
                                    You might handle this better instead of trying to draw directly on the dialog by creating a "custom control" the same size as the client area of the dialog, and adding that with CONTROL ADD "MyWindowClassName" ......

                                    True, you will have to handle the graphing using the Windows' GDI calls instead of the more convenient "GRAPHIC dosomething" commands, but if you are already graphing with GRAPHIC LINE commands, LineTo() is really not too different from that at all.

                                    Using your own registered window class gives you a control with which you can do anything you want, not limited by some 'standard' control it might be a little easier to use.
                                    Michael Mattias
                                    Tal Systems (retired)
                                    Port Washington WI USA
                                    [email protected]
                                    http://www.talsystems.com

                                    Comment


                                    • #19
                                      Michael, my friend, that's a little too heavy for me. I've got the thing working with my graphic control and that's enough for now. I'm still a newbie to PB and not quite ready to go where you can go. No doubt the time will come when I'm into subclassing and custom controls, but right now they scare me. But, Michael, please don't be put off trying to help me. Your advice is listened to carefully. Gradually I hope to reach your standard. Thank you very much.

                                      Comment

                                      Working...
                                      X