April 19, 2024, 03:34:03 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Tabs

Started by Andy, June 07, 2018, 06:38:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi,

Can anyone tell me how to change the colour of an individual tab, just looking at the tab control example which is great, but all tabs are grey.

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

Egil

Tried using SETCONTROLCOLOR?

Egil
Support Amateur Radio  -  Have a ham  for dinner!

LarryMc

you mean like this to show the selected tab?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Yes, something like that Larry would be good.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

TabControl win_main,0,4,2000,24,@BORDER|@TABSTOP|@TCS_TOOLTIPS|@TCS_OWNERDRAWFIXED ,0,IDT_CONTROL
tcInsertTab win_main,IDT_CONTROL,0,"Browse by Category"
tcInsertTab win_main,IDT_CONTROL,1,"Browse by Author"
tcInsertTab win_main,IDT_CONTROL,2,"Browse by Date"
tcInsertTab win_main,IDT_CONTROL,3,"Search"
SETFONT win_main, "tahoma", 8, 700,  0x00FF0000,IDT_CONTROL
string LPFNPROP
LPFNPROP= "TLZ8TD96"
SetProp(getcontrolhandle(win_main,IDT_CONTROL), LPFNPROP, SetWindowLong(getcontrolhandle(win_main,IDT_CONTROL), GWL_WNDPROC, &MyTabProc))
'tcSetSelectedTab(win_main,IDT_CONTROL,0)


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 window property
SetWindowLong(hwnd, GWL_WNDPROC, proc)
RemoveProp(hwnd, LPFNPROP)

case WM_DRAWITEM
hDC=*<DRAWITEMSTRUCT>lParam.hdc
SetBkMode(hdc, TRANSPARENT)
SetTextAlign (hdc,TA_CENTER | TA_Baseline)
if IsWindowEnabled(hwnd)
IF *<DRAWITEMSTRUCT>lParam.itemState =1
hbr=CreateSolidBrush(GETSYSCOLOR(COLOR_HIGHLIGHT))
SetTextColor(hdc, GETSYSCOLOR(COLOR_HIGHLIGHTTEXT))
'SetBkColor(hdc, GETSYSCOLOR(COLOR_HIGHLIGHT))
ELSE
hbr=CreateSolidBrush(GETSYSCOLOR(COLOR_BTNFACE))
SetTextColor(hdc, GETSYSCOLOR(COLOR_BTNTEXT))
ENDIF
else
IF *<DRAWITEMSTRUCT>lParam.itemState =1
hbr=CreateSolidBrush(RGB(128,128,255))
SetTextColor(hdc, RGB(92,92,92))
'SetBkColor(hdc, RGB(128,128,255))
ELSE
hbr=CreateSolidBrush(GETSYSCOLOR(COLOR_BTNFACE))
SetTextColor(hdc, GETSYSCOLOR(COLOR_GRAYTEXT ))
ENDIF
endif
obrush = SelectObject(hdc,hbr)
winrect b = *<DRAWITEMSTRUCT>lParam.rcitem
FillRect(hDC,b,hbr)
txt=tcGetTabText(win_main,IDT_CONTROL,*<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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Larry,

That's great, the only problem is that the text for the tabs doesn't show up until you have clicked on each tab.


$include "windowssdk.inc"

window win_main
const IDT_CONTROL = 500


OPENWINDOW win_main,0,0,1000,600,@CAPTION|@SYSMENU,0,"Tab Control Sample",&mainwindow

TabControl win_main,0,4,2000,24,@BORDER|@TABSTOP|@TCS_TOOLTIPS|@TCS_OWNERDRAWFIXED ,0,IDT_CONTROL
tcInsertTab win_main,IDT_CONTROL,0,"Browse by Category"
tcInsertTab win_main,IDT_CONTROL,1,"Browse by Author"
tcInsertTab win_main,IDT_CONTROL,2,"Browse by Date"
tcInsertTab win_main,IDT_CONTROL,3,"Search"
SETFONT win_main, "tahoma", 8, 700,  0x00FF0000,IDT_CONTROL
string LPFNPROP
LPFNPROP= "TLZ8TD96"
SetProp(getcontrolhandle(win_main,IDT_CONTROL), LPFNPROP, SetWindowLong(getcontrolhandle(win_main,IDT_CONTROL), GWL_WNDPROC, &MyTabProc))
'tcSetSelectedTab(win_main,IDT_CONTROL,0)


waituntil win_main = 0
CLOSEWINDOW win_main
end

sub mainwindow
select @CLASS
case @IDCREATE
CENTERWINDOW #<WINDOW>@HITWINDOW

case @IDCLOSEWINDOW
  closewindow win_main
        end

case @IDCONTROL
SELECT @NOTIFYCODE

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 window property
SetWindowLong(hwnd, GWL_WNDPROC, proc)
RemoveProp(hwnd, LPFNPROP)

case WM_DRAWITEM
hDC=*<DRAWITEMSTRUCT>lParam.hdc
SetBkMode(hdc, TRANSPARENT)
SetTextAlign (hdc,TA_CENTER | TA_Baseline)
if IsWindowEnabled(hwnd)
IF *<DRAWITEMSTRUCT>lParam.itemState =1
hbr=CreateSolidBrush(GETSYSCOLOR(COLOR_HIGHLIGHT))
SetTextColor(hdc, GETSYSCOLOR(COLOR_HIGHLIGHTTEXT))
'SetBkColor(hdc, GETSYSCOLOR(COLOR_HIGHLIGHT))
ELSE
hbr=CreateSolidBrush(GETSYSCOLOR(COLOR_BTNFACE))
SetTextColor(hdc, GETSYSCOLOR(COLOR_BTNTEXT))
ENDIF
else
IF *<DRAWITEMSTRUCT>lParam.itemState =1
hbr=CreateSolidBrush(RGB(128,128,255))
SetTextColor(hdc, RGB(92,92,92))
'SetBkColor(hdc, RGB(128,128,255))
ELSE
hbr=CreateSolidBrush(GETSYSCOLOR(COLOR_BTNFACE))
SetTextColor(hdc, GETSYSCOLOR(COLOR_GRAYTEXT ))
ENDIF
endif
obrush = SelectObject(hdc,hbr)
winrect b = *<DRAWITEMSTRUCT>lParam.rcitem
FillRect(hDC,b,hbr)
txt=tcGetTabText(win_main,IDT_CONTROL,*<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


So can we change that?

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

Egil

It works fine after rearranging the tabcontrol code:

TabControl win_main,0,4,2000,24,@BORDER|@TABSTOP|@TCS_TOOLTIPS|@TCS_OWNERDRAWFIXED ,0,IDT_CONTROL
SETFONT win_main, "tahoma", 8, 700,  0x00FF0000,IDT_CONTROL
string LPFNPROP
LPFNPROP= "TLZ8TD96"
tcInsertTab win_main,IDT_CONTROL,0,"Browse by Category"
tcInsertTab win_main,IDT_CONTROL,1,"Browse by Author"
tcInsertTab win_main,IDT_CONTROL,2,"Browse by Date"
tcInsertTab win_main,IDT_CONTROL,3,"Search"
SetProp(getcontrolhandle(win_main,IDT_CONTROL), LPFNPROP, SetWindowLong(getcontrolhandle(win_main,IDT_CONTROL), GWL_WNDPROC, &MyTabProc))
tcSetSelectedTab(win_main,IDT_CONTROL,0)




Egil
Support Amateur Radio  -  Have a ham  for dinner!

Andy

Thanks Egil,

That's great!!!

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

Andy

Well, I'm new to the tabbing functions.

If I wanted different controls showing for different tabs I would have to use:

tcGetFocusTab to see which tab has the focus, and the hide / show the appropriate controls?

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

Brian

This works nicely...

Brian

Brian

I realised today that you can change the shape of tab controls to a variety of shapes, rather than
them looking just like buttons. Any ideas? Can't find anything meaningful on the 'net

Brian

Andy

Brian,

Thanks for all your help, and that was going to be my next question lol.

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

LarryMc

When you use the OWNERDRAWN flag it means exactly that, owner drawn; not system drawn.
If you look at the tail end of both my  and Brain's subclass procedures you will see this block of code:

oBrush=SelectObject(hDC,hBr)
winrect b=*<DRAWITEMSTRUCT>lParam.rcitem
FillRect(hDC,b,hBr)
txt=tcGetTabText(win,IDTABCONTROL,*<DRAWITEMSTRUCT>lParam.itemID)
TextOut(hDC,b.left+(b.right-b.left)/2,b.top+14,txt,LEN(txt))
SelectObject(hDC,oBrush)
deleteObject(hBr)

This actually draws the tabs.  If you want the tabs to look different(other than color) then this code has to be changed.
hDC is the device context you  have to draw to
winrect b is the size of the rectangle that the tab has to fit inside of
txt is the text of the tab you are currently drawing

in this case FillRect api was used to used to fill rectangle b with bruch hBr
you can get as fancy as you want

The code here draws all the tabs the same
with an extra if statement you could have it draw the selected tab a larger size than the non selected.

or by using SELECT/CASE you could have each tab a different color and then have the selected a larger size.

it all depends on how much time you want to spend on it
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

June 12, 2018, 01:32:53 AM #13 Last Edit: June 12, 2018, 01:35:38 AM by Andy
Thanks Larry will look at that.

Next one:

Here is a child window with tabs, but it doesn't show the tab's text - help anyone?



$include "windowssdk.inc"

const EDIT_1 = 1
const EDIT_2 = 2
const EDIT_3 = 3
const EDIT_4 = 4
const EDIT_5 = 5
const EDIT_6 = 6
const EDIT_7 = 7
const EDIT_8 = 8
const EDIT_9 = 9
const EDIT_10 = 10
const EDIT_11 = 11
const EDIT_12 = 12
const EDIT_13 = 13
const EDIT_14 = 14
const EDIT_15 = 15
const EDIT_16 = 16

const STATIC_1 = 101
const STATIC_2 = 102
const STATIC_3 = 103
const STATIC_4 = 104
const STATIC_5 = 105
const STATIC_6 = 106
const STATIC_7 = 107
const STATIC_8 = 108
const STATIC_9 = 109
const STATIC_10 = 110
const STATIC_11 = 111
const STATIC_12 = 112
const STATIC_13 = 113
const STATIC_14 = 114
const STATIC_15 = 115
const STATIC_16 = 116

const BUTTON_1 = 201
const BUTTON_2 = 202
const BUTTON_3 = 203
const BUTTON_4 = 204
const BUTTON_5 = 205
const BUTTON_6 = 206
const BUTTON_7 = 207
const BUTTON_8 = 208
const BUTTON_9 = 209
const BUTTON_10 = 210
const BUTTON_11 = 211
const BUTTON_12 = 212
const BUTTON_13 = 213
const BUTTON_14 = 214
const BUTTON_15 = 215
const BUTTON_16 = 216
const BUTTON_17 = 217
const BUTTON_18 = 218


window w1,w2
CONST TCM_INSERTITEM = 0x1307
CONST TCN_SELCHANGE = -550-1
CONST TCM_GETCURSEL = 4875

CONST IDTABCONTROL=400

OPENWINDOW w1,0,0,1024,768,@MINBOX|@MAXBOX|@SIZE,0,"Tab Control",&msgHandler

OPENWINDOW w2,200,50,700,500,@NOCAPTION,w1,"Tab Control",&msgHandler2

TabControl w2,0,4,500,24,@BORDER|@TABSTOP|@TCS_OWNERDRAWFIXED,0,IDTABCONTROL
SETFONT w2,"Tahoma",8,700,0x00FF0000,IDTABCONTROL 'OEM Charset
ISTRING LPFNPROP[9]="TLZ8TD96"
tcInsertTab w2,IDTABCONTROL,0,"Tab1"
tcInsertTab w2,IDTABCONTROL,1,"Tab2"
tcInsertTab w2,IDTABCONTROL,2,"Tab3"
tcInsertTab w2,IDTABCONTROL,3,"Tab4"

tcSetTip w2,IDTABCONTROL,0,tcGetTabText(w2,IDTABCONTROL,0)
tcSetTip w2,IDTABCONTROL,1,tcGetTabText(w2,IDTABCONTROL,1)
tcSetTip w2,IDTABCONTROL,2,tcGetTabText(w2,IDTABCONTROL,2)
tcSetTip w2,IDTABCONTROL,3,tcGetTabText(w2,IDTABCONTROL,3)
tcSetTip w2,IDTABCONTROL,4,tcGetTabText(w2,IDTABCONTROL,4)
SetProp(GETCONTROLHANDLE(w2,IDTABCONTROL),LPFNPROP,SetWindowLong(GETCONTROLHANDLE(w2,IDTABCONTROL),GWL_WNDPROC,&MyTabProc))
tcSetSelectedTab(w2,IDTABCONTROL,1)

WAITUNTIL IswindowClosed(w1)
END

SUB msgHandler(),INT
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW w1
CASE @IDCLOSEWINDOW
CLOSEWINDOW w1

case @IDCONTROL
SELECT @NOTIFYCODE

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
SetBkMode(hDC,TRANSPARENT)
SetTextAlign(hDC,TA_CENTER|TA_BASELINE)
IF IswindowEnabled(hWnd)
IF *<DRAWITEMSTRUCT>lParam.itemState=1
hBr=CreateSolidBrush(RGB(178,164,226))
SetTextColor(hDC,GETSYSCOLOR(COLOR_HIGHLIGHTTEXT))
ELSE
hBr=CreateSolidBrush(GETSYSCOLOR(COLOR_BTNFACE))
SetTextColor(hDC,GETSYSCOLOR(COLOR_BTNTEXT))
ENDIF
ELSE
IF *<DRAWITEMSTRUCT>lParam.itemState=1
hBr=CreateSolidBrush(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

SUB msgHandler2(),INT
SELECT @MESSAGE
CASE @IDCREATE
'CENTERWINDOW w2
CASE @IDCLOSEWINDOW
CLOSEWINDOW w2

case @IDCONTROL
SELECT @NOTIFYCODE
    case TCN_SELCHANGE

ENDSELECT

ENDSELECT
RETURN 0
ENDSUB


Thanks,
Andy.

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

Andy

It's okay, found it!


This line needed to be changed from w1 to w2.

txt=tcGetTabText(w2,IDTABCONTROL,*<DRAWITEMSTRUCT>lParam.itemID)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.