Programming by Example

 

A BB4W Compendium

freeman69@gmx.com

IDIC BBC_Owl2 M&P

Blank line removal

  10 INSTALL @lib$+"WINLIB2"

  20 INSTALL @lib$+"WINLIB5"

  30

  40 ON ERROR SYS "MessageBox",@hwnd%,REPORT$,0,48:QUIT

  50

  60 SYS "SetWindowText",@hwnd%,"Blank line removal"

  70

  80 REM Main window creation (Fontsize=12)

  90 scrtop=190:scrwdth=265

 100 dlg%=FN_newdialog("",0,0,scrwdth,scrtop,12,1000)

 110 dlg%!16=(dlg%!16 OR &40000000) AND NOT &80400000

 120

 130 REM Static text box 1

 140 I$="1. Copy and paste program text into the edit box."+CHR$(13)

 150 I$+="2. Click the button below to remove unwanted line spacing."+CHR$(13)

 160 I$+="    The result will be copied to the clipboard, ready to paste into BB4W."

 170 PROC_static(dlg%,I$,101,4,4,250,28,0)

 180

 190 REM Text entry box

 200 ES_MULTILINE=4

 210 ES_WANTRETURN=&1000

 220 WS_VSCROLL=&200000

 230 PROC_editbox(dlg%,"",103,0,34,265,137,WS_VSCROLL+ES_WANTRETURN+ES_MULTILINE)

 240

 250 REM Delete button creation

 260 idDelete=FN_setproc(PROCgrab_text)

 270 PROC_pushbutton(dlg%,"Remove and Copy",idDelete,8,175,76,12,0)

 280

 290 REM Brings the main window to the screen

 300 PROC_showdialog(dlg%)

 310

 320 REM Find object id

 330 SYS "GetDlgItem",!dlg%,103 TO hEdit

 340

 350 REM Dock dialogue: Resize outer window border to

 360 REM surround inner dialogue box & disable resize button

 370 DIM rc{l%,t%,r%,b%}

 380 SYS "GetWindowRect",!dlg%,rc{}

 390 SYS "GetWindowLong",@hwnd%,-16 TO style%

 400 SYS "SetWindowLong",@hwnd%,-16, style% AND NOT &50000

 410 SYS "AdjustWindowRect",rc{},style% AND NOT &50000, 0

 420 SYS "SetWindowPos",@hwnd%,0,0,0,rc.r%-rc.l%,rc.b%-rc.t%,102

 430

 440 REM Send script to clipboard on window close, just in case

 450 ON CLOSE PROCgrab_text:QUIT

 460

 470 REPEAT

 480   WAIT 1

 490 UNTIL FALSE

 500 END

 510

 520 REM Copy updated edit box contents to clipboard

 530 DEF PROCgrab_text

 540 LOCAL text$

 550 text$=FNget_text

 560 SYS "GlobalAlloc",&2000,LEN(text$)+1 TO hdata%

 570 SYS "GlobalLock",hdata% TO tmp%

 580 $$tmp%=text$

 590 SYS "GlobalUnlock",hdata%

 600 SYS "OpenClipboard",@hwnd%

 610 SYS "EmptyClipboard"

 620 SYS "SetClipboardData",1,hdata%

 630 SYS "CloseClipboard"

 640 PROC_setfocus(hEdit)

 650 ENDPROC

 660

 670 REM Copy text from edit box, removing extra LF & CR characters

 680 DEF FNget_text

 690 LOCAL T$,size%,mem%,lf%,c,a

 700 SYS "SendMessage",hEdit,14,0,0 TO size%

 710 SYS "GlobalAlloc",0,size%+1 TO mem%

 720 SYS "SendMessage",hEdit,13,size%+1,mem%

 730 T$=$$mem%

 740 SYS "GlobalFree",mem%

 750 REPEAT lf%=INSTR(T$,CHR$10)

 760   IF lf% THEN

 770     c=0:REPEAT:c+=1:a=ASC(MID$(T$,lf%+c)):UNTIL a<>10 AND a<>13

 780     T$=LEFT$(T$,lf%-1)+MID$(T$,lf%+c)

 790   ENDIF

 800 UNTIL lf%=0

 810 =T$