May 07, 2024, 02:50:26 AM

News:

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


Disabling a TabControl

Started by LarryMc, June 12, 2009, 05:34:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

I had a need to disable a tab control and discovered that although
you can disable it with the ENABLECONTROL command so that it doesn't
respond to mouse clicks it DOESN'T change the appearance of the tab control.
It still "looks" like it is enabled.

By subclassing the tab control anfter it has been created with the OWNERDRAWN flag
it is easy enough to set the coloring to whatever you would like.
(tab controls don't normally respond to the SETCONTROLCOLOR command either)

The only little oddity is that the tabcontrol is subclassed AFTER the WM_CREATE
message has been sent; meaning the tabcontrol is initially empty.
The only way I knew to get it to draw the new colors and text that first time was to invalidate the control.

There may be a better way to do that??

'EBASIC example program
'sub-classed tabcontrol
'Compile as a WINDOWS target
$INCLUDE "WINDOWSSDK.inc"

def win_main:window
def run:int
def tc,temp:int

const IDT_CONTROL=100

string LPFNPROP
LPFNPROP= "Z8TD96"

run = 1
openwindow win_main,0,0,520,300,@CAPTION|@SYSMENU,0,"Tab Control Sample",&mainwindow
TabControl win_main,0,4,2000,24,@BORDER|@TABSTOP|@TCS_OWNERDRAWFIXED|@TCS_FLATBUTTONS  ,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,  0,IDT_CONTROL
CONTROL win_main,@BUTTON,"Enable TabControl",10,40,120,20,0,1
SETFONT win_main, "tahoma", 8, 700,  0,1
CONTROL win_main,@BUTTON,"Disable TabControl",10,70,120,20,0,2
SETFONT win_main, "tahoma", 8, 700,  0,2
SetProp(getcontrolhandle(win_main,IDT_CONTROL), LPFNPROP, SetWindowLong(getcontrolhandle(win_main,IDT_CONTROL), GWL_WNDPROC, &MyTabProc))
tcSetSelectedTab(win_main,IDT_CONTROL,0)
InvalidateRect(getcontrolhandle(win_main,IDT_CONTROL), NULL, FALSE)

waituntil run=0
closewindow win_main
end

sub mainwindow
select @CLASS
case @IDCREATE
CENTERWINDOW #<WINDOW>@HITWINDOW
case @IDCLOSEWINDOW
run = 0
case @IDCONTROL
SELECT @CONTROLID
case IDT_CONTROL
move win_main,0,205
temp=tcGetSelectedTab(win_main,IDT_CONTROL)
print win_main,USING("& # &","Tab#",temp+1,"was selected..")
case 1
ENABLECONTROL win_main,IDT_CONTROL, 1
case 2
ENABLECONTROL win_main,IDT_CONTROL, 0
endselect
endselect
return
ENDSUB



sub MyTabProc(int hwnd,UINT uMsg,int wParam,int lParam),int
int proc
UINT hDC,hbr,obrush,tmppen,oldpen
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


Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Create the control as initially hidden.

TabControl win_main,0,4,2000,24,@BORDER|@TABSTOP|@TCS_OWNERDRAWFIXED|@TCS_FLATBUTTONS|@SYSMENU  ,0,IDT_CONTROL
..subclass etc
ShowWindow win_main, @SWSHOW, IDT_CONTROL

@SYSMENU means @HIDDEN for controls.  Yes I know, its an undocumented quirk, but it works.  A long time ago, in a different galaxy, I had added the ability to initially hide the control and reused the constant for sysmenu since controls don't have icon menus. 

Paul.

Ionic Wind Support Team