English
Source / code snippets

TabControl with "neu"-tab and "Schließen-X"

 

Jens-Arne
Reumschüssel
here How promised (see  [...]  ) the View source for TabControl with "neu"-tab and "Schließen-X" on the Tabs. everything in reinem XProfanX4 written.

'TabControl with "new"-tab and "Closing-X"

$H windows.ph
$H messages.ph
$H commctrl.ph

STRUCT S_RECT=left&,top&,right&,bottom&
STRUCT S_DRAWITEMSTRUCT=CtlType&,CtlID&,itemID&,itemAction&,itemState&,hwndItem&,hDC&,rcX1&,rcY1&,rcX2&,rcY2&,itemData&
STRUCT S_TCITEM=mask&,dwState&,dwStateMask&,pszText&,cchTextMax&,iImage&,lParam&

declare _hTC%,_hIL%,_hBMP%,_hWhiteBrush%,_hIclose%,_ende%,_MaxTab%,_TabNr%

SUBCLASSPROC
declare dis#,rect#,tcitem#,b#,t$,mx%,my%,i%,o%
if &sWnd=%HWnd
'{ 'Closing-X on Tabs malen
if %sMessage=~WM_DRAWITEM
dim dis#,S_DRAWITEMSTRUCT
dis#=&slParam
if dis#.hwndItem&=_hTC%
dim rect#,S_RECT
dim tcitem#,S_TCITEM
rect#.left&=dis#.rcX1&+~GetSystemMetrics(~SM_CXEDGE)
rect#.top&=dis#.rcY1&+~GetSystemMetrics(~SM_CYEDGE)
rect#.right&=dis#.rcX2&-~GetSystemMetrics(~SM_CXEDGE)
rect#.bottom&=dis#.rcY2&
tcitem#.mask&=~TCIF_TEXT | ~TCIF_STATE
tcitem#.dwStateMask&=$FFFFFFFF
dim b#,1000
tcitem#.psztext&=b#
tcitem#.cchtextmax&=1000
@sendmessage(_hTC%,~TCM_GETITEMA,dis#.itemID&,tcitem#)
if TCITEM#.dwstate&=1
~FillRect(dis#.hDC&,rect#,_hWhiteBrush%)
~SetBkMode(dis#.hDC&,~TRANSPARENT)
rect#.left&=rect#.left&+4
rect#.top&=rect#.top&+2
endif
t$=@string$(b#,0)
dispose b#
'~selectobject(DIS#.hDC&,_hTabFont)
~drawtext(dis#.hDC&,@addr(t$),-1,rect#,~DT_LEFT | ~DT_SINGLELINE)
if tcitem#.dwstate&<>1
rect#.right&=rect#.right&+4
endif
if t$<>" *new"
~DrawIconEx(dis#.hDC&,rect#.right&-16-2,rect#.top&,_hIclose%,16,16,0,0,~DI_IMAGE | ~DI_MASK)
endif
dispose rect#,tcitem#
endif
dispose dis#
endif
'}
elseif &sWnd=_hTC%
'{ 'Closing-X or "*new"-tab klicked
if %smessage=~WM_LBUTTONDOWN
mx%=@mouseabsx()
my%=@mouseabsy()
dim rect#,S_RECT
for i%,0,_MaxTab%-1
@sendmessage(_hTC%,~TCM_GETITEMRECT,i%,rect#)
if i%<_MaxTab%-1
if (mx%>=rect#.right&-16-2+@GetAbsWindowPosX1(_hTC%)) and (mx%<=rect#.right&+@GetAbsWindowPosX1(_hTC%)) and (my%>=rect#.top&+@GetAbsWindowPosY1(_hTC%)) and (my%<=rect#.top&+16+@GetAbsWindowPosY1(_hTC%))
@sendmessage(_hTC%,~TCM_DELETEITEM,i%,0)
dec _MaxTab%
'for o%,0,_MaxTab%-2
' settext _hTC%,o%,"tab "+@st$(o%+1)+" "
'endfor 'o%
break
endif
else
if (mx%>=rect#.left&+@GetAbsWindowPosX1(_hTC%)) and (mx%<=rect#.right&+@GetAbsWindowPosX1(_hTC%)) and (my%>=rect#.top&+@GetAbsWindowPosY1(_hTC%)) and (my%<=rect#.bottom&+@GetAbsWindowPosY2(_hTC%))
inc _TabNr%
inserttab(_hTC%,_MaxTab%-1,"tab "+@st$(_TabNr%)+" ")
inc _MaxTab%
break
endif
endif
endfor 'i%
dispose rect#
endif
'}
endif
ENDPROC 'SUBCLASSPROC

'{ 'Hilfsfunktionen
PROC MouseAbsX
Declare Point#,XX&
Dim Point#,8
@external("user32.dll","GetCursorPos",Point#)
XX&=@long(Point#,0)
Dispose Point#
Return XX&
ENDPROC 'MouseAbsX
PROC MouseAbsY
Declare Point#,YY&
Dim Point#,8
@external("user32.dll","GetCursorPos",Point#)
YY&=@long(Point#,4)
Dispose Point#
Return YY&
ENDPROC 'MouseAbsY
PROC GetAbsWindowPosX1
parameters hW&
declare b#,ret&
dim b#,4*4
@external("user32.dll","GetWindowRect",hW&,b#)
ret&=@long(b#,0)
dispose b#
return ret&
ENDPROC 'GetAbsWindowPosX1
PROC GetAbsWindowPosY1
parameters hW&
declare b#,ret&
dim b#,4*4
@external("user32.dll","GetWindowRect",hW&,b#)
ret&=@long(b#,4)
dispose b#
return ret&
ENDPROC 'GetAbsWindowPosY1
PROC GetAbsWindowPosX2
'it'll The absolute position determined! for wide/Höhe GetWindowSpan use!
parameters hW&
declare b#,ret&
dim b#,4*4
@external("user32.dll","GetWindowRect",hW&,b#)
ret&=@long(b#,8)
dispose b#
return ret&
ENDPROC 'GetAbsWindowPosX2
PROC GetAbsWindowPosY2
'it'll The absolute position determined! for wide/Höhe GetWindowSpan use!
parameters hW&
declare b#,ret&
dim b#,4*4
@external("user32.dll","GetWindowRect",hW&,b#)
ret&=@long(b#,12)
dispose b#
return ret&
ENDPROC 'GetAbsWindowPosY2
'}


'Hauptprogramm:
cls
usermessages $10
_hWhiteBrush%=~CreateSolidBrush(@rgb(255,255,255))
_hBMP%=Create("HPIC",0,"TOOLBAR")
_hIL%=@Create("IMAGELIST",16,16,_hBMP%,@rgb(192,192,192))
_hIclose%=~ImageList_GetIcon(_hIL%,10,~ILD_NORMAL)
deleteobject _hBMP%
_hTC%=@Create("TABCTRL",%HWnd,_hIL%,0,0,@width(%HWnd),24)
setstyle _hTC%,@getstyle(_hTC%) | ~TCS_OWNERDRAWFIXED
@set("FASTMODE",1)
subclass %HWnd,1
subclass _hTC%,1
inserttab(_hTC%,1,"tab 1 ") 'three Spaces right, so the Closing-X-Icon hineinpasst
inserttab(_hTC%,1,"tab 2 ")
inserttab(_hTC%,2," *new")
waitinput 1 'TabControl 1x Show
@set("FASTMODE",0) 'Fastmode can now again off go
_MaxTab%=3
_TabNr%=2
while _ende%=0
waitinput
if (%uMessage=$10) or ((~GetForegroundWindow()=%HWnd) and @iskey(27))
while @iskey(27)
sleep 25
endwhile
_ende%=1
endif
endwhile
subclass _hTC%,0
subclass %HWnd,0
deleteobject _hIL%
deleteobject _hWhiteBrush%
deleteobject _hIclose%
usermessages 0
end

Greeting, Jens-Arne
 
XProfan X4 * Prf2Cpp * XPSE * JRPC3 * Win11 Pro 64bit * PC i7-7700K@4,2GHz, 32 GB RAM
PM: jreumsc@web.de
09/18/22  
 




RudiB.
this is Yes pointed....correctly. well !!! only one have I fixes.
at that delete one Tabs, ought to there not too very z.B. tab3 deleted go, and not always the lastly begot tab.
have time 10 Tabs created and tab1 delete want. To to that bitteren end stayed tab1.
or should the so his ?
but otherwise genial....can too slight alter. I werd something try.
Greeting from munich
Rudi
 
XProfan X4
Xprofan X4
Rudolf Beske / München

Hardware: NB Intel I9 - 16GByte RAM
09/18/22  
 




Jens-Arne
Reumschüssel
Yes, the ought to for the example objectively so his. But if I me the now right consider, is the naturally in the doing balderdash. I have the example therefore adjusted. now stay The Beizeichnungen the Tabs receive, if one a deletes.

Greeting, Jens-Arne
 
XProfan X4
XProfan X4 * Prf2Cpp * XPSE * JRPC3 * Win11 Pro 64bit * PC i7-7700K@4,2GHz, 32 GB RAM
PM: jreumsc@web.de
09/19/22  
 




Sven
Bader
thanks for tollen code! Sowohl Redraw as well as Mausposition are so really fummelig but it shining the only lane To his. for my needs has one Multiplikationszeichen × to that close gereicht, and so I me at least whom Ownder-Draw save can. with Stukturen instead of Hilfsfunktionen is it yet something kürzer become.

Who need can here my angepasster code.

greetings

Sven
'TabControl with "neu"-tab and "Schließen-X"
 $H windows.ph
 $H messages.ph
 $H commctrl.ph
STRUCT S_RECT      = left&,top&,right&,bottom&
STRUCT S_TABRECT   = x1&,y1&,x2&,y2&
STRUCT S_MOUSE     = mx&,my&
declare tabcontrol&,_hIL%,_ende%,_MaxTab%,_TabNr%, hFont%

SUBCLASSPROC

    declare rect#,i%,o%,tabrect#,mouse#

    If SubClassMessage(Tabcontrol&, ~WM_LBUTTONDOWN)

        '{ 'Closing-X or "*neu"-tab klicked
        dim rect#,S_RECT
        dim mouse#,S_MOUSE
        dim tabrect#,S_TABRECT
        external("user32.dll","GetCursorPos",mouse#)
        external("user32.dll","GetWindowRect",Tabcontrol&,tabrect#)
        for i%,0,_MaxTab%-1
        sendmessage(Tabcontrol&,~TCM_GETITEMRECT,i%,rect#)

        if i%<_MaxTab%-1

            if (mouse#.mx&>=rect#.right&-16-2+tabrect#.x1&) and (mouse#.mx&<=rect#.right&+tabrect#.x1&) and (mouse#.my&>=rect#.top&+tabrect#.y1&) and (mouse#.my&<=rect#.top&+16+tabrect#.y1&)

                sendmessage(Tabcontrol&,~TCM_DELETEITEM,i%,0)
                dec _MaxTab%
                break

            endif

        else

            if (mouse#.mx&>=rect#.left&+tabrect#.x1&) and (mouse#.mx&<=rect#.right&+tabrect#.x1&) and (mouse#.my&>=rect#.top&+tabrect#.y1&) and (mouse#.my&<=rect#.bottom&+tabrect#.x2&)

                inc _TabNr%
                inserttab(Tabcontrol&,_MaxTab%-1,"Tab "+st$(_TabNr%)+"  × ")
                inc _MaxTab%
                break

            endif

        endif

        endfor'i%
        dispose rect#, mouse#, tabrect#
        '}

    endif

ENDPROC'SUBCLASSPROC

'Hauptprogramm:
cls
hFont% = Create("Font","segoe ui",16,0,0,0,0)
SetDialogFont  hFont%
usermessages $10
Tabcontrol&=Create("TABCTRL",%HWnd,_hIL%,0,0,width(%HWnd),24)
subclass Tabcontrol&,1
set("FASTMODE",1)
inserttab(Tabcontrol&,1,"Tab 1  × ")'three Spaces right, so the Closing-X-Icon hineinpasst
inserttab(Tabcontrol&,1,"Tab 2  × ")
inserttab(Tabcontrol&,2,"  *neu")
waitinput 1'TabControl 1x Show
set("FASTMODE",0)'Fastmode can now again off go
_MaxTab%=3
_TabNr%=2

while _ende%=0

    waitinput

    if (%uMessage=$10) or ((~GetForegroundWindow()=%HWnd) and iskey(27))

        while iskey(27)

            sleep 25

        endwhile

        _ende%=1

    endif

endwhile

subclass Tabcontrol&,0
usermessages 0
end

so see it then in the finished Program from:


78 kB
Hochgeladen:03/14/23
Downloadcounter60
Download
 
03/14/23  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

2.604 Views

Themeninformationen



Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie