Announcement

Collapse
No announcement yet.

Showing an old blinking underscore cursor in a Graphics Window

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

  • Showing an old blinking underscore cursor in a Graphics Window

    Well here is ole dummy again:

    Is there a way to show a cursor like the (console cursor) in a graphics window where text is being entered. Is there a command for it or will it take a lot of programming to show a cursor.

    Thanks everyone for any help.

  • #2
    Hi Leroy,
    A simple Graphic Box (tall and narrow) drawn to end of the most recent print operation? Each time you write text, erase the old box and draw a new one at the end of the new text.

    If you want it to "blink", use a timer to do draw/erase at a short interval.

    Something like that?

    Comment


    • #3
      The GRAPHIC LINE INPUT and GRAPHIC INPUT statements will cause a flashing Caret to be displayed until the input action is completed with the Enter key.
      (They are blocking statements though which might not be convenient)

      To display a Caret on demand you could draw/flash your own construct as suggested by Gary.

      Another option might be to lean on the Windows API to do the job.
      ie Use CreateCaret(), SetCaretPos() and ShowCaret()

      Here's some test code as an example of using the API with a Graphic Window.
      Code:
      #Compile Exe          'PBCC5^
      #Dim All
      #CONSOLE OFF
      #Register None
      #Include "WIN32API.INC"
      
      '------------------/
      
      Function PBMain () As Long
       Local hGWin, hFont, hStatic As Dword
       Local x, y, ncW, ncH As Single
       Local sI As String
        Font New "Courier", 12, 1 To hFont                          ' NB. Fixed-width font
       ' Create and show a Graphic window
        Graphic Window "Graphic Window", 300, 300, 400, 300 To hGWin
          hStatic = GetWindow(hGWin, %GW_CHILD)                     ' handle of Static child of Gfx Window
      
         ' SubClass Static to attach cursor etc
          SetProp hGWin, "OldStaticProc", SetWindowLong(hStatic, %GWL_WNDPROC, CodePtr(StaticProc))
          SendMessage hStatic, %WM_User + 1000, 0, 0                ' Send message to Subclass Proc to Create Caret
      
        Graphic Attach hGWin, 0
        Graphic Set Font hFont                                      ' Font select.
        Graphic Chr Size To ncW!, ncH!                              ' Get char size for this font.
        Graphic Box (10, 10) - (390, 290), 0, %Blue                 ' Draw box - eg has 'char grid' of 17 x 37
        Graphic Set Pos (20,2)                                      ' with the Courier 12 point font.
        Graphic Print "Graphic Note Pad"
        Graphic Set Pos (2*ncW, 2*ncH)
      
        Graphic Get Pos To x, y
        SendMessage hStatic, %WM_User + 1001, Mak(Long, ncW, ncH), Mak(Long, x, y)    ' Update caret pos
        SetCaretPos 2*ncW,2*ncH                                                       ' pass char size and x, y
       ' InKey$ Loop
        Do
          Graphic InKey$ To sI                                      ' Get keyboard input
            If Len(sI)=1 Then
              If sI = $Cr Then   ' New Line.. unless at bottom of typing range (this e.g. = 270)
                Graphic Print "" : Graphic Get Pos To x,y : Graphic Set Pos (2*ncW, Min(y, 270))
                SendMessage hStatic, %WM_User + 1001, 0, Mak(Long, 2*ncW, Min(y, 270))  ' Send message to update cursorSubclass Proc to
              End If
              If sI = $Bs Then   ' Backspace (easier when using fixed width font!)
                Graphic Get Pos To x,y
                If x <= 2*ncW Then sI = "" : Iterate Loop
                Graphic Set Pos (x-ncW,y)  : Graphic Print Space$(1)
                Graphic Set Pos (x-ncW,y)  : SendMessage hStatic, %WM_User + 1001, 0, Mak(Long, x-ncW, y)
                sI = "" : Iterate Loop
              End If
              Graphic Get Pos To x,y
              If x => 370 Then
                Graphic Print sI : Graphic Get Pos To x,y : Graphic Set Pos (2*ncW, Min(y, 270))
              Else
                Graphic Print sI;
              End If
              Graphic Get Pos To x,y : SendMessage hStatic, %WM_User + 1001, 0, Mak(Long, x, y)
              Sleep 10
            End If
            If Len(sI) = 2 Then                                     ' Extended key pressed (not number pad)
              Graphic Get Pos To x, y
              Select Case Asc(Right$(sI,1))
                Case 72 : y = Max(y - ncH, 2*ncH)  : Graphic Set Pos (x,y)   ' Up Arrow
                  SendMessage hStatic, %WM_User + 1001, 0, Mak(Long, x, y)
                Case 75 : x = Max(x - ncW, 2*ncW)  : Graphic Set Pos (x,y)   ' Left Arrow
                  SendMessage hStatic, %WM_User + 1001, 0, Mak(Long, x, y)
                Case 77 : x = Min(x + ncW, 37*ncW) : Graphic Set Pos (x,y)   ' Right Arrow
                  SendMessage hStatic, %WM_User + 1001, 0, Mak(Long, x, y)
                Case 80 : y = Min(y + ncH, 17*ncH) : Graphic Set Pos (x,y)   ' Down Arrow
                  SendMessage hStatic, %WM_User + 1001, 0, Mak(Long, x, y)
              End Select
            End If
          Sleep 10       ' Avoid hogging the CPU
        Loop While IsWindow(hGWin)
       ' Cleanup
        SetWindowLong(hStatic, %GWL_WNDPROC, GetProp(hGWin, "OldStaticProc"))
        RemoveProp hGWin, "OldStaticProc"
        SetWindowLong(hGWin, %GWL_WNDPROC, GetProp(hGWin, "OldGWProc"))
        RemoveProp hGWin, "OldGWroc"
        Graphic Window END
      End Function
      '------------------/PBMain
      
      Function StaticProc(ByVal hWnd As Dword, ByVal wMsg As Dword, _
                      ByVal wParam As Dword, ByVal lParam As Long) As Long
       Local x! ,y!
       Static ncw!, ncH!
        Select Case As Long wMsg
          Case %WM_User + 1000                    ' Startup - initialize caret
            CreateCaret hWnd, 0, 2, 16            ' ## Create solid Caret 2x16 pixels
      
          Case %WM_User + 1001                    ' User message to update caret pos
            If wParam Then ncW = Lo(Word, wParam) : ncH = Hi(Word, wParam)
            x = Lo(Word, lParam) : y = Hi(Word, lParam)
            SetCaretPos x, y                      ' ## Set Caret Position
            ShowCaret hWnd                        ' ## Showcaret
      
          Case %WM_KillFocus
            DestroyCaret                          ' Don't show caret if focus elsewhere
      
          Case %WM_SetFocus
            CreateCaret hWnd, 0, 2, 16            ' ## Create solid Caret 2x16 pixels
            ShowCaret hWnd                        ' we're back! - show caret
      
          Case %WM_MouseMove
            If GetFocus = hWnd Then               ' don't update cursor pos if focus elsewhere
              x = Lo(Word, lParam) : y = Hi(Word, lParam)
              SetWindowText GetParent(hWnd), "x" + Str$(x) + ", y" + Str$(y)
            End If
      
          Case %WM_LButtonUp
            x = Lo(Word, lParam) : y = Hi(Word, lParam)
            SetWindowText GetParent(hWnd), "LBtnUp at: " + "x" + Str$(x) + ", y" + Str$(y)
            x = (x\ncW)*ncW : y = (y\ncH)*ncH : SetCaretPos x, y        ' new pos adjusted to char/line spacing
            Graphic Attach GetParent(hWnd), 0 : Graphic Set Pos (x, y)
        End Select
       Function = CallWindowProc(GetProp (GetParent(hWnd), "OldStaticProc"), hWnd, wMsg, wParam, lParam)
      End Function
      '------------------/StaticProc
      Rgds, Dave

      Comment


      • #4
        A SPECIAL thank you to Mr. Gary Beene for your suggestion on showing a blinking cursor. It only took the following lines of code to make a fairly decent blinking cursor. I had another suggestion with the code to go with it but since I am a beginner I really didn't understand it all that well. I tried a vertical one and settled on the horizontal one below. Again thanks for the help, there are some amazing and generous people on this forum, there is always an abundance of helpful members on here.

        A$ = ""
        GRAPHIC SET POS (colVal&, rowVal&)
        IF lng% < = 4 THEN ' Space for 5 digits don't want cursor to print on 5th digit, it goes to 6th digit then leaves a white space if use backspace.
        DO
        GRAPHIC BOX (colVal&, rowVal& + 14) - (colVal& + 12, rowVal + 15), 0, %RGB_WHITE, %RGB_WHITE
        SLEEP 100
        GRAPHIC BOX (colVal&, rowVal& + 14) - (colVal& + 12, rowVal + 15), 0, %RGB_BLACK, %RGB_BLACK
        GRAPHIC WAITKEY$(".0123456789QqRrCc" & CHR$(13) & CHR$(8) ,50) TO A$
        LOOP WHILE A$ = ""
        ELSE
        GRAPHIC WAITKEY$(".0123456789QqRrSs" & CHR$(13) & CHR$(8)) TO A$
        END IF

        Comment

        Working...
        X