$include "windowssdk.inc" $INCLUDE "richedit.inc" int once = 0 int OnTab = 0 int WasOnTab = 0 openconsole window w1 CONST TCM_INSERTITEM = 0x1307 CONST TCN_SELCHANGE = -550-1 CONST TCM_GETCURSEL = 4875 ISTRING LPFNPROP[9]="TLZ8TD96" istring Buffer1[1048576,100] Buffer1[0,1] = "Hello world" Buffer1[0,2] = "My cat likes her food" Buffer1[0,3] = "Third text" Buffer1[0,4] = "Fourth text" const RichEdit = 100 CONST IDTABCONTROL=400 OPENWINDOW w1,0,0,500,400,@MINBOX|@MAXBOX|@SIZE,0,"Tab Control",&msgHandler setwindowcolor w1,rgb(211,211,211) 'Sets the tab control (right side & pade data to white???? otherwise it's gray??? CONTROL w1,@BUTTON,"Delete OnTab",10,10,120,25,0,1 SETCONTROLCOLOR w1,1,rgb(0,0,0),rgb(211,211,211) CONTROL w1,@BUTTON,"Add Tab",10,40,120,25,0,2 SETCONTROLCOLOR w1,2,rgb(0,0,0),rgb(211,211,211) 'The rich edit control CONTROL w1,@RICHEDIT,"",10,70,460,160,0x50b010c4,RichEdit SETFONT w1,"Arial",12,400,0,RichEdit MODIFYEXSTYLE(w1,0,@EXCLIENTEDGE|WS_BORDER,RichEdit) REDRAWFRAME(w1,RichEdit) SENDMESSAGE w1,EM_SETBKGNDCOLOR,rgb(0,0,0),rgb(211,211,211),RichEdit CONTROLCMD w1,RichEdit,@RTSETLIMITTEXT,1048576 TabControl w1,0,337,500,25,@TABSTOP|@TCS_OWNERDRAWFIXED|TCS_BUTTONS,0,IDTABCONTROL 'No page data showing 'TabControl w1,0,235,500,125,@TABSTOP|@TCS_OWNERDRAWFIXED|TCS_BUTTONS,0,IDTABCONTROL 'Page data showing SETFONT w1,"Arial",12,400,0,IDTABCONTROL tcInsertTab w1,IDTABCONTROL,0,"Editor v5.0 ?" tcInsertTab w1,IDTABCONTROL,1,"Second" tcInsertTab w1,IDTABCONTROL,2,"Third" tcInsertTab w1,IDTABCONTROL,3,"Fourth" SetProp(GETCONTROLHANDLE(w1,IDTABCONTROL),LPFNPROP,SetWindowLong(GETCONTROLHANDLE(w1,IDTABCONTROL),GWL_WNDPROC,&MyTabProc)) tcSetSelectedTab(w1,IDTABCONTROL,1) setcontroltext(w1,RichEdit,Buffer1[0,OnTab]) WAITUNTIL IswindowClosed(w1) closeconsole END SUB msgHandler(),INT SELECT @MESSAGE CASE @IDCREATE CENTERWINDOW w1 CASE @IDCLOSEWINDOW CLOSEWINDOW w1 case @IDCONTROL SELECT @CONTROLID case 1 tcdeletetab(w1,idtabcontrol,OnTab-1) int TabCount = tcGetTabCount(w1,idtabcontrol) OnTab = TabCount tcSetSelectedTab(w1,IDTABCONTROL,OnTab-1) case 2 print "NEW TAB CLICKED, Tab Was ",OnTab Buffer1[0,OnTab] = getcontroltext(w1,RichEdit) TabCount = tcGetTabCount(w1,idtabcontrol) tcInsertTab w1,IDTABCONTROL,TabCount,"Tab " + ltrim$(str$(TabCount+1)) OnTab = TabCount tcSetSelectedTab(w1,IDTABCONTROL,OnTab) setcontroltext(w1,RichEdit,"") print "New tab ",OnTab endselect ENDSELECT RETURN 0 ENDSUB SUB MyTabProc(int hWnd,UINT uMsg,int wParam,int lParam),int INT proc UINT hDC,hBr,oBrush STRING txt proc=GetProp(hWnd,LPFNPROP) SELECT uMsg CASE WM_DESTROY 'Remove subclass and delete w1dow property SetwindowLong(hWnd,GWL_WNDPROC,proc) RemoveProp(hWnd,LPFNPROP) CASE WM_DRAWITEM hDC = *lParam.hDC 'SetBkColor(hDC,rgb(211,211,211)) SetBkMode(hDC,TRANSPARENT) SetTextAlign(hDC,TA_CENTER|TA_BASELINE) IF IswindowEnabled(hWnd) IF *lParam.itemState = 1 'The selected tab hBr = CreateSolidBrush(RGB(0,128,255)) 'Blue colour SetTextColor(hDC,GETSYSCOLOR(COLOR_HIGHLIGHTTEXT)) SetTextAlign(hDC,TA_CENTER|TA_BASELINE) if once = 0 'Seems this is done twice, so let's do this once? 'New Tab Selection print "Tab was ---------> ",OnTab Buffer1[0,OnTab] = getcontroltext(w1,RichEdit) 'Save rich edit text to the correct buffer OnTab = tcGetFocusTab(w1,IDTABCONTROL) + 1 print "Now On Tab ",OnTab 'Now load new text into the rich edit setcontroltext(w1,RichEdit,Buffer1[0,OnTab]) 'Set rich edit text to the correct buffer once = 1 else once = 0 endif ELSE hBr = CreateSolidBrush(rgb(211,211,211)) 'GETSYSCOLOR(COLOR_BTNFACE)) SetTextColor(hDC,GETSYSCOLOR(COLOR_BTNTEXT)) ENDIF ELSE IF *lParam.itemState = 1 hBr = CreateSolidBrush(rgb(211,211,211)) 'GETSYSCOLOR(COLOR_BTNFACE)) SetTextColor(hDC,GETSYSCOLOR(COLOR_BTNTEXT)) ELSE hBr = CreateSolidBrush(GETSYSCOLOR(COLOR_BTNFACE)) SetTextColor(hDC,GETSYSCOLOR(COLOR_BTNTEXT)) ENDIF ENDIF oBrush = SelectObject(hDC,hBr) winrect b = *lParam.rcitem FillRect(hDC,b,hBr) txt = tcGetTabText(w1,IDTABCONTROL,*lParam.itemID) TextOut(hDC,b.left + (b.right-b.left) / 2,b.top + 14,txt,LEN(txt)) SelectObject(hDC,oBrush) DeleteObject(hBr) RETURN 0 CASE WM_ENABLE InvalidateRect(hWnd,NULL,FALSE) RETURN 0 ENDSELECT RETURN CallwindowProc(proc,hWnd,uMsg,wParam,lParam) ENDSUB