April 18, 2024, 11:26:23 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Rich text edit control

Started by Andy, September 05, 2017, 12:55:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

I'm working on using a rich text edit control (something I've never used before).

I want the user to be able to press <CR> to jump to the next line, but I don't want them to be able to press <CR> and then another <CR>.

This is - leaving a blank line.

Example:

Line1
Line2


Line3

Does anyone know how I could do this please?

Thanks,
Andy.
 
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

subclass the edit control, monitor keystrokes, set a flag after the the first CR is hit, dump CRs while the flag is set, when any other key is hit reset the flag
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Larry,

Sub classing the Rich edit control worked, together with a slightly modified mask input.

My registry viewer and editor now correctly accepts multi string registry entries that the user cannot get wrong (unlike regedit).

The code below is an example of how to do it - bare in mind that the edit2 box is borderless - just type away - press CR, and then try pressing CR again.

Once you type something else - you can press CR again.

$INCLUDE "windowssdk.inc"

int crcount = 0
WINDOW win

const EDIT1 = 100
const EDIT2 = 101

OpenWindow win,0,0,416,500,@SIZE|@MINBOX|@MAXBOX|@CAPTION|@SYSMENU,0,"Form2",&win_handler
CONTROL win,@EDIT,"",79,74,186,25,@CTEDITAUTOH|@CTEDITLEFT,EDIT1
CONTROL win,@RICHEDIT,"",79,120,500,300,0x50B010C4|@TABSTOP,EDIT2
SETCONTROLCOLOR win,edit2,RGB(146,117,0),rgb(0,0,0)

int MaskLoop = 0
string MaskString = ""

for MaskLoop = 32 to 126
    MaskString = MaskString + chr$(MaskLoop)
next MaskLoop

MaskString = MaskString + chr$(13) 'Return
MaskString = MaskString + chr$(8)  'Backspace

MaskEditControlCR(win, EDIT2, MaskString)

setfocus win,edit2

WAITUNTIL ISWINDOWCLOSED(win)
END


sub win_handler(), int
  select @MESSAGE
    case @IDCREATE
      centerwindow win
    case @IDCONTROL
      select @CONTROLID
        case EDIT1
        case EDIT2
      endselect
    case @IDCLOSEWINDOW
      closewindow win
  endselect
  return 0
endsub


sub MaskedEditHandlerCR(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam),LRESULT
  pointer mask = GetWindowLong(hwnd, GWL_USERDATA)
  SELECT uMsg
    case WM_NCDESTROY
      delete mask
    CASE @IDCHAR
if #<int>mask[wParam & 0xff] = FALSE
return 0
else
  if wParam = 13 'Carriage Return pressed
  if crcount > 0
  return
  endif
  crcount ++
  setcaption win,"Carriage Return set to 1."
  else
  setcaption win,"Carriage Return reset to zero."
  crcount = 0
  endif
      endif
    ENDSELECT
  RETURN CallWindowProcA(#<int>mask[256],hWnd,uMsg,wParam,lParam)
ENDSUB


SUB MaskEditControlCR(WINDOW parent, INT id, string szMask)
   HWND hEdit = GETCONTROLHANDLE(parent,id)
   LONG lpFn = GetWindowLong(hEdit, GWL_WNDPROC)
   pointer mask
   int i

   if lpFn <> &MaskedEditHandlerCR
     mask = new(int, 257)
   else
     mask = GetWindowLong(hEdit, GWL_USERDATA)
   endif

   for i = 0 to 255
     #<int>mask[i] = FALSE
   next i

   for i = 0 to len(szMask)
     #<int>mask[szMask[i]] = TRUE
   next i

   if lpFn <> &MaskedEditHandlerCR
     #<int>mask[256] = SetWindowLongA(hEdit,GWL_WNDPROC,&MaskedEditHandlerCR)
     SetWindowLong(hEdit, GWL_USERDATA, mask)
   endif

ENDSUB


Thanks.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

subclassing really comes in handy sometimes
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library