Announcement

Collapse
No announcement yet.

KEYBOARD ENTRIES/PRINTING

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

    KEYBOARD ENTRIES/PRINTING

    I am new to DLL and would like some help on how to:
    1. use F1-F10, enter, etc. keys
    2. limit text entered in text box so not be continuous typing
    3. use enter key to make cursor go to next text box when you
    have two or more text boxes instead of having to use tab.
    4. printing text & graphics. you have one posted but would
    to see if there are other posting else where or some place else
    to see more examples.

    I have a programming windows book but seeing some example code
    in the above would help me get started.

    Thanks RA


    ------------------

    #2
    >1. use F1-F10, enter, etc. keys

    Look for RegisterHotKey/UnregisterHotKey/WM_HOTKEY in your Win32.hlp

    >2. limit text entered in text box so not be continuous typing

    SendMessage myedit&, %EM_EXLIMITTEXT, 0, maxlength&

    >3. use enter key to make cursor go to next text box when you
    >have two or more text boxes instead of having to use tab.

    Subclassing with WM_CHAR, I think.

    >4. printing text & graphics. you have one posted but would
    >to see if there are other posting else where or some place else
    >to see more examples.

    Try the searchengine of this Forum.

    >I have a programming windows book but seeing some example code
    >in the above would help me get started.

    Sorry, I know (or think I know ) how you problems could be solved,
    but I din't used anythink of it myself.

    ------------------
    E-Mail (home): mailto:[email protected][email protected]</A>
    E-Mail (work): mailto:[email protected]sven.blumen[email protected]</A>

    Comment


      #3

      Do a search of this forum, it should have all the example code you could wish for, and more, for all those points.

      Regards,

      ------------------
      Kev G Peel
      KGP Software, Bridgwater, UK.
      mailto:[email protected][email protected]</A> http://www.kgpsoftware.com
      kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

      Comment


        #4
        Robert:

        Here's one technique for processing keystrokes in your application... something for you to study.
        Code:
        #COMPILE EXE
        #REGISTER NONE
        #INCLUDE "WIN32API.INC"
        
        
        GLOBAL hDlg       AS LONG
        GLOBAL StopKBHook AS LONG
        
        
        CALLBACK FUNCTION DlgProc
           SELECT CASE CBMSG
           CASE %WM_DESTROY
              StopKBHook = %TRUE
              PostQuitMessage 0
              FUNCTION = 0
           END SELECT
        END FUNCTION
        
        
        FUNCTION PBMAIN
           DIALOG NEW 0, "Keyboard Trap", , , 200, 60, %WS_SYSMENU + %WS_MINIMIZEBOX  TO hDlg
           CONTROL ADD LABEL, hDlg, 100, "Keyboard trap is in place... start pressing keys.", 25, 15, 150, 10, %SS_SUNKEN + %SS_NOPREFIX
           DIALOG SHOW MODELESS hDlg CALL DlgProc
           CALL KBHook
        END FUNCTION
        
        
        SUB KBHook
           LOCAL InterceptKey AS LONG
           LOCAL KeyCode      AS LONG
           LOCAL KeyStroke    AS STRING
           LOCAL LastKey      AS STRING
           LOCAL Msg          AS TAGMSG
        
        
           WHILE GetMessage(Msg, %NULL, 0, 0) = %TRUE
              KeyStroke = ""
              SELECT CASE Msg.message
              CASE %WM_KEYDOWN, %WM_SYSKEYDOWN
                 IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                    KeyCode = Msg.wParam
                    IF KeyCode <> 16 THEN
                       KeyStroke = "SHIFT "
                       GOSUB WhichKey
                       IF LEN(LastKey) > 1 THEN
                          KeyStroke = KeyStroke + LastKey
                       ELSE
                          KeyStroke = LastKey
                       END IF
                    END IF
                 ELSEIF ISTRUE(LOWRD(GetKeyState(%VK_CONTROL)) AND &H8000) THEN
                    KeyCode = Msg.wParam
                    IF KeyCode <> 17 THEN
                       GOSUB WhichKey
                       IF LEN(LastKey) THEN
                          KeyStroke = "CTRL " + LastKey
                       END IF
                    END IF
                 ELSEIF ISTRUE(LOWRD(GetKeyState(%VK_MENU)) AND &H8000) THEN
                    KeyCode = Msg.wParam
                    GOSUB WhichKey
                    IF LEN(LastKey) THEN
                       KeyStroke = "ALT " + LastKey
                    END IF
                 ELSE
                    KeyCode = Msg.wParam
                    GOSUB WhichKey
                    IF LEN(LastKey) THEN
                       KeyStroke = LastKey
                    END IF
                 END IF
              END SELECT
        
        
              IF KeyStroke <> "" THEN
        
        
                 ' This is where you can select which keystrokes to intercept
                 ' and act on, and which keystrokes to pass through to Windows
                 '
                 CONTROL SET TEXT hDlg, 100, KeyStroke
                 '
                 ' Optionally pass keystroke through with following code
                 '
                 ' IF IsDialogMessage(hDlg, Msg) = %FALSE THEN
                 '    TranslateMessage Msg
                 '    DispatchMessage Msg
                 ' END IF
        
        
              ELSEIF IsDialogMessage(hDlg, Msg) = %FALSE THEN
                 TranslateMessage Msg
                 DispatchMessage Msg
              END IF
              IF StopKBHook THEN
                 EXIT SUB
              END IF
           LOOP
        
        
           WhichKey: ' GOSUB routine used above
        
        
           SELECT CASE KeyCode
           CASE %VK_LEFT
              LastKey = "LEFT ARROW"
           CASE %VK_RIGHT
              LastKey = "RIGHT ARROW"
           CASE %VK_DOWN
              LastKey = "DOWN ARROW"
           CASE %VK_UP
              LastKey = "UP ARROW"
           CASE %VK_HOME
              LastKey = "HOME"
           CASE %VK_END
              LastKey = "END"
           CASE %VK_INSERT
              LastKey = "INSERT"
           CASE %VK_DELETE
              LastKey = "DELETE"
           CASE %VK_PGUP
              LastKey = "PGUP"
           CASE %VK_PGDN
              LastKey = "PGDN"
           CASE %VK_TAB
              LastKey = "TAB"
           CASE %VK_RETURN
              LastKey = "RETURN"
           CASE %VK_BACK
              LastKey = "BACKSPACE"
           CASE %VK_ESCAPE
              LastKey = "ESCAPE"
           CASE %VK_F1
              LastKey = "F1"
           CASE %VK_F2
              LastKey = "F2"
           CASE %VK_F3
              LastKey = "F3"
           CASE %VK_F4
              LastKey = "F4"
           CASE %VK_F5
              LastKey = "F5"
           CASE %VK_F6
              LastKey = "F6"
           CASE %VK_F7
              LastKey = "F7"
           CASE %VK_F8
              LastKey = "F8"
           CASE %VK_F9
              LastKey = "F9"
           CASE %VK_F10
              LastKey = "F10"
           CASE %VK_F11
              LastKey = "F11"
           CASE %VK_F12
              LastKey = "F12"
           CASE %VK_PRINT
              LastKey = "PRINT SCREEN"
           CASE %VK_SCROLL
              LastKey = "SCROLL LOCK"
           CASE %VK_PAUSE
              LastKey = "PAUSE BREAK"
           CASE 63, 111
              ' ? or o   produced by numeric keypad
              LastKey = CHR$(47) ' /
           CASE 58, 106
              ' : or j   produced by numeric keypad
              LastKey = CHR$(42) ' *
           CASE 61, 109
              ' = or m   produced by numeric keypad
              LastKey = CHR$(45) ' -
           CASE 59, 107
              ' ; or k   produced by numeric keypad
              LastKey = CHR$(43) ' +
           CASE 110
              ' n        produced by numeric keypad
              LastKey = CHR$(46) ' .
           CASE 96 TO 105
              '          produced by numeric keypad
              IF GetKeyState(%VK_NUMLOCK) THEN
                 KeyCode = KeyCode - 48
                 ' 0 through 9
              END IF
              LastKey = CHR$(KeyCode)
           CASE 32
              LastKey = "SPACE"
           CASE 48 TO 57
              ' 0 through 9
              IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                 SELECT CASE KeyCode
                 CASE 48
                    LastKey = CHR$(41) ' )
                 CASE 49
                    LastKey = CHR$(33) ' !
                 CASE 50
                    LastKey = CHR$(64) ' @
                 CASE 51
                    LastKey = CHR$(35) ' #
                 CASE 52
                    LastKey = CHR$(36) ' $
                 CASE 53
                    LastKey = CHR$(37) ' %
                 CASE 54
                    LastKey = CHR$(94) ' ^
                 CASE 55
                    LastKey = CHR$(38) ' &
                 CASE 56
                    LastKey = CHR$(42) ' *
                 CASE 57
                    LastKey = CHR$(40) ' (
                 END SELECT
              ELSE
                 LastKey = CHR$(KeyCode)
              END IF
           CASE 65 TO 90
              ' A through Z
              IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) OR GetKeyState(%VK_CAPITAL) THEN
                 KeyStroke = ""
              ELSE
                 ' a through z
                 KeyCode = KeyCode + 32
              END IF
              LastKey = CHR$(KeyCode)
           CASE 186
              IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                 LastKey = CHR$(58) ' :
              ELSE
                 LastKey = CHR$(59) ' ;
              END IF
           CASE 187
              IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                 LastKey = CHR$(43) ' +
              ELSE
                 LastKey = CHR$(61) ' =
              END IF
           CASE 188
              IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                 LastKey = CHR$(60) ' <
              ELSE
                 LastKey = CHR$(44) ' .
              END IF
           CASE 189
              IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                 LastKey = CHR$(95) ' _
              ELSE
                 LastKey = CHR$(45) ' -
              END IF
           CASE 190
              IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                 LastKey = CHR$(62) ' >
              ELSE
                 LastKey = CHR$(46) ' ,
              END IF
           CASE 191
              IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                 LastKey = CHR$(63) ' ?
              ELSE
                 LastKey = CHR$(47) ' /
              END IF
           CASE 192
              IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                 LastKey = CHR$(126) ' ~
              ELSE
                 LastKey = CHR$(96)  ' `
              END IF
           CASE 219
              IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                 LastKey = CHR$(123) ' {
              ELSE
                 LastKey = CHR$(91)  ' [
              END IF
           CASE 220
              IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                 LastKey = CHR$(124) ' |
              ELSE
                 LastKey = CHR$(92)  ' \
              END IF
           CASE 221
              IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                 LastKey = CHR$(125) ' }
              ELSE
                 LastKey = CHR$(93)  ' ]
              END IF
           CASE 222
              IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                 LastKey = CHR$(34) ' "
              ELSE
                 LastKey = CHR$(39) ' '
              END IF
           CASE 20, 144, 12
              ' CapsLock, NumLock and the "5" on keypad w/numlock off
              ' Ignore these
              LastKey = ""
           CASE 91, 92, 93
              ' Windows and Windows Menu keys
              ' Ignore these
              LastKey = ""
           CASE ELSE
              ' Unknown
              LastKey = ""
           END SELECT
        
        
           RETURN
        END SUB
        Timm
        mailto:[email protected]
        Tsunami Record Manager

        Comment


          #5
          Originally posted by ROBERT ALVAREZ:
          I am new to DLL and would like some help on how to:
          1. use F1-F10, enter, etc. keys
          2. limit text entered in text box so not be continuous typing
          3. use enter key to make cursor go to next text box when you
          have two or more text boxes instead of having to use tab.
          4. printing text & graphics. you have one posted but would
          to see if there are other posting else where or some place else
          to see more examples.

          I have a programming windows book but seeing some example code
          in the above would help me get started.

          Thanks RA


          I will try a sample program to try out some of the samples code.
          If I am not successful I will post this sample with things that
          are in question <<< noted.
          A new question I have so far is : where is the search engine for
          this forum? I looked around but could not find one.

          Thanks All for your help. RA.



          ------------------
          Robert Alvarez

          Comment


            #6
            http://www.powerbasic.com/support/fo...i?action=intro

            Look at the upper right corner of this page here

            ------------------
            E-Mail (home): mailto:[email protected][email protected]</A>
            E-Mail (work): mailto:[email protected]sven.blumen[email protected]</A>

            Comment


              #7
              '==============================================================================
              ' keysamp4.BAS 3.1.01 8.6.01
              ' Simple Dialog Example for PB/DLL 6.0
              ' Simple example of an application that has a dialog
              '
              '==============================================================================
              '8.6.01
              '>>>>Heres my small example program to try to plugin code for my questions.<<<<<<<<
              '
              'For question #1, trying to use F9 & F10 only works when I first type E or use mouse.
              'This will not work until I first go to edit screen then F9 F10 works. Tried putting
              'KBHook in several places but still same problem.
              '
              'For my question #2, trying to limit keyboard input. This I could not figure out
              'where or how to use the code.
              'see below 2 places FOR more questions plugging IN code IN RIGHT place.
              '
              'For my question #3, use enter to goto next text block. Cannot figure out this one too.
              '
              'For my question #4, after looking in the search engine I will post another posting for
              'help on printing. There is a lot of reading to do.
              '
              'Which win98 programing book is best to learn about api's and has the most useful information
              'for use with dll & win exe programing. The one I good is not too good.


              #COMPILE EXE
              #INCLUDE "WIN32API.INC"

              %IDNXT = 3
              %IDDATE = 10
              %IDOK = 1
              %IDCANCEL = 2
              %IDTEXT = 100
              %BS_DEFAULT = 1

              %IDLABEL1=21: %IDLABEL2=22: %IDLABEL3=23
              %IDTXT1=31: %IDTXT2=32: %IDTXT3=33
              %IDTXTBX1=41: %IDTXTBX2=42: %IDTXTBX3=43

              '------------------------------------------------------------------------------
              ' Global variable to recieve the user name

              GLOBAL UserName AS STRING, hDlg AS LONG, SCRN AS LONG, TXTL AS LONG
              GLOBAL T1 AS STRING, T2 AS STRING, T3 AS STRING
              GLOBAL StopKBHook AS LONG
              DECLARE CALLBACK FUNCTION OkBUTTON()
              DECLARE CALLBACK FUNCTION CancelButton()

              'Found this line in winapi.inc but do not know how to use it. I have never done any api calls. ???? Question 2 ????
              'DECLARE FUNCTION SendMessage LIB "USER" (BYVAL hWnd AS WORD, BYVAL wMsg AS WORD, BYVAL wParam AS WORD, BYVAL lParam AS DWORD) AS DWORD

              '------------------------------------------------------------------------------

              CALLBACK FUNCTION DlgProc
              SELECT CASE CBMSG
              CASE %WM_DESTROY
              StopKBHook = %TRUE
              PostQuitMessage 0
              FUNCTION = 0
              END SELECT
              'CALL KBHook '<<<<<<< ?????
              'DOES NOT WORK IF PUT HERE ???
              'GET ERROR 496, DOES NOT SHOW IN TASK DIALOG BOX
              'HAVE TO REBOOT COMPUTER TO REMOVE PROG FROM MEMORY
              'BY TURNING OFF COMPUTER.
              END FUNCTION

              SUB KBHook
              LOCAL InterceptKey AS LONG
              LOCAL KeyCode AS LONG
              LOCAL KeyStroke AS STRING
              LOCAL LastKey AS STRING
              LOCAL Msg AS TAGMSG

              WHILE GetMessage(Msg, %NULL, 0, 0) = %TRUE
              KeyStroke = ""
              SELECT CASE Msg.message
              CASE %WM_KEYDOWN, %WM_SYSKEYDOWN
              IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
              KeyCode = Msg.wParam
              IF KeyCode <> 16 THEN
              KeyStroke = "SHIFT "
              GOSUB WhichKey
              IF LEN(LastKey) > 1 THEN
              KeyStroke = KeyStroke + LastKey
              ELSE
              KeyStroke = LastKey
              END IF
              END IF
              ELSEIF ISTRUE(LOWRD(GetKeyState(%VK_CONTROL)) AND &H8000) THEN
              KeyCode = Msg.wParam
              IF KeyCode <> 17 THEN
              GOSUB WhichKey
              IF LEN(LastKey) THEN
              KeyStroke = "CTRL " + LastKey
              END IF
              END IF
              ELSEIF ISTRUE(LOWRD(GetKeyState(%VK_MENU)) AND &H8000) THEN
              KeyCode = Msg.wParam
              GOSUB WhichKey
              IF LEN(LastKey) THEN
              KeyStroke = "ALT " + LastKey
              END IF
              ELSE
              KeyCode = Msg.wParam
              GOSUB WhichKey
              IF LEN(LastKey) THEN
              KeyStroke = LastKey
              END IF
              END IF
              END SELECT

              IF KeyStroke <> "" THEN

              ' This is where you can select which keystrokes to intercept
              ' and act on, and which keystrokes to pass through to Windows
              '
              CONTROL SET TEXT hDlg, 100, KeyStroke
              '
              ' Optionally pass keystroke through with following code
              '
              ' IF IsDialogMessage(hDlg, Msg) = %FALSE THEN
              ' TranslateMessage Msg
              ' DispatchMessage Msg
              ' END IF

              ELSEIF IsDialogMessage(hDlg, Msg) = %FALSE THEN
              TranslateMessage Msg
              DispatchMessage Msg
              END IF
              IF StopKBHook THEN
              EXIT SUB
              END IF
              LOOP

              WhichKey: ' GOSUB routine used above

              SELECT CASE KeyCode
              CASE %VK_F9 AND SCRN=1
              'MSGBOX "F9"
              CALL F9OkButton
              CASE %VK_F10 AND SCRN=2
              'MSGBOX "F10"
              CALL F10DONE1
              CASE %VK_RETURN AND TXTL=1 'DOES NOT WORK ??????? QUESTION
              CONTROL SET FOCUS hDlg&,%IDTXTBX2
              CASE %VK_RETURN AND TXTL=2
              CONTROL SET FOCUS hDlg&,%IDTXTBX3
              CASE %VK_RETURN AND TXTL=3
              CONTROL SET FOCUS hDlg&,%IDTXTBX1
              CASE ELSE
              ' Unknown
              LastKey = ""
              END SELECT

              RETURN
              END SUB

              CALLBACK FUNCTION TXTBX1()
              ' SendMessage hDlg&, &HC5, 0, 5 ' ???? %EM_EXLIMITTEXT Question 2 ????
              TXTL=2
              CONTROL GET TEXT hDlg&, %IDTXTBX1 TO T1
              END FUNCTION

              CALLBACK FUNCTION TXTBX2()
              TXTL=2
              CONTROL GET TEXT hDlg&, %IDTXTBX2 TO T2
              END FUNCTION

              CALLBACK FUNCTION TXTBX3()
              TXTL=2
              CONTROL GET TEXT hDlg&, %IDTXTBX3 TO T3
              END FUNCTION

              CALLBACK FUNCTION DONE1()
              CONTROL KILL hDlg, %IDTXTBX1
              CONTROL KILL hDlg, %IDTXTBX2
              CONTROL KILL hDlg, %IDTXTBX3
              CONTROL KILL hDlg, %IDOK
              CONTROL ADD LABEL, hDlg, %IDTXT1, T1, 192, 100, 50, 12, 0
              CONTROL ADD LABEL, hDlg, %IDTXT2, T2, 192, 115, 50, 12, 0
              CONTROL ADD LABEL, hDlg, %IDTXT3, T3, 192, 130, 50, 12, 0
              CONTROL ADD BUTTON, hDlg, %IDOK, "F9 &Edit", 130, 152, 40, 14, CALL OkButton
              CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Cancel", 200, 152, 40, 14, 0 CALL CancelButton
              END FUNCTION

              SUB F10DONE1()
              SCRN=1
              CONTROL KILL hDlg, %IDTXTBX1
              CONTROL KILL hDlg, %IDTXTBX2
              CONTROL KILL hDlg, %IDTXTBX3
              CONTROL KILL hDlg, %IDOK
              CONTROL ADD LABEL, hDlg, %IDTXT1, T1, 192, 100, 50, 12, 0
              CONTROL ADD LABEL, hDlg, %IDTXT2, T2, 192, 115, 50, 12, 0
              CONTROL ADD LABEL, hDlg, %IDTXT3, T3, 192, 130, 50, 12, 0
              CONTROL ADD BUTTON, hDlg, %IDOK, "F9 &Edit", 130, 152, 40, 14, CALL OkButton
              CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Cancel", 200, 152, 40, 14, 0 CALL CancelButton
              END SUB


              CALLBACK FUNCTION OkButton()
              SCRN=2
              CONTROL KILL hDlg, %IDTXT1
              CONTROL KILL hDlg, %IDTXT2
              CONTROL KILL hDlg, %IDTXT3
              CONTROL KILL hDlg, %IDOK
              CONTROL KILL hDlg, %IDCANCEL
              ' CALL KBHook 'DOES NOT WORK PROPERLY IF PUT HERE
              CONTROL ADD TEXTBOX, hDlg, %IDTXTBX1, T1, 192, 100, 50, 12, CALL TXTBX1
              CONTROL ADD TEXTBOX, hDlg, %IDTXTBX2, T2, 192, 115, 50, 12, CALL TXTBX2
              CONTROL ADD TEXTBOX, hDlg, %IDTXTBX3, T3, 192, 130, 50, 12, CALL TXTBX3
              CONTROL ADD BUTTON, hDlg, %IDOK, "F10 &DONE", 130, 152, 40, 14, CALL DONE1
              CONTROL SET FOCUS hDlg&,%IDTXTBX1
              ' CALL DlgProc 'ERROR 546 IF PUT HERE
              CALL KBHook
              END FUNCTION

              SUB F9OkButton()
              SCRN=2
              CONTROL KILL hDlg, %IDTXT1
              CONTROL KILL hDlg, %IDTXT2
              CONTROL KILL hDlg, %IDTXT3
              CONTROL KILL hDlg, %IDOK
              CONTROL KILL hDlg, %IDCANCEL
              CONTROL ADD TEXTBOX, hDlg, %IDTXTBX1, T1, 192, 100, 50, 12, CALL TXTBX1
              CONTROL ADD TEXTBOX, hDlg, %IDTXTBX2, T2, 192, 115, 50, 12, CALL TXTBX2
              CONTROL ADD TEXTBOX, hDlg, %IDTXTBX3, T3, 192, 130, 50, 12, CALL TXTBX3
              CONTROL ADD BUTTON, hDlg, %IDOK, "F10 &DONE", 130, 152, 40, 14, CALL DONE1
              CONTROL SET FOCUS hDlg&,%IDTXTBX1
              END SUB

              CALLBACK FUNCTION CancelButton()
              DIALOG END CBHNDL, 0
              END FUNCTION

              '------------------------------------------------------------------------------

              FUNCTION PBMAIN () AS LONG

              $REGISTER NONE

              LOCAL result AS LONG

              T1$="A2345" :T2$="B2345678": T3$="C2345678": SCRN=1: TXTL=1

              ' ** Create a new dialog template 160, 50, 0, 0
              DIALOG NEW 0, "DATA BASE ONE", ,, 400, 350, 0, 0 TO hDlg

              ' ** Add controls to it
              CONTROL ADD LABEL, hDlg, %IDLABEL1, " 5 CHARACTERS>", 125, 100, 65, 12, 0
              CONTROL ADD LABEL, hDlg, %IDLABEL2, " 8 CHARACTERS>", 125, 115, 65, 12, 0
              CONTROL ADD LABEL, hDlg, %IDLABEL3, "10 CHARACTERS>", 125, 130, 65, 12, 0
              CONTROL ADD LABEL, hDlg, %IDTXT1, T1, 192, 100, 50, 12, 0
              CONTROL ADD LABEL, hDlg, %IDTXT2, T2, 192, 115, 50, 12, 0
              CONTROL ADD LABEL, hDlg, %IDTXT3, T3, 192, 130, 50, 12, 0
              CONTROL ADD BUTTON, hDlg, %IDOK, "F9 &Edit", 130, 152, 40, 14, CALL OkButton
              CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Cancel", 200, 152, 40, 14, 0 CALL CancelButton

              ' ** Display the dialog
              DIALOG SHOW MODAL hDlg CALL DlgProc

              ' ** Check the result
              IF result THEN
              MSGBOX "Hello"
              END IF
              '
              'DIALOG SHOW MODAL hDlg TO result <<<<<<<<<<<<<<<<<<<<<

              END FUNCTION


              ------------------
              Robert Alvarez

              Comment


                #8
                Robert:
                Code:
                #COMPILE EXE
                #INCLUDE "WIN32API.INC"
                
                
                %BS_DEFAULT = 1
                %IDNXT      = 3
                %IDDATE     = 10
                %IDOK       = 1
                %IDCANCEL   = 2
                %IDTEXT     = 100
                %IDLABEL1   = 21
                %IDLABEL2   = 22
                %IDLABEL3   = 23
                %IDTXT1     = 31
                %IDTXT2     = 32
                %IDTXT3     = 33
                %IDTXTBX1   = 41
                %IDTXTBX2   = 42
                %IDTXTBX3   = 43
                
                
                GLOBAL hDlg       AS LONG
                GLOBAL SCRN       AS LONG
                GLOBAL StopKBHook AS LONG
                GLOBAL T1         AS STRING
                GLOBAL T2         AS STRING
                GLOBAL T3         AS STRING
                GLOBAL TXTL       AS LONG
                GLOBAL UserName   AS STRING
                
                
                DECLARE CALLBACK FUNCTION OkBUTTON()
                DECLARE CALLBACK FUNCTION CancelButton()
                
                
                CALLBACK FUNCTION DlgProc
                   SELECT CASE CBMSG
                   CASE %WM_DESTROY
                      StopKBHook = %TRUE
                      PostQuitMessage 0
                      FUNCTION = 0
                   END SELECT
                END FUNCTION
                
                
                SUB KBHook
                   LOCAL InterceptKey AS LONG
                   LOCAL KeyCode AS LONG
                   LOCAL KeyStroke AS STRING
                   LOCAL LastKey AS STRING
                   LOCAL Msg AS TAGMSG
                
                
                   WHILE GetMessage(Msg, %NULL, 0, 0) = %TRUE
                      KeyStroke = ""
                      SELECT CASE Msg.message
                      CASE %WM_KEYDOWN, %WM_SYSKEYDOWN
                         IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                            KeyCode = Msg.wParam
                            IF KeyCode <> 16 THEN
                               KeyStroke = "SHIFT "
                               GOSUB WhichKey
                               IF LEN(LastKey) > 1 THEN
                                  KeyStroke = KeyStroke + LastKey
                               ELSE
                                  KeyStroke = LastKey
                               END IF
                            END IF
                
                
                         ELSEIF ISTRUE(LOWRD(GetKeyState(%VK_CONTROL)) AND &H8000) THEN
                            KeyCode = Msg.wParam
                            IF KeyCode <> 17 THEN
                               GOSUB WhichKey
                               IF LEN(LastKey) THEN
                                  KeyStroke = "CTRL " + LastKey
                               END IF
                            END IF
                
                
                         ELSEIF ISTRUE(LOWRD(GetKeyState(%VK_MENU)) AND &H8000) THEN
                            KeyCode = Msg.wParam
                            GOSUB WhichKey
                            IF LEN(LastKey) THEN
                               KeyStroke = "ALT " + LastKey
                            END IF
                
                
                         ELSE
                            KeyCode = Msg.wParam
                            GOSUB WhichKey
                            IF LEN(LastKey) THEN
                               KeyStroke = LastKey
                            END IF
                
                
                         END IF
                      END SELECT
                
                
                      IF KeyStroke <> "" THEN
                         '
                         ' This is where you can select which keystrokes to intercept
                         ' and act on, and which keystrokes to pass through to Windows
                         '
                         SELECT CASE KeyStroke
                         CASE "RETURN"
                            SELECT CASE TXTL
                            CASE 1
                               CONTROL SET FOCUS hDlg, %IDTXTBX2
                            CASE 2
                               CONTROL SET FOCUS hDlg, %IDTXTBX3
                            CASE 3
                               CONTROL SET FOCUS hDlg, %IDTXTBX1
                            END SELECT
                
                
                         CASE "F9"
                            IF SCRN = 1 THEN
                               CALL F9OkButton
                            END IF
                
                
                         CASE "F10"
                            IF SCRN = 2 THEN
                               CALL F10DONE1
                            END IF
                
                
                         END SELECT
                         '
                         ' Optionally pass keystroke through with following code
                         '
                         ' IF IsDialogMessage(hDlg, Msg) = %FALSE THEN
                         '    TranslateMessage Msg
                         '    DispatchMessage Msg
                         ' END IF
                         '
                      ELSEIF IsDialogMessage(hDlg, Msg) = %FALSE THEN
                         TranslateMessage Msg
                         DispatchMessage Msg
                
                
                      END IF
                
                
                      IF StopKBHook THEN
                         EXIT SUB
                      END IF
                   LOOP
                
                
                   WhichKey:
                
                
                   SELECT CASE KeyCode
                   CASE %VK_F9
                      LastKey = "F9"
                
                
                   CASE %VK_F10
                      LastKey = "F10"
                
                
                   CASE %VK_RETURN
                      LastKey = "RETURN"
                
                
                   CASE ELSE
                      ' Don't trap anything else
                      LastKey = ""
                
                
                   END SELECT
                   RETURN
                END SUB
                
                
                CALLBACK FUNCTION TXTBX1()
                   TXTL=1
                   CONTROL GET TEXT hDlg, %IDTXTBX1 TO T1
                END FUNCTION
                
                
                CALLBACK FUNCTION TXTBX2()
                   TXTL=2
                   CONTROL GET TEXT hDlg, %IDTXTBX2 TO T2
                END FUNCTION
                
                
                CALLBACK FUNCTION TXTBX3()
                   TXTL=3
                   CONTROL GET TEXT hDlg, %IDTXTBX3 TO T3
                END FUNCTION
                
                
                CALLBACK FUNCTION DONE1()
                   CONTROL KILL hDlg, %IDTXTBX1
                   CONTROL KILL hDlg, %IDTXTBX2
                   CONTROL KILL hDlg, %IDTXTBX3
                   CONTROL KILL hDlg, %IDOK
                   CONTROL ADD LABEL, hDlg, %IDTXT1, T1, 192, 100, 50, 12, 0
                   CONTROL ADD LABEL, hDlg, %IDTXT2, T2, 192, 115, 50, 12, 0
                   CONTROL ADD LABEL, hDlg, %IDTXT3, T3, 192, 130, 50, 12, 0
                   CONTROL ADD BUTTON, hDlg, %IDOK, "F9 &Edit", 130, 152, 40, 14, CALL OkButton
                   CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Cancel", 200, 152, 40, 14, 0 CALL CancelButton
                END FUNCTION
                
                
                SUB F10DONE1()
                   SCRN=1
                   CONTROL KILL hDlg, %IDTXTBX1
                   CONTROL KILL hDlg, %IDTXTBX2
                   CONTROL KILL hDlg, %IDTXTBX3
                   CONTROL KILL hDlg, %IDOK
                   CONTROL ADD LABEL, hDlg, %IDTXT1, T1, 192, 100, 50, 12, 0
                   CONTROL ADD LABEL, hDlg, %IDTXT2, T2, 192, 115, 50, 12, 0
                   CONTROL ADD LABEL, hDlg, %IDTXT3, T3, 192, 130, 50, 12, 0
                   CONTROL ADD BUTTON, hDlg, %IDOK, "F9 &Edit", 130, 152, 40, 14, CALL OkButton
                   CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Cancel", 200, 152, 40, 14, 0 CALL CancelButton
                END SUB
                
                
                CALLBACK FUNCTION OkButton()
                   SCRN=2
                   CONTROL KILL hDlg, %IDTXT1
                   CONTROL KILL hDlg, %IDTXT2
                   CONTROL KILL hDlg, %IDTXT3
                   CONTROL KILL hDlg, %IDOK
                   CONTROL KILL hDlg, %IDCANCEL
                   CONTROL ADD TEXTBOX, hDlg, %IDTXTBX1, T1, 192, 100, 50, 12, CALL TXTBX1
                   CONTROL ADD TEXTBOX, hDlg, %IDTXTBX2, T2, 192, 115, 50, 12, CALL TXTBX2
                   CONTROL ADD TEXTBOX, hDlg, %IDTXTBX3, T3, 192, 130, 50, 12, CALL TXTBX3
                   CONTROL ADD BUTTON, hDlg, %IDOK, "F10 &DONE", 130, 152, 40, 14, CALL DONE1
                   CONTROL SET FOCUS hDlg&,%IDTXTBX1
                END FUNCTION
                
                
                SUB F9OkButton()
                   SCRN=2
                   CONTROL KILL hDlg, %IDTXT1
                   CONTROL KILL hDlg, %IDTXT2
                   CONTROL KILL hDlg, %IDTXT3
                   CONTROL KILL hDlg, %IDOK
                   CONTROL KILL hDlg, %IDCANCEL
                   CONTROL ADD TEXTBOX, hDlg, %IDTXTBX1, T1, 192, 100, 50, 12, CALL TXTBX1
                   CONTROL ADD TEXTBOX, hDlg, %IDTXTBX2, T2, 192, 115, 50, 12, CALL TXTBX2
                   CONTROL ADD TEXTBOX, hDlg, %IDTXTBX3, T3, 192, 130, 50, 12, CALL TXTBX3
                   CONTROL ADD BUTTON, hDlg, %IDOK, "F10 &DONE", 130, 152, 40, 14, CALL DONE1
                   CONTROL SET FOCUS hDlg&,%IDTXTBX1
                END SUB
                
                
                CALLBACK FUNCTION CancelButton()
                   DIALOG END CBHNDL, 0
                END FUNCTION
                
                
                FUNCTION PBMAIN () AS LONG
                   $REGISTER NONE
                   LOCAL result AS LONG
                
                
                   T1$ = "A2345"
                   T2$ = "B2345678"
                   T3$ = "C2345678"
                   SCRN = 1
                   TXTL = 1
                   ' ** Create a new dialog template 160, 50, 0, 0
                   DIALOG NEW 0, "DATA BASE ONE", ,, 400, 350, 0, 0 TO hDlg
                   ' ** Add controls to it
                   CONTROL ADD LABEL, hDlg, %IDLABEL1, " 5 CHARACTERS>", 125, 100, 65, 12, 0
                   CONTROL ADD LABEL, hDlg, %IDLABEL2, " 8 CHARACTERS>", 125, 115, 65, 12, 0
                   CONTROL ADD LABEL, hDlg, %IDLABEL3, "10 CHARACTERS>", 125, 130, 65, 12, 0
                   CONTROL ADD LABEL, hDlg, %IDTXT1, T1, 192, 100, 50, 12, 0
                   CONTROL ADD LABEL, hDlg, %IDTXT2, T2, 192, 115, 50, 12, 0
                   CONTROL ADD LABEL, hDlg, %IDTXT3, T3, 192, 130, 50, 12, 0
                   CONTROL ADD BUTTON, hDlg, %IDOK, "F9 &Edit", 130, 152, 40, 14, CALL OkButton
                   CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Cancel", 200, 152, 40, 14, 0 CALL CancelButton
                   ' ** Display the dialog
                   DIALOG SHOW MODELESS hDlg CALL DlgProc
                   CALL KBHook
                END FUNCTION
                Timm
                mailto:[email protected]
                Tsunami Record Manager

                Comment


                  #9
                  Thank you Timm for your help in my code listing. I still have the
                  question on how to limit text keying in a text box, I will wait
                  a few days to see if anyone can help with this topic. Mr. Sven
                  made a lead to follow but I could not get anywhere with that.
                  After a while I will re-post my last question and see if anyone
                  out there can help.

                  Thank to fellow member for your repies.
                  RA

                  ------------------
                  Robert Alvarez

                  Comment


                    #10
                    Robert:
                    Code:
                    #COMPILE EXE
                    #INCLUDE "WIN32API.INC"
                    
                    
                    FUNCTION PBMAIN
                       LOCAL hDlg AS LONG
                       DIALOG NEW 0, "Limit To 12 Characters",,, 120, 50, %WS_SYSMENU + %WS_CAPTION TO hDlg
                       CONTROL ADD TEXTBOX, hDlg, 100, "", 20, 15, 80, 12
                       CONTROL SEND hDlg, 100, %EM_LIMITTEXT, 12, 0
                       DIALOG SHOW MODAL hDlg
                    END FUNCTION
                    Timm
                    mailto:[email protected]
                    Tsunami Record Manager

                    Comment


                      #11
                      Thanks Timm. That made my simple program work, but there are some
                      bugs in it, which I am having trying to find.
                      1. try using the insert key to over-write you text in the text
                      box or insert key to insert a character in the middle of the
                      text line when it is full. This may not be a bug but only the
                      way the text box works.
                      2. When in the edit screen tab down to the F10 button and hit enter
                      when it is highlighted. It does not work in screen one either, for
                      any button.
                      3. Also when tabing around the edit screen and editing, sometimes
                      the F10, and F9 keys do not work.



                      ------------------
                      Robert Alvarez

                      Comment


                        #12
                        Robert:

                        1. The behavior you are seeing is the nature of a textbox.
                        2. You need to pass the RETURN key through when not in a textbox (see example below).
                        3. I can't reproduce the situation you described.
                        Code:
                        #COMPILE EXE
                        #INCLUDE "WIN32API.INC"
                         
                        %BS_DEFAULT = 1
                        %IDNXT      = 3
                        %IDDATE     = 10
                        %IDOK       = 1
                        %IDCANCEL   = 2
                        %IDTEXT     = 100
                        %IDLABEL1   = 21
                        %IDLABEL2   = 22
                        %IDLABEL3   = 23
                        %IDTXT1     = 31
                        %IDTXT2     = 32
                        %IDTXT3     = 33
                        %IDTXTBX1   = 41
                        %IDTXTBX2   = 42
                        %IDTXTBX3   = 43
                         
                        GLOBAL hDlg       AS LONG
                        GLOBAL SCRN       AS LONG
                        GLOBAL StopKBHook AS LONG
                        GLOBAL T1         AS STRING
                        GLOBAL T2         AS STRING
                        GLOBAL T3         AS STRING
                        GLOBAL TXTL       AS LONG
                        GLOBAL UserName   AS STRING
                         
                        DECLARE CALLBACK FUNCTION OkBUTTON()
                        DECLARE CALLBACK FUNCTION CancelButton()
                         
                        CALLBACK FUNCTION DlgProc
                           SELECT CASE CBMSG
                           CASE %WM_INITDIALOG
                              CONTROL SET FOCUS CBHNDL, %IDOK
                           CASE %WM_DESTROY
                              StopKBHook = %TRUE
                              PostQuitMessage 0
                              FUNCTION = 0
                           END SELECT
                        END FUNCTION
                         
                        SUB KBHook
                           LOCAL InterceptKey AS LONG
                           LOCAL KeyCode AS LONG
                           LOCAL KeyStroke AS STRING
                           LOCAL LastKey AS STRING
                           LOCAL Msg AS TAGMSG
                         
                           WHILE GetMessage(Msg, %NULL, 0, 0) = %TRUE
                              KeyStroke = ""
                              SELECT CASE Msg.message
                              CASE %WM_KEYDOWN, %WM_SYSKEYDOWN
                                 IF ISTRUE(LOWRD(GetKeyState(%VK_SHIFT)) AND &H8000) THEN
                                    KeyCode = Msg.wParam
                                    IF KeyCode <> 16 THEN
                                       KeyStroke = "SHIFT "
                                       GOSUB WhichKey
                                       IF LEN(LastKey) > 1 THEN
                                          KeyStroke = KeyStroke + LastKey
                                       ELSE
                                          KeyStroke = LastKey
                                       END IF
                                    END IF
                         
                                 ELSEIF ISTRUE(LOWRD(GetKeyState(%VK_CONTROL)) AND &H8000) THEN
                                    KeyCode = Msg.wParam
                                    IF KeyCode <> 17 THEN
                                       GOSUB WhichKey
                                       IF LEN(LastKey) THEN
                                          KeyStroke = "CTRL " + LastKey
                                       END IF
                                    END IF
                         
                                 ELSEIF ISTRUE(LOWRD(GetKeyState(%VK_MENU)) AND &H8000) THEN
                                    KeyCode = Msg.wParam
                                    GOSUB WhichKey
                                    IF LEN(LastKey) THEN
                                       KeyStroke = "ALT " + LastKey
                                    END IF
                         
                                 ELSE
                                    KeyCode = Msg.wParam
                                    GOSUB WhichKey
                                    IF LEN(LastKey) THEN
                                       KeyStroke = LastKey
                                    END IF
                         
                                 END IF
                              END SELECT
                         
                              IF KeyStroke <> "" THEN
                                 '
                                 ' This is where you can select which keystrokes to intercept
                                 ' and act on, and which keystrokes to pass through to Windows
                                 '
                                 SELECT CASE KeyStroke
                                 CASE "RETURN"
                                    SELECT CASE TXTL
                                    CASE 1
                                       CONTROL SET FOCUS hDlg, %IDTXTBX2
                                    CASE 2
                                       CONTROL SET FOCUS hDlg, %IDTXTBX3
                                    CASE 3
                                       CONTROL SET FOCUS hDlg, %IDTXTBX1
                                    CASE ELSE
                         
                                       IF SCRN = 2 THEN  ' Added later
                                          CALL F10DONE1  '
                                       END IF            '
                         
                                       IF IsDialogMessage(hDlg, Msg) = %FALSE THEN
                                          TranslateMessage Msg
                                          DispatchMessage Msg
                                       END IF
                                    END SELECT
                         
                                 CASE "F9"
                                    IF SCRN = 1 THEN
                                       CALL F9OkButton
                                    END IF
                         
                                 CASE "F10"
                                    IF SCRN = 2 THEN
                                       CALL F10DONE1
                                    END IF
                         
                                 END SELECT
                                 '
                                 ' Optionally pass keystroke through with following code
                                 '
                                 ' IF IsDialogMessage(hDlg, Msg) = %FALSE THEN
                                 '    TranslateMessage Msg
                                 '    DispatchMessage Msg
                                 ' END IF
                                 '
                              ELSEIF IsDialogMessage(hDlg, Msg) = %FALSE THEN
                                 TranslateMessage Msg
                                 DispatchMessage Msg
                         
                              END IF
                         
                              IF StopKBHook THEN
                                 EXIT SUB
                              END IF
                           LOOP
                         
                           WhichKey:
                         
                           SELECT CASE KeyCode
                           CASE %VK_F9
                              LastKey = "F9"
                         
                           CASE %VK_F10
                              LastKey = "F10"
                         
                           CASE %VK_RETURN
                              LastKey = "RETURN"
                         
                           CASE ELSE
                              ' Don't trap anything else
                              LastKey = ""
                         
                           END SELECT
                           RETURN
                        END SUB
                         
                        CALLBACK FUNCTION TXTBX1()
                           SELECT CASE CBMSG
                           CASE %WM_COMMAND
                              SELECT CASE CBCTLMSG
                              CASE %EN_SETFOCUS
                                 TXTL = 1
                              CASE %EN_KILLFOCUS
                                 TXTL = 0
                              END SELECT
                           END SELECT
                           CONTROL GET TEXT hDlg, %IDTXTBX1 TO T1
                        END FUNCTION
                         
                        CALLBACK FUNCTION TXTBX2()
                           SELECT CASE CBMSG
                           CASE %WM_COMMAND
                              SELECT CASE CBCTLMSG
                              CASE %EN_SETFOCUS
                                 TXTL = 2
                              CASE %EN_KILLFOCUS
                                 TXTL = 0
                              END SELECT
                           END SELECT
                           CONTROL GET TEXT hDlg, %IDTXTBX2 TO T2
                        END FUNCTION
                         
                        CALLBACK FUNCTION TXTBX3()
                           SELECT CASE CBMSG
                           CASE %WM_COMMAND
                              SELECT CASE CBCTLMSG
                              CASE %EN_SETFOCUS
                                 TXTL = 3
                              CASE %EN_KILLFOCUS
                                 TXTL = 0
                              END SELECT
                           END SELECT
                           CONTROL GET TEXT hDlg, %IDTXTBX3 TO T3
                        END FUNCTION
                         
                        CALLBACK FUNCTION DONE1()
                           CONTROL KILL hDlg, %IDTXTBX1
                           CONTROL KILL hDlg, %IDTXTBX2
                           CONTROL KILL hDlg, %IDTXTBX3
                           CONTROL KILL hDlg, %IDOK
                           CONTROL ADD LABEL, hDlg, %IDTXT1, T1, 192, 100, 50, 12, 0
                           CONTROL ADD LABEL, hDlg, %IDTXT2, T2, 192, 115, 50, 12, 0
                           CONTROL ADD LABEL, hDlg, %IDTXT3, T3, 192, 130, 50, 12, 0
                           CONTROL ADD BUTTON, hDlg, %IDOK, "F9 &Edit", 130, 152, 40, 14, CALL OkButton
                           CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Cancel", 200, 152, 40, 14, 0 CALL CancelButton
                        END FUNCTION
                         
                        SUB F10DONE1()
                           SCRN=1
                           CONTROL KILL hDlg, %IDTXTBX1
                           CONTROL KILL hDlg, %IDTXTBX2
                           CONTROL KILL hDlg, %IDTXTBX3
                           CONTROL KILL hDlg, %IDOK
                           CONTROL ADD LABEL, hDlg, %IDTXT1, T1, 192, 100, 50, 12, 0
                           CONTROL ADD LABEL, hDlg, %IDTXT2, T2, 192, 115, 50, 12, 0
                           CONTROL ADD LABEL, hDlg, %IDTXT3, T3, 192, 130, 50, 12, 0
                           CONTROL ADD BUTTON, hDlg, %IDOK, "F9 &Edit", 130, 152, 40, 14, CALL OkButton
                           CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Cancel", 200, 152, 40, 14, 0 CALL CancelButton
                        END SUB
                         
                        CALLBACK FUNCTION OkButton()
                           SCRN=2
                           CONTROL KILL hDlg, %IDTXT1
                           CONTROL KILL hDlg, %IDTXT2
                           CONTROL KILL hDlg, %IDTXT3
                           CONTROL KILL hDlg, %IDOK
                           CONTROL KILL hDlg, %IDCANCEL
                           CONTROL ADD TEXTBOX, hDlg, %IDTXTBX1, T1, 192, 100, 50, 12, CALL TXTBX1
                           CONTROL ADD TEXTBOX, hDlg, %IDTXTBX2, T2, 192, 115, 50, 12, CALL TXTBX2
                           CONTROL ADD TEXTBOX, hDlg, %IDTXTBX3, T3, 192, 130, 50, 12, CALL TXTBX3
                           CONTROL ADD BUTTON, hDlg, %IDOK, "F10 &DONE", 130, 152, 40, 14, CALL DONE1
                           CONTROL SET FOCUS hDlg&,%IDTXTBX1
                        END FUNCTION
                         
                        SUB F9OkButton()
                           SCRN=2
                           CONTROL KILL hDlg, %IDTXT1
                           CONTROL KILL hDlg, %IDTXT2
                           CONTROL KILL hDlg, %IDTXT3
                           CONTROL KILL hDlg, %IDOK
                           CONTROL KILL hDlg, %IDCANCEL
                           CONTROL ADD TEXTBOX, hDlg, %IDTXTBX1, T1, 192, 100, 50, 12, CALL TXTBX1
                           CONTROL ADD TEXTBOX, hDlg, %IDTXTBX2, T2, 192, 115, 50, 12, CALL TXTBX2
                           CONTROL ADD TEXTBOX, hDlg, %IDTXTBX3, T3, 192, 130, 50, 12, CALL TXTBX3
                           CONTROL ADD BUTTON, hDlg, %IDOK, "F10 &DONE", 130, 152, 40, 14, CALL DONE1
                           CONTROL SET FOCUS hDlg&,%IDTXTBX1
                        END SUB
                         
                        CALLBACK FUNCTION CancelButton()
                           DIALOG END CBHNDL, 0
                        END FUNCTION
                         
                        FUNCTION PBMAIN () AS LONG
                           $REGISTER NONE
                           LOCAL result AS LONG
                         
                           T1$ = "A2345"
                           T2$ = "B2345678"
                           T3$ = "C2345678"
                           SCRN = 1
                           'TXTL = 1
                           ' ** Create a new dialog template 160, 50, 0, 0
                           DIALOG NEW 0, "DATA BASE ONE", ,, 400, 350, 0, 0 TO hDlg
                           ' ** Add controls to it
                           CONTROL ADD LABEL, hDlg, %IDLABEL1, " 5 CHARACTERS>", 125, 100, 65, 12, 0
                           CONTROL ADD LABEL, hDlg, %IDLABEL2, " 8 CHARACTERS>", 125, 115, 65, 12, 0
                           CONTROL ADD LABEL, hDlg, %IDLABEL3, "10 CHARACTERS>", 125, 130, 65, 12, 0
                           CONTROL ADD LABEL, hDlg, %IDTXT1, T1, 192, 100, 50, 12, 0
                           CONTROL ADD LABEL, hDlg, %IDTXT2, T2, 192, 115, 50, 12, 0
                           CONTROL ADD LABEL, hDlg, %IDTXT3, T3, 192, 130, 50, 12, 0
                           CONTROL ADD BUTTON, hDlg, %IDOK, "F9 &Edit", 130, 152, 40, 14, CALL OkButton
                           CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Cancel", 200, 152, 40, 14, 0 CALL CancelButton
                           ' ** Display the dialog
                           DIALOG SHOW MODELESS hDlg CALL DlgProc
                           CALL KBHook
                        END FUNCTION
                        Timm




                        [This message has been edited by Timm Motl (edited August 15, 2001).]
                        mailto:[email protected]
                        Tsunami Record Manager

                        Comment


                          #13
                          Timm
                          To see the F9 key stop working when the program is run:
                          1. on first screen press F9 to goto edit screen
                          2. tab all the way down to highlight F10 DONE button and press enter
                          3. now back on the first screen F9 does not work. To make F9 work
                          again you have to press F10 first and then F9 will work.

                          I do not know if you will get the same results I did, but I do not
                          see why not unless the problem is computer related.


                          ------------------
                          Robert Alvarez

                          Comment


                            #14
                            Robert:

                            OK, now I see what you are talking about. I revised the source code in my last posting to correct that
                            situation (look for "Added later"). When you tab to the "F10" button and press enter, you need to call
                            the F10DONE1 sub just as if the F10 key had been pressed.

                            Timm
                            mailto:[email protected]
                            Tsunami Record Manager

                            Comment


                              #15
                              Is there a simple way to trap a key like say the CTRL or ALT key
                              so that a "secret" flag can be set?

                              Didnt I read that Hooking was not good?

                              ------------------
                              Kind Regards
                              Mike

                              Comment


                                #16
                                Mike:

                                > Didnt I read that Hooking was not good?

                                As far as I know, in the U.S. it's illegal everywhere but certain parts of Nevada.

                                However, the code examples above are simply using the GetMessage function (see win32api) to retrieve messages
                                from the calling thread's message queue, act on them if necessary or simply pass them through. Monitoring for
                                keyboard messages can be as elaborate as the example above, or simple enough to watch for the occurance of a
                                single keystroke that you want to intercept... it's up to you.

                                Obviously, you can cause problems using the GetMessage function, just like you can with any other function...
                                you need to do it correctly. I've been using this technique in almost all of my PB/DLL apps without problems
                                on any Windows version.

                                Others may have a different view...

                                Timm


                                [This message has been edited by Timm Motl (edited August 15, 2001).]
                                mailto:[email protected]
                                Tsunami Record Manager

                                Comment


                                  #17
                                  Hooking is a standard Windows technique, more commonly referred to as
                                  subclassing or superclassing. There are good reasons to avoid global
                                  keyboard system hooks, but that's a special case.


                                  ------------------
                                  Tom Hanlin
                                  PowerBASIC Staff

                                  Comment


                                    #18
                                    Timm
                                    That works. Thanks again for your help.
                                    I now can use this sample code for keyboard control in my applications.

                                    RA

                                    ------------------
                                    Robert Alvarez

                                    Comment


                                      #19
                                      Curious why MSGBOX doesn't work after CALL KBHOOK is finished?

                                      Code:
                                      FUNCTION PBMAIN
                                         DIALOG NEW 0, "Keyboard Trap", , , 200, 60, %WS_SYSMENU + %WS_MINIMIZEBOX  TO hDlg
                                         CONTROL ADD LABEL, hDlg, 100, "Keyboard trap is in place... start pressing keys.", 25, 15, 150, 10, %SS_SUNKEN + %SS_NOPREFIX
                                         DIALOG SHOW MODELESS hDlg CALL DlgProc
                                         CALL KBHook 'doesn't return until end
                                         DIM x AS LONG
                                         FOR x = 1 TO 10 'works
                                           SLEEP 250
                                           BEEP
                                         NEXT
                                         MSGBOX "HI"         'nope
                                         MSGBOX "HI"         'nope
                                         SHELL "NOTEPAD.EXE" 'works
                                      END FUNCTION
                                      ------------------

                                      Comment


                                        #20
                                        Best guess is because the keyboard hook function (assuming it's the KBHook function posted on page one) is sucking up all the messages for the current thread. Then again, "MSGBOX" is a proprietary function so we don't really know what it's doing, do we?

                                        Going back to the 'leadoff' post of this thread...
                                        I am new to DLL and would like some help on how to:
                                        1. use F1-F10, enter, etc. keys
                                        2. limit text entered in text box so not be continuous typing
                                        3. use enter key to make cursor go to next text box when you
                                        have two or more text boxes instead of having to use tab.
                                        4. printing text & graphics. you have one posted but would
                                        to see if there are other posting else where or some place else
                                        to see more examples
                                        1. Pick off the WM_CHAR and/or WM_KEYDOWN|UP and/or WM_SYSKEYDOWN|UP notifications in your dialog procedure. Then again, nobody uses function keys in GUI applications anymore. You can also do this using subclassing or *what might be the most straighforward method* keyboard accelerators (see ACCEL xxx in your help file)).
                                        2. See the EM_SETLIMITTEXT message in your Windows' API reference
                                        3. Search here for "subclass". There have got to be at least one hundred ninety-seven demos of converting <ENTER> to <TAB> (end edit and advance one field on screen). (Not that I would recommend this: <TAB> is "the Windows way" and the use of <ENTER> may confuse users).
                                        4. See XPRINT family of functions in your PB/WIN 8x help file.

                                        MCM


                                        Michael Mattias
                                        Tal Systems (retired)
                                        Port Washington WI USA
                                        [email protected]
                                        http://www.talsystems.com

                                        Comment

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