Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

DLL32: Dealing with EDIT/TEXT controls

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

  • DLL32: Dealing with EDIT/TEXT controls

    Code:
    '==============================================================================
    '
    '   Edit Control encapsulation for PB/DLL 5.0
    '   Copyright (c) 1997,98 by PowerBASIC, Inc.
    '
    '   Notes:
    '
    '   *  Assumes that WIN32API.INC will also be included into your code.
    '   *  Windows 95 has a limit of 65536 bytes per edit control.
    '   *  Success = 0 if an operation is successful, otherwise a non-zero value
    '      is returned.
    '
    '==============================================================================
     
    '------------------------------------------------------------------------------
    '  TITLE: EmCanUndo
    '   DESC: Determine whether an edit-control operation can be undone; that is,
    '         whether the control can respond to the %EM_UNDO message.
    ' SYNTAX: success = EmCanUndo(hEdit)
    '
    FUNCTION EmCanUndo(BYVAL hEdit AS LONG) AS LONG
      FUNCTION = SendMessage(hEdit, %EM_CANUNDO, 0, 0)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmCharFromPos
    '   DESC: Retrieve the zero-based character index and zero-based line index of
    '         the character nearest the specified point in an edit control.
    ' SYNTAX: nPos = EmCharFromPos(hEdit, x, y)
    '  NOTES: 'x' specifies the x-coordinate of a point in the edit control's
    '         client area. The coordinate is relative to the upper-left corner of
    '         the client area. 'y' specifies the y-coordinate of a point in the
    '         edit control's client area. The coordinate is relative to the
    '         upper-left corner of the client area. he return value specifies the
    '         character index in the low-order word and the line index in the
    '         high-order word. For single-line edit controls, the line index is
    '         always 0. The return value is the last character in the edit control
    '         if the given point is beyond the last character in the control. The
    '         return value is -1 if the specified point is outside the client area
    '         of the edit control.
    '
    FUNCTION EmCharFromPos(BYVAL hEdit AS LONG, BYVAL x AS INTEGER, BYVAL y AS INTEGER) AS LONG
      FUNCTION = SendMessage(hEdit, %EM_CHARFROMPOS, 0, MAKLNG(x, y))
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmEmptyUndoBuffer
    '   DESC: Reset the undo flag of an edit control. The undo flag is set whenever
    '         an operation within the edit control can be undone.
    ' SYNTAX: EmEmptyUndoBuffer hEdit
    '  NOTES: The undo flag is automatically reset whenever the edit control
    '         receives a %WM_SETTEXT or %EM_SETHANDLE message.
    '
    SUB EmEmptyUndoBuffer(BYVAL hEdit AS LONG)
      SendMessage hEdit, %EM_EMPTYUNDOBUFFER, 0, 0
    END SUB
     
    '------------------------------------------------------------------------------
    '  TITLE: EmFmtLines
    '   DESC: Set the inclusion flag of soft linebreak characters on or off within
    '         a multiline edit control. A soft linebreak consists of two carriage
    '         returns and a linefeed and is inserted at the end of a line that is
    '         broken because of wordwrapping.
    ' SYNTAX: EmFmtLines hEdit, AddEolFlag
    '  NOTES: 'AddEolFlag' specifies whether soft-linebreak characters are to be
    '         inserted. A value of TRUE inserts the characters; a value of FALSE
    '         removes them. This message affects only the buffer returned by the
    '         %EM_GETHANDLE message and the text returned by the %WM_GETTEXT
    '         message. It has no effect on the display of the text within the edit
    '         control. EmFmtLines does not affect a line that ends with a hard
    '         linebreak. A hard linebreak consists of one carriage return and a
    '         linefeed.
    '
    SUB EmFmtLines(BYVAL hEdit AS LONG, BYVAL AddEolFlag AS LONG)
      SendMessage hEdit, %EM_FMTLINES, ISTRUE(AddEolFlag) AND 1, 0
    END SUB
     
    '------------------------------------------------------------------------------
    '  TITLE: EmGetFirstVisibleLine
    '   DESC: Determine the uppermost visible line in an edit control.
    ' SYNTAX: nLine = EmGetFirstVisibleLine(hEdit)
    '  NOTES: The return value is the zero-based index of the uppermost visible
    '         line in a multiline edit control. For single-line edit controls, the
    '         return value is the zero-based index of the first visible character.
    '
    FUNCTION EmGetFirstVisibleLine(BYVAL hEdit AS LONG) AS LONG
      FUNCTION = SendMEssage(hEdit, %EM_GETFIRSTVISIBLELINE, 0, 0)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmGetHandle
    '   DESC: Retrieve a handle of the memory currently allocated for a multiline
    '         edit control's text.
    ' SYNTAX: hMem = EmGetHandle(hEdit)
    '  NOTES: The return value is a memory handle identifying the buffer that holds
    '         the content of the edit control. If an error occurs, such as sending
    '         the message to a single-line edit control, the return value is zero.
    '
    FUNCTION EmGetHandle(BYVAL hEdit AS LONG) AS LONG
      FUNCTION = SendMessage(hEdit, %EM_GETHANDLE, 0, 0)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmGetLimitText
    '   DESC: Retrieve the current text limit, in characters, for an edit control.
    ' SYNTAX: nBytes = EmGetLimitText(hEdit)
    '
    FUNCTION EmGetLimitText(BYVAL hEdit AS LONG) AS LONG
      FUNCTION = SendMessage(hEdit, %EM_GETLIMITTEXT, 0, 0)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmGetLineCount
    '   DESC: Retrieve the number of lines in a multiline edit control.
    ' SYNTAX: nLines = EmGetLineCount(hEdit)
    '  NOTES: The return value is the number of lines in the multiline edit
    '         control. If no text is in the edit control, the return value is 1.
    '
    FUNCTION EmGetLineCount(BYVAL hEdit AS LONG) AS LONG
      FUNCTION = SendMessage(hEdit, %EM_GETLINECOUNT, 0, 0)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmGetMargins
    '   DESC: Retrieve the widths of the left and right margins for an edit control.
    ' SYNTAX: nWidth = EmGetMargins(hEdit)
    '  NOTES: Returns the width of the left margin in the low-order word, and the
    '         width of the right margin in the high-order word.
    '
    FUNCTION EmGetMargins(BYVAL hEdit AS LONG) AS LONG
      FUNCTION = SendMessage(hEdit, %EM_GETMARGINS, 0, 0)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmGetModify
    '   DESC: Determine whether the content of an edit control has been modified.
    ' SYNTAX: fModify = EmGetModify(hEdit)
    '  NOTES: If the content of edit control has been modified, the return value is
    '         TRUE; otherwise, it is FALSE. Windows maintains an internal flag
    '         indicating whether the content of the edit control has been changed.
    '         This flag is cleared when the edit control is first created;
    '         alternatively, an application can send an EM_SETMODIFY message to
    '         the edit control to clear the flag.
    '
    FUNCTION EmGetModify(BYVAL hEdit AS LONG) AS LONG
      FUNCTION = SendMessage(hEdit, %EM_GETMODIFY, 0, 0)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmGetPasswordChar
    '   DESC: Retrieve the password character displayed in an edit control when
    '         the user enters text.
    ' SYNTAX: nChar = EmGetPasswordChar(hEdit)
    '  NOTES: The return value specifies the character to be displayed in place of
    '         the character typed by the user. The return value is %NULL if no
    '         password character exists. If the edit control is created with the
    '         %ES_PASSWORD style, the default password character is set to an
    '         asterisk (*).
    '
    FUNCTION EmGetPasswordChar(BYVAL hEdit AS LONG) AS LONG
      FUNCTION = SendMessage(hEdit, %EM_GETPASSWORDCHAR, 0, 0)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmGetSel
    '   DESC: Get the starting and ending character positions of the current
    '         selection in an edit control.
    ' SYNTAX: EmGetSel hEdit, lpStart, lpEnd
    '  NOTES: 'lpStart' receives the starting position of the selection. 'lpEnd'
    '         receives the position of the first nonselected character after the
    '         end of the selection.
    '
    SUB EmGetSel(BYVAL hEdit AS LONG, lpStart AS LONG, lpEnd AS LONG)
      SendMessage hEdit, %EM_GETSEL, VARPTR(lpStart), VARPTR(lpEnd)
    END SUB
     
    '------------------------------------------------------------------------------
    '  TITLE: EmGetTextLength
    '   DESC: Retrieve the length of all text in an edit control.
    ' SYNTAX: nLen = EmGetTextLength(hEdit)
    '
    FUNCTION EmGetTextLength(BYVAL hEdit AS LONG) AS LONG
      FUNCTION = SendMessage(hEdit, %WM_GETTEXTLENGTH, 0, 0)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmGetText
    '   DESC: Retrieve the text from an edit control.
    ' SYNTAX: Text$ = EmGetText(hEdit)
    '
    FUNCTION EmGetText(BYVAL hEdit AS LONG) AS STRING
     
      LOCAL nLen   AS LONG
      LOCAL buffer AS STRING
     
      nLen = EmGetTextLength(hEdit)
      Buffer = SPACE$(nLen + 1)
      GetWindowText hEdit, BYVAL STRPTR(Buffer), nLen + 1
     
      FUNCTION = Buffer
     
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmGetThumb
    '   DESC: Retrieve the position of the scroll box (thumb) in a multiline edit
    '         control.
    ' SYNTAX: nPos = EmGetThumb(hEdit)
    '
    FUNCTION EmGetThumb(BYVAL hEdit AS LONG) AS LONG
      FUNCTION = SendMessage(hEdit, %EM_GETTHUMB, 0, 0)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmLimitText
    '   DESC: Limit the amount of text the user may enter into an edit control.
    ' SYNTAX: EmLimitText nBytes
    '  NOTES: EmLimitText limits only the text the user can enter. It has no effect
    '         on any text already in the edit control when the message is sent,
    '         nor does it affect the length of the text copied to the edit control
    '         by the %WM_SETTEXT message. If an application uses the %WM_SETTEXT
    '         message to place more text into an edit control than is specified by
    '         EmLimitText, the user can edit the entire contents of the edit
    '         control.
    '
    SUB EmLimitText(BYVAL hEdit AS LONG, BYVAL chMax AS LONG)
      SendMessage hEdit, %EM_LIMITTEXT, chMax, 0
    END SUB
     
    '------------------------------------------------------------------------------
    '  TITLE: EmLineFromChar
    '   DESC: Retrieve the index of the line that contains the specified character
    '         index in a multiline edit control. A character index is the number of
    '         characters from the beginning of the edit control.
    ' SYNTAX: nLine = EmLineFromChar(hEdit, index)
    '  NOTES: 'index' specifies the character index of the character contained in
    '         the line whose number is to be retrieved. If it is -1, either the line
    '         number of the current line (the line containing the caret) is
    '         retrieved or, if there is a selection, the line number of the line
    '         containing the beginning of the selection is retrieved.
    '
    FUNCTION EmLineFromChar(BYVAL hEdit AS LONG, BYVAL index AS LONG) AS LONG
      FUNCTION = SendMessage(hEdit, %EM_LINEFROMCHAR, index, 0)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmLineIndex
    '   DESC: Retrieve the character index of a line in a multiline edit control.
    '         The character index is the number of characters from the beginning of
    '         the edit control to the specified line.
    ' SYNTAX: nPos = EmLineIndex(hEdit, nLine)
    '  NOTES: 'nLine' specifies the zero-based line number. A value of -1 specifies
    '         the current line number (the line that contains the caret). The
    '         return value is the character index of the line specified in the line
    '         parameter, or it is -1 if the specified line number is greater than
    '         the number of lines in the edit control.
    '
    FUNCTION EmLineIndex(BYVAL hEdit AS LONG, BYVAL nLine AS LONG) AS LONG
      FUNCTION = SendMessage(hEdit, %EM_LINEINDEX, nLine, 0)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmLineLength
    '   DESC: Retrieve the length of a line, in characters, in an edit control.
    ' SYNTAX: nLength = EmLineLength(hEdit, index)
    '  NOTES: 'index' specifies the character index of a character in the line
    '         whose length is to be retrieved. If this parameter is -1, the message
    '         returns the number of unselected characters on lines containing
    '         selected characters. For example, if the selection extended from the
    '         fourth character of one line through the eighth character from the
    '         end of the next line, the return value would be 10 (three characters
    '         on the first line and seven on the next). The return value is the
    '         length, in characters, of the line specified by the 'index' parameter.
    '         The return value is the length, in characters, of the text in the
    '         edit control when it is a single-line edit control.
    '
    FUNCTION EmLineLength(BYVAL hEdit AS LONG, BYVAL index AS LONG) AS LONG
      FUNCTION = SendMessage(hEdit, %EM_LINELENGTH, index, 0)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmLineScroll
    '   DESC: Scroll the text vertically and/or horizontally in a multiline edit
    '         control.
    ' SYNTAX: success = EmLineScroll(hEdit, x, y)
    '  NOTES: If the message is sent to a multiline edit control, the return value
    '         is TRUE; if the message is sent to a single-line edit control, the
    '         return value is FALSE. The edit control does not scroll vertically
    '         past the last line of text in the edit control. If the current line
    '         plus the number of lines specified by the 'y' parameter exceeds the
    '         total number of lines in the edit control, the value is adjusted so
    '         that the last line of the edit control is scrolled to the top of the
    '         edit-control window.
    '
    FUNCTION EmLineScroll(BYVAL hEdit AS LONG, BYVAL x AS LONG, BYVAL y AS LONG) AS LONG
      FUNCTION = SendMessage(hEdit, %EM_LINESCROLL, x, y)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmPosFromChar
    '   DESC: Retrieve the coordinates of the specified character in an edit
    '         control.
    ' SYNTAX: nPosd = EmPosFromChar(hEdit, index)
    '  NOTES: The return value specifies the coordinates of the upper-left corner
    '         of the character. If 'index' is greater than the index of the last
    '         character in the control, the return value specifies the coordinates
    '         of the position just past the last character in the control. The
    '         x-coordinate is in the low-order word and the y-coordinate is in the
    '         high-order word. The coordinates are relative to the upper-left
    '         corner of the edit control's client area. For a single-line edit
    '         control, the y-coordinate is always zero. A returned coordinate can
    '         be negative if the character has been scrolled outside the edit
    '         control's client area. The coordinates are truncated to integer
    '         values.
    '
    FUNCTION EmPosFromChar(BYVAL hEdit AS LONG, BYVAL index AS LONG) AS LONG
      FUNCTION = SendMessage(hEdit, %EM_POSFROMCHAR, index, 0)
    END FUNCTION
     
    '------------------------------------------------------------------------------
    '  TITLE: EmSetText
    '   DESC: Set the text of an edit control.
    ' SYNTAX: EmSetText hEdit, text$
    '
    SUB EmSetText(BYVAL hEdit AS LONG, BYVAL text AS STRING)
      SetWindowText hEdit, BYVAL STRPTR(text)
    END SUB

    -------------
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Home of the BASIC Gurus
    www.basicguru.com

  • #2
    Dave, are these updated includes for PBGEN10 or are you just releasing
    these to all?

    Regards, Jules
    Best regards
    Jules
    www.rpmarchildon.com

    Comment


    • #3
      I don't know if they've been updated or not. These are from my personal INCLUDE directory.

      --Dave


      -------------
      PowerBASIC Support
      mailto:[email protected][email protected]</A>

      Home of the BASIC Gurus
      www.basicguru.com

      Comment


      • #4
        Does the edit control have to exist or does this also
        create it? Would appreciate an example CALL.

        ------------------
        [email protected]
        The world is full of apathy, but who cares?

        Comment


        • #5
          Guys,

          This is not a discussion forum. It's for source code. If you have questions, please post them in the Windows or Programming forums.

          --Dave

          ps. Mike, the edit control must exist and you must have the handle to use these functions.

          ------------------
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Home of the BASIC Gurus
          www.basicguru.com

          Comment

          Working...
          X