MULTI-COLOURED TEXT INPUT BOXES USING A DLL
by Ray Fisher

rmfisher@talk21.com OR
rmfisher@btinternet.com

Home

Liberty BASIC News
Safe Registry and Ini File Alternative
Deleting and Renaming Disk Files
Segments and Flushing
Flat Toolbar with Toolips
Translating 32-bit VB API Calls
Event-Driven Programming Concepts
Spotlight on the Community!
ODBC in Liberty BASIC
Hex Viewer
Listing Files Recursively
Registering Hot Keys
Preventing more than 1 instance
Multi-Coloured Text Input Boxes
Images on Buttons and Statictext
Two Demos by David Conner

In Newsletter No.100 I described how to create a custom control for text input that could have any colour of text and any colour of background.

In a programme using this method it was necessry to have a number of functions at the end of the main part of the code. This was a bit messy, so I have tried to encapsulate the methods in a DLL. By doing this most of the code is hidden from sight, and a single call to the DLL function is all that is required for each instance of the control. This is demonstated in '_1stTestdllv01.bas'.

The calling syntax is:

open "rmfDLLv01.dll" for dll as #rmfdll
calldll #rmfdll, "reInputBox", _
  handle    as long, _ ' handle of parent window
  inkHex$   as ptr, _  ' ink colour
  paperHex$ as ptr, _  ' paper colour
  x         as long, _ ' x co-ord
  y         as long, _ ' y co-ord
  w         as long, _ ' width
  h         as long, _ ' height
  max       as long, _ ' max chars
  hTB       as long    ' returns a handle to the new control
close #rmfdll

This will create a single line input box.
The background can be set to any colour.
The font can be set to any colour.
This version uses HEX colour values for input.
The position and size can be set.
The maximum number of chars entered can be set.
The function returns a handle to the new control.

If multiple instances of the control are required, the code can be kept simple by enclosing the call to the DLL function in a LB function, and this can be called from the main part of the programme with a single line of code. See '_2ndTestdllv01.bas'. In this demo I have added extra code so that the controls can be tabbed by using the ESC key.

I have supplied the source code for the DLL for those who may be interested. At the moment the DLL only contains this single external function. Because the colour information is passed as a hexadecimal value, in Liberty BASIC this must be passed as a string. Inside the function the calls to SendMessage() requires that the colour be passed as a RGB value. Therefore it will be seen that there is an internal function 'hex2rgb()' that converts the HEX string into a RGB value. Because this is all inside the DLL, it is hidden from view in usage.

I hope this is of interest, and any of the code can be copied or altered.

[Editor's note]
'Place text into the text input boxes with the API function SetWindowTextA

CallDLL #user32, "SetWindowTextA",_
hTB As long,_    'handle of textbox
txt$ As ptr,_    'desired text
result As void   'no return

'Retrieve text that the user has typed into the textbox with GetWindowTextA, like this:

CallDLL #user32, "GetWindowTextLengthA",_ 'determine size of buffer
hTB As long,_    'handle of textbox
tlength As long  'returns length of text

Txt$=Space$(tlength)+Chr$(0)
CallDLL #user32, "GetWindowTextA",_
hTV As long,_    'handle of textbox
Txt$ As ptr,_    'buffer to hold returned text
tlength As long,_'size of buffer
blength As long  'size of returned string

print "Text is ";left$(Txt$,blength)
[End editor's note]

  

Home

Liberty BASIC News
Safe Registry and Ini File Alternative
Deleting and Renaming Disk Files
Segments and Flushing
Flat Toolbar with Toolips
Translating 32-bit VB API Calls
Event-Driven Programming Concepts
Spotlight on the Community!
ODBC in Liberty BASIC
Hex Viewer
Listing Files Recursively
Registering Hot Keys
Preventing more than 1 instance
Multi-Coloured Text Input Boxes
Images on Buttons and Statictext
Two Demos by David Conner