Hi,
I need help!
Just going back to tab controls for a while, and I have some basic questions as I'm not getting it with this control type.
I have looked at the example program, and looked through the posts, and even MSDN doesn't really tell me a lot.
Attached is just a basic window with a tab control in it.
There are two buttons:
1. Delete - delete a tab
2. Add - add a tab.
Now when I add say 3 or 4 new tabs, they appear - so far so good.
But then the < & > buttons appear, I presume so you can "scroll" though the tabs either way.
But after adding say 4 new tabs and "scrolling back" to the original ones or clicking on tabs, some tabs just disappear?
It seems to happen when I first click say tab 3 then press either the < or > buttons.
I sub classed the tab control to see what message was / is being sent when clicking < or > and it is indeed sending a message to delete the selected tab.
Why?
What am I doing wrong here?
And what are the < & > buttons called? and do you have to detect a message sent from them? if so how?
Help!
Thanks,
Andy.
Andy
I just tested this old EB example and all work fine
are you sure that all is fine with your computer ?
registry ..???...fragmenting....
long time ago i made OxyEdit in EB with tabs abd all work fine .
PS ..to admin::::
Why is a problem with code tags is not fixed ??
::)
------------------------------------------------------------------------------
'EBASIC example program
'Compile as a WINDOWS target
def win:window
def run:int
def tc,temp:int
'declare "user32",CreateWindowExA(ex:int,classtring,name:string,style:int,x:int ,y:int,x1:int,y1:int,parent:UINT,id:int,hinstance:int,ed:int),uint
declare "user32",DestroyWindow(wnd:uint),int
setid "WS_VISIBLE",0x10000000
setid "WS_CHILD",0x40000000
CONST TCM_INSERTITEM = 0x1307
CONST TCN_SELCHANGE = -550-1
CONST TCM_GETCURSEL = 4875
run = 1
openwindow win,0,0,420,300,@CAPTION|@SYSMENU,0,"Tab Control Sample",&mainwindow
tc=CreateTabControl(win,10,5,5,400,200)
SETCONTROLCOLOR(win, tc, RGB(255,255,255), RGB(0,0,0))
if tc=0
closewindow win
end
endif
AddTab(tc,0,"First Tab")
SETCONTROLCOLOR(win, 10, RGB(255,255,255), RGB(0,0,0))
AddTab(tc,1,"Tab 2")
AddTab(tc,2,"Tab 3")
AddTab(tc,3,"Tab 4")
AddTab(tc,4,"Tab 5")
AddTab(tc,5,"Tab 6")
waituntil run=0
DeleteTabControl(tc)
closewindow win
end
sub mainwindow
select @CLASS
case @IDCREATE
CENTERWINDOW #<WINDOW>@HITWINDOW
case @IDCLOSEWINDOW
run = 0
case @IDCONTROL
SELECT @NOTIFYCODE
case TCN_SELCHANGE
move win,0,205
temp=GetSelectedTab(tc)
print win,USING("& # &","Tab#",temp+1,"was selected..")
ENDSELECT
endselect
return
ENDSUB
sub CreateTabControl(parent:WINDOW,num:int,x:int,y:int,w:int,ht:int),UINT
tc = CONTROLEX(parent,"systabcontrol32","",x,y,w,ht,@BORDER|@EXCLIENTEDGE,0,num)
return tc
ENDSUB
sub AddTab(hWnd:uint,index:int,text:string)
type TC_ITEM
def mask:int
def res1:int
def res2:int
def pszText:POINTER
def cchTextMax:int
def iImage:int
def lParam:int
endtype
def tie:TC_ITEM
tie.mask=1
'TCIF_TEXT=1
tie.pszText=text
tie.cchTextMax=len(text)
tie.iImage=-1
SendMessage(hWnd,TCM_INSERTITEM,index,tie)
return
ENDSUB
sub GetSelectedTab(hWnd:uint),INT
temp = SENDMESSAGE(hWnd,TCM_GETCURSEL,0,0)
return temp
ENDSUB
sub DeleteTabControl(hWnd:uint)
DestroyWindow(hWnd)
return
ENDSUB
here i changed font ...
---------------------------------
'EBASIC example program
'Compile as a WINDOWS target
def win:window
def run:int
def tc,temp:int
'declare "user32",CreateWindowExA(ex:int,classtring,name:string,style:int,x:int ,y:int,x1:int,y1:int,parent:UINT,id:int,hinstance:int,ed:int),uint
declare "user32",DestroyWindow(wnd:uint),int
setid "WS_VISIBLE",0x10000000
setid "WS_CHILD",0x40000000
CONST TCM_INSERTITEM = 0x1307
CONST TCN_SELCHANGE = -550-1
CONST TCM_GETCURSEL = 4875
run = 1
openwindow win,0,0,420,300,@CAPTION|@SYSMENU,0,"Tab Control Sample",&mainwindow
tc=CreateTabControl(win,10,5,5,400,200)
SETCONTROLCOLOR(win, tc, RGB(255,255,255), RGB(0,0,0))
SETFONT win, "Consolas", 10, 300, 0, 10
if tc=0
closewindow win
end
endif
AddTab(tc,0,"First Tab")
SETCONTROLCOLOR(win, 10, RGB(255,255,255), RGB(0,0,0))
AddTab(tc,1,"Tab 2")
AddTab(tc,2,"Tab 3")
AddTab(tc,3,"Tab 4")
AddTab(tc,4,"Tab 5")
AddTab(tc,5,"Tab 6")
waituntil run=0
DeleteTabControl(tc)
closewindow win
end
sub mainwindow
select @CLASS
case @IDCREATE
CENTERWINDOW #<WINDOW>@HITWINDOW
case @IDCLOSEWINDOW
run = 0
case @IDCONTROL
SELECT @NOTIFYCODE
case TCN_SELCHANGE
move win,0,205
temp=GetSelectedTab(tc)
print win,USING("& # &","Tab#",temp+1,"was selected..")
ENDSELECT
endselect
return
ENDSUB
sub CreateTabControl(parent:WINDOW,num:int,x:int,y:int,w:int,ht:int),UINT
tc = CONTROLEX(parent,"systabcontrol32","",x,y,w,ht,@BORDER|@EXCLIENTEDGE,0,num)
'SETFONT (tc, "Consolas", 10, 600, 0)
return tc
ENDSUB
sub AddTab(hWnd:uint,index:int,text:string)
type TC_ITEM
def mask:int
def res1:int
def res2:int
def pszText:POINTER
def cchTextMax:int
def iImage:int
def lParam:int
endtype
def tie:TC_ITEM
tie.mask=1
'TCIF_TEXT=1
tie.pszText=text
tie.cchTextMax=len(text)
tie.iImage=-1
SendMessage(hWnd,TCM_INSERTITEM,index,tie)
return
ENDSUB
sub GetSelectedTab(hWnd:uint),INT
temp = SENDMESSAGE(hWnd,TCM_GETCURSEL,0,0)
return temp
ENDSUB
sub DeleteTabControl(hWnd:uint)
DestroyWindow(hWnd)
return
ENDSUB
Thanks Aurel,
No I don't think it's the registry.
If you look at the two screen shots attached, mine has the < > buttons (which I want), and yours adds another row instead of the < > buttons.
It's these < > buttons that are doing the delete selected tab - all I want them to do is to scroll between the existing tabs.
Any ideas?
Thanks,
Andy.
Andy
How the heck you get one above another...?
looks to me like two tab controls ..do i have a right ?
also if you creating tabs when you rich the end of cotrol size then pin buttons are there
also conrol must be in-line flag
I see i get same
in oxyedit i create tab control on this way :
'***************TAB CONTROL*************************************************
'crete tab control
tc=CONTROLEX(w1,"SysTabControl32","",170,38,456,24,@TCS_HOTTRACK,0,50)
and yes this work properly...
Andy
I modified some of your code. Take a look at this.
$include "windowssdk.inc"
$INCLUDE "richedit.inc"
int TabCount
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,500,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,480,25,@TABSTOP|@TCS_OWNERDRAWFIXED|TCS_BUTTONS|TCS_SINGLELINE,0,IDTABCONTROL 'No 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
setcontrolcolor(w1,IDTABCONTROL ,rgb(0,0,0),rgb(211,0,211))
CASE @IDCLOSEWINDOW
CLOSEWINDOW w1
case @IDCONTROL
SELECT @CONTROLID
case 1
IF @NOTIFYCODE = @BN_CLICKED
tcdeletetab(w1,idtabcontrol,OnTab-1)
TabCount = tcGetTabCount(w1,idtabcontrol)
OnTab = TabCount
tcSetSelectedTab(w1,IDTABCONTROL,OnTab-1)
endif
case 2
IF @NOTIFYCODE = @BN_CLICKED
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
endif
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 = *<DRAWITEMSTRUCT>lParam.hDC
SetBkColor(hDC,rgb(211,211,211))
SetBkMode(hDC,TRANSPARENT)
SetTextAlign(hDC,TA_CENTER|TA_BASELINE)
IF IswindowEnabled(hWnd)
IF *<DRAWITEMSTRUCT>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 *<DRAWITEMSTRUCT>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 = *<DRAWITEMSTRUCT>lParam.rcitem
FillRect(hDC,b,hBr)
txt = tcGetTabText(w1,IDTABCONTROL,*<DRAWITEMSTRUCT>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
Aurel,
Thanks, you have really put some work in again as usual to help out, and it's nice to know there are people out there who will always help.
It is strange how you can get different results.
Larry,
Thank you for amending my earlier code, on first testing it works correctly and as I need it to, so thanks again for that - nice to see you posting code again!
General note:
I now have a working example that I can use, but that's not quite the end of it for me, I need to now understand the subtle differences between the code examples.
Finally, if you've never see Aurel's Oxy editor, there's some nice work there, have a look sometime.
Thanks guys,
Andy.
:)
Andy
main difference is in tab control Flag which in this case should be @TCS_HOTTRACK
original version use autopositions and is let say good for settings panel(read window)
Larry example is very complex in a sense of using a lot of pointers which in general i like to
avoid if there is no real need for that , pointers are good in IWB/EB because they are fast but
UDT + pointers are slow and eat memory ..also Larry example use sapero ssdk which i never liked to use .
hmm
some off topic
i am always wondering why EB is little bit and in some cases very slow in execution comparing with other
similar compilers,it is not problem in compiler itself then in in NASM
look at this :
QuoteOne thing NASM is bad at is optimizing jumps (choosing shortest possible jump instructions). When given a large file with several thousands of jumps it assembles pathetically slow.
So NASM is a reason..
I hope that new version which LarryS works will eliminate need for NASM.
Aurel,
Thanks for telling me the main differences, it does help a lot.
Don't know much at all about NASM, used Ebasic a lot, it was my first entry language into programming with Windows.
So far, I've managed to shrink the editor program down by 2,500 lines and still going. Most things are still working correctly, so it's just a matter of working through the program now to get version 5.0 up and running.
Thanks again Aurel.
Andy.
No problem
Andy ... ;)