Announcement

Collapse
No announcement yet.

Floating TextBox without buttons

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

  • Borje Hagsten
    replied
    Maybe something like this can be of help:
    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Modal, "floating" input box. Only one way out, except 3-finger
    ' salute or pull plug - to write some text and press the Enter key..
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
     
    %ID_TEXT = 10                         'Id for textbox
    GLOBAL oldTxtproc AS LONG             'for address of original textbox procedure
    DECLARE CALLBACK FUNCTION DlgProc
    DECLARE CALLBACK FUNCTION TextWndProc
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Create dialog and controls, etc
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN
      LOCAL hDlg AS LONG, hEdit AS LONG
     
      DIALOG NEW 0, "Programmer's logic:", , , 120, 46, %WS_CAPTION, 0 TO hDlg
      SetWindowPos hDlg, %HWND_TOPMOST, 0,0,0,0, %SWP_NOMOVE OR %SWP_NOSIZE 'Set dialog as TopMost
     
      CONTROL ADD LABEL, hDlg, -1, "Press Enter to Exit:", 2, 2, 114, 10
      CONTROL ADD TEXTBOX, hDlg, %ID_TEXT, "", 2, 12, 116, 32, %WS_CHILD OR %ES_MULTILINE OR _
                                 %WS_VSCROLL, %WS_EX_CLIENTEDGE CALL DlgProc
      CONTROL HANDLE hDlg, %ID_TEXT TO hEdit
     
      oldTxtproc = SetWindowLong(hEdit, %GWL_WNDPROC, CODEPTR(TextWndProc)) 'Subclass Edit control
      SetFocus hEdit                                                        'Give textbox focus
     
      DIALOG SHOW MODAL hDlg CALL DlgProc                                   'Modal is okay here
     
      IF oldTxtproc THEN SetWindowLong hEdit, %GWL_WNDPROC, oldTxtproc      'Restore from subclass at exit
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Main dialog's message handler
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgProc
      SELECT CASE CBMSG
         CASE %WM_COMMAND
           IF CBCTL = %WM_USER + 1 AND CBCTLMSG = %BN_CLICKED THEN DIALOG END CBHNDL
      END SELECT
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Textbox's subclassed message handler
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION TextWndProc
      SELECT CASE CBMSG
         CASE %WM_KEYDOWN                    'Trap keyboard input here
            IF CBWPARAM = %VK_RETURN THEN    'If Enter key was pressed
               LOCAL txt AS STRING
               CONTROL GET TEXT GetParent(CBHNDL), %ID_TEXT TO txt 'Get Text
     
               SetWindowPos GetParent(CBHNDL), _
                            %HWND_NOTOPMOST, 0,0,0,0, %SWP_NOMOVE OR %SWP_NOSIZE 'Remove TopMost
     
               IF LEN(TRIM$(txt)) = 0 THEN
                  MSGBOX "Please enter your secret code!", %MB_OK, "CIA message" 'Whatever..
                  SetWindowPos GetParent(CBHNDL), _
                               %HWND_TOPMOST, 0,0,0,0, %SWP_NOMOVE OR %SWP_NOSIZE 'Set TopMost again
                  SetFocus CBHNDL                             'Set focus back to textbox
                  EXIT FUNCTION                               'Cancel process
                  
               ELSE
                  MSGBOX "You wrote: " & txt, %MB_OK, "OKAY!" 'Show what user entered
               END IF                                         'and close the program, if you like..
               SendMessage GetParent(CBHNDL), %WM_COMMAND, MAKLNG(%WM_USER + 1, %BN_CLICKED), CBHNDL
               FUNCTION = 0 : EXIT FUNCTION
            END IF
     
      END SELECT
      FUNCTION = CallWindowProc(oldTxtproc, CBHNDL, CBMSG, CBWPARAM, CBLPARAM)
    END FUNCTION
    Okay, saw you wanted it to close on no input. Just change the last
    check code above to make it act like you want..
    ------------------


    [This message has been edited by Borje Hagsten (edited February 28, 2001).]

    Leave a comment:


  • Bern Ertl
    replied
    Mike, Lance is correct. Your original question was not very clear,
    so I gave you a simple outline how you could achieve a persistent
    edit box without having to create/destroy.

    My outline assumed that you would have more than one dialog running.
    Why have a 'floating edit box' if there is no other dialog? The

    Code:
    CONTROL GET SIZE hMainDlg TO X&, X&
    statement was meant to check for the closing of your (other) main
    dialog. When X& = 0 the dialog no longer exists - either you executed
    a DIALOG END statement or the user clicked the system box (little X
    box in in the upper right corner). Note that the statement specifies
    hMainDlg and not hDlg.



    ------------------
    Bernard Ertl

    Leave a comment:


  • Lance Edmonds
    replied
    in all honesty, this is the wrong approach to successfully make a masked-input edit control - this approach is almost "fighting" the standard edit control's behavior, and is highly inefficient since the loop is running constantly, even when there is no activity relative to the edit control.

    you should either subclass the edit control and handle it "from inside"; or work with the notification messages that are sent to the dialog callback function (ie, %wm_command|%en_update, etc); or a combination of the two.

    an in-depth tutorial on this is really beyond the bounds of this forum (since the topic is relatively complicated), however, i posted an example on subclassing a ddt textbox control in the source code forum many moons ago (aug 99) - see:

    for detailed information on working with edit controls, i highly recommend rector/newcomer's "win32 programming". see http://www.powerbasic.com/support/pb...hread.php?t=39

    i hope this helps!


    ------------------
    lance
    powerbasic support
    mailto:[email protected][email protected]</a>

    Leave a comment:


  • Mike Doty
    replied
    Code:
    'Can anyone get the following to work?
    'This could turn into a very useful input routine
    
    'Modeless textbox  will attempt input mask later
    
    '1 Get Enter or Esc to exit
    '2 CONTROL GET SIZE hDlg, %IDText TO x&, x&  'what is x& for?
    '3 Can each keystroke be trapped?
    '4 Loop until x& = 0  x& never equals 0
    
    
    #COMPILE EXE
    #DIM ALL
    #REGISTER NONE
    #INCLUDE "WIN32API.INC"
    %IDTEXT     = 100
    %IDOK       = 1
    %IDCANCEL   = 2
    %IDTEXT     = 100
    %BS_DEFAULT = 1
    '------------------------------------------------------------------------------
    GLOBAL UserName AS STRING
    
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN () AS LONG
      LOCAL hDlg   AS LONG
      LOCAL result AS LONG
      LOCAL answer AS STRING
      DIM x AS LONG
      DIM Style AS LONG
    
      DIALOG NEW 0, "Press Enter or Esc to end   (10 characters exits)", ,, 320, 40, 0, 0 TO hDlg
      CONTROL ADD TEXTBOX, hDlg, %IDTEXT, Answer$, 10,  1, 300, 12, 0
      style& = %ES_Center
      DIALOG SHOW MODELESS hDlg
      DO
        DIALOG DOEVENTS
        CONTROL GET TEXT hDlg, %IDText TO Answer$
        'CONTROL GET SIZE hDlg TO 300,12   'can't use 300,12
        'can't put in width and height as variables?
        CONTROL GET SIZE hDlg, %IDText TO x&, x& 'x&,x&
        BEEP             'just seeing if loop is running
        SLEEP 0
      LOOP UNTIL LEN(Answer$) > 10   '10 characters a way out
      DIALOG END hDlg                'added this
      MSGBOX Answer$ + CHR$(34) + STR$(x) + CHR$(34)
    END FUNCTION



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

    Leave a comment:


  • Bern Ertl
    replied
    Mike, have you tried creating a MODELESS dialog with a textbox?

    You can then use a loop to process any user input in the box.

    Ie.:

    Code:
    DIALOG NEW 0, "I won't go away!",,,320,40,0,0 TO hTBDlg
    CONTROL ADD TEXTBOX, hTBDlg, %IDTEXT, Default$, 10,  1, 300, 12, 0
    
    
    'Make your main dialogs MODELESS also here...
    
    
    DIALOG SHOW MODELESS hTBDlg 'Use callback if desired to process textbox
    
    
    DO
       DIALOG DOEVENTS
    
    
    'or process textbox here....
       CONTROL GET TEXT hTBDlg, %IDTEXT TO TextVar$
       'Process TextVar$
    
    
       'Process main dialog here or in a callback
    
    
       CONTROL GET SIZE hMainDlg TO X&, X&
    LOOP UNTIL X& = 0
    ------------------
    Bernard Ertl



    [This message has been edited by Bern Ertl (edited February 27, 2001).]

    Leave a comment:


  • Mike Doty
    started a topic Floating TextBox without buttons

    Floating TextBox without buttons

    'Can a TextBox be created that can
    'stay in a loop without recreating
    'the textbox each time? I want to
    'use it to accept input at any position
    'on a screen or accept multiple lines
    'of input. Also, can this be done without
    'the OK and Cancel buttons.
    '
    If the input is blank (result=0) just terminate.
    '
    'Any help would be appreciated.

    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "WIN32API.INC"
    %IDTEXT     = 100
    %IDOK       = 1
    %IDCANCEL   = 2
    %IDTEXT     = 100
    %BS_DEFAULT = 1
    '------------------------------------------------------------------------------
    GLOBAL UserName AS STRING
    
    CALLBACK FUNCTION OkButton()
    
      CONTROL GET TEXT CBHNDL, %IDTEXT TO UserName
      DIALOG END CBHNDL, 1
    
    END FUNCTION
    
    CALLBACK FUNCTION CancelButton()
    
      DIALOG END CBHNDL, 0
    
    END FUNCTION
    
    '------------------------------------------------------------------------------
    
    FUNCTION PBMAIN () AS LONG
    
      #REGISTER NONE
    
      LOCAL hDlg   AS LONG
      LOCAL result AS LONG
      LOCAL answer AS STRING
      DIM x AS LONG
      DIM Style AS LONG
      DIM DEFAULT AS STRING
    
    top:
    ' ** Create a new dialog template
      DIALOG NEW 0, "Click Cancel to end", ,, 320, 40, 0, 0 TO hDlg
    
    
    ' ** Add controls to it
      style& = %ES_Center
      default$ = ""
      CONTROL ADD TEXTBOX, hDlg, %IDTEXT, Default$, 10,  1, 300, 12, 0
      CONTROL ADD BUTTON, hDlg, %IDOK, "OK", 10, 22, 40, 14, %BS_DEFAULT CALL OkButton
      CONTROL ADD BUTTON, hDlg, %IDCANCEL, "Cancel", 84, 22, 40, 14, 0 CALL CancelButton
    
    ' ** Display the dialog
        DIALOG SHOW MODAL hDlg TO result
    ' ** Check the result
         'IF result THEN MSGBOX UserName
         IF result THEN GOTO top
    END FUNCTION

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


    [This message has been edited by Mike Doty (edited February 27, 2001).]
Working...
X