Author Topic: Gettabtext problem  (Read 3779 times)

0 Members and 1 Guest are viewing this topic.

Aurel

  • Guest
Gettabtext problem
« on: June 27, 2013, 10:05:47 AM »
Hi all... :)
To avoid stupid and useless chalenges on bp.org back to real stuff...
Anyone maybe have a idea what is wrong with function where i need to get tab control text.
I create function which SetTabtext and who work fine but GettabText wont return string(text)
-caption of tab...
any help is welcome.. ;)

this functions work:
Code: [Select]
Function SetTabControl(byval _tbhwnd as INT,byval _tx as INT,byval _ty as INT,byval _tw as INT,byval _th as INT,byval _tbflag as INT,byval _ex as INT,byval cID as INT) As INT
INT _hfont
  If _tbflag=0
    _tbflag=WS_CHILD | WS_VISIBLE|_tbflag
  End If
 
  hTabControl = CreateWindowEx(_ex,"SysTabControl32","",_tbflag,_tx,_ty,_tw,_th,_tbhwnd,cID,0,0)
 _hfont = GetStockObject(17)
 SendMessage hTabControl,WM_SETFONT,_hfont,0
  UpdateWindow _tbhwnd
Function = hTabControl
End Function
'=====================================================================================
'AddTab
Function AddTab (hwnd as INT ,tbpos as INT,tbtext as String ) as INT
TC_ITEM tie
tie.mask=1
tie.pszText= strptr(tbtext)
tie.cchTextMax=Len(tbtext)
tie.iImage = -1
SendMessage(hWnd,0x1307,tbpos,&tie)

End Function
'=====================================================================================
Function SetTabText (cntID as INT,tbIndex as INT,tabText as String)
TC_ITEM tie
tie.mask=1
tie.pszText= strptr(tabText)
tie.cchTextMax=Len(tabtext)
tie.iImage = -1
SendMessage(cntID,TCM_SETITEM,tbIndex,&tie)
Return
End Function

'=====================================================================================

Function GetSelectedTab (cntID as INT) as INT
INT tbIndex
tbIndex = Sendmessage (cntID,TCM_GETCURSEL,0,0)

Return tbIndex
End Function

but this one not:
Code: [Select]
Function GetTabText (cntID as INT,tbIndex as INT) as string
char tabText[100]
TC_ITEM tie
tie.mask=1

tabtext=Sendmessage (cntID,WM_GETTEXT,tbIndex,&tie.psztext)
Return tabText
End Function

I have search trough all possible exemples i found on net and nothing work... ???

JRS

  • Guest
Re: Gettabtext problem
« Reply #1 on: June 27, 2013, 10:26:34 AM »
Quote
To avoid stupid and useless chalenges on bp.org back to real stuff...

Tomaaz has taken the baton and running full speed.  ::)

Sorry, I have nothing to offer to resolve your issues.

 

Aurel

  • Guest
Re: Gettabtext problem
« Reply #2 on: June 27, 2013, 10:58:57 AM »
Ok John ...i see ,he is just a lonely freak :D
Maybe Charles know where to look... ;)

JRS

  • Guest
Re: Gettabtext problem
« Reply #3 on: June 27, 2013, 11:24:02 AM »
Quote
Ok John ...i see ,he is just a lonely freak

No, I don't think so. He was just filling in.  :-*

Charles Pegge

  • Guest

Aurel

  • Guest
Re: Gettabtext problem
« Reply #5 on: June 27, 2013, 12:56:31 PM »
sorry Charles but i don't have acces to msdn ( because of some unknown reason--our  wifi network).
Maybe is something useful on joseRoca site  ???

Aurel

  • Guest
Re: Gettabtext problem
« Reply #6 on: June 27, 2013, 01:26:10 PM »
hmm..i have found this on JRoca forum:
Code: [Select]
LOCAL szTabTxt  AS ASCIIZ * 256

   nTab = SendMessage(ghTabMdi, %TCM_GETITEMCOUNT, 0, 0)
   FOR idx = 0 TO nTab - 1
      ' Get tab item text string
      ttc_item.mask       = %TCIF_TEXT
      ttc_item.pszText    = VARPTR(szTabTxt)
      ttc_item.cchTextMax = SIZEOF(szTabTxt)
      SendMessage ghTabMdi, %TCM_GETITEM, idx, BYVAL VARPTR(ttc_item)

so i do this in oxygen...

Code: [Select]
Function GetTabText (byval cntID as int,byval tabIndex as int) as string
string tabText
TC_ITEM tie
tie.mask=1
tie.pszText = strptr (tabText)
tie.cchTextMax = sizeOf(tabText)
SendMessage(cntID,TCM_GETITEM,tabIndex,&tie)

print "TAB_TEXT:" + tabText
Return tabtext
End Function

And not work ,string is not recieved  ???
How is this posssible? do i must use maybe something else than string ?

Aurel

  • Guest
Re: Gettabtext problem
« Reply #7 on: June 27, 2013, 01:36:46 PM »
I also try this to:
Code: [Select]
Function GetTabText ( cntID as int, tabIndex as int) as string
zstring tabText[256]
TC_ITEM tie
tie.mask=1
tie.pszText = strptr tabText
tie.cchTextMax = LEN(tabText)
SendMessage(cntID,TCM_GETITEM,tabIndex,&tie)

print "TAB_TEXT:" + tabText
Return tabtext
End Function

and still nothing ???

Aurel

  • Guest
Re: Gettabtext problem
« Reply #8 on: June 27, 2013, 01:45:05 PM »
I even try with asciiz:
Code: [Select]
Function GetTabText ( cntID as int, tabIndex as int) as char
dim tabText as asciiz * 256
TC_ITEM tie
tie.mask=1
tie.pszText = strptr tabText
tie.cchTextMax = LEN(tabText)
SendMessage(cntID,TCM_GETITEM,tabIndex,&tie)

'print "TAB_TEXT:" + tabText
Return tabtext
End Function

And again nothing...i simply don't get it what might be wrong ::)

Charles Pegge

  • Guest
Re: Gettabtext problem
« Reply #9 on: June 28, 2013, 12:09:32 AM »
Hi Aurel

Taking the Jose snippet:

PB / Jose:

LOCAL szTabTxt  AS ASCIIZ * 256

   nTab = SendMessage(ghTabMdi, %TCM_GETITEMCOUNT, 0, 0)
   FOR idx = 0 TO nTab - 1
      ' Get tab item text string
      ttc_item.mask       = %TCIF_TEXT
      ttc_item.pszText    = VARPTR(szTabTxt)
      ttc_item.cchTextMax = SIZEOF(szTabTxt)
      SendMessage ghTabMdi, %TCM_GETITEM, idx, BYVAL VARPTR(ttc_item)
      ...


Oxygen

LOCAL szTabTxt  AS ASCIIZ * 256

   nTab = SendMessage(ghTabMdi, %TCM_GETITEMCOUNT, 0, 0)
   indexbase 0
   FOR idx = 0 TO nTab - 1
      ' Get tab item text string
      ttc_item.mask       = %TCIF_TEXT
      ttc_item.pszText    = strptr(szTabTxt)
      ttc_item.cchTextMax = 256 'buffer size
      SendMessage ghTabMdi, %TCM_GETITEM, idx, & ttc_item)
      ...


I think its the buffersize you need. (256)
« Last Edit: June 28, 2013, 12:18:03 AM by Charles Pegge »

Aurel

  • Guest
Re: Gettabtext problem
« Reply #10 on: June 28, 2013, 02:19:35 AM »
YES...it work...
But how then not work with sizeOf or with LEN
PowerBasic use sizeOf like many C or similar examples  ???
Ok oxygen need number...good to know  ;)

Thank you Charles!
Without this i simply cannot continue work on tab control for AsciEditor..
because i must know what text is on tab
so now function look like this:
Code: [Select]
Function GetTabText ( cntID as int, tabIndex as int) as string
dim tbText as asciiz * 256
TC_ITEM tie
tie.mask=1
tie.pszText = strptr tbText
tie.cchTextMax = 256
SendMessage(cntID,TCM_GETITEM,tabIndex,&tie)

'print "TAB_TEXT:" + tabText
Return tbtext
End Function

Charles Pegge

  • Guest
Re: Gettabtext problem
« Reply #11 on: June 28, 2013, 02:38:47 AM »
You can use spanof

dim s as asciiz*256
print sizeof s  '=1
print spanof s '=256


Aurel

  • Guest
Re: Gettabtext problem
« Reply #12 on: June 28, 2013, 01:41:13 PM »
aha i see... ;)
also work with
string tabtext=space(256)
tabtext[256] as zstring
char tabtext[256]

 :)
« Last Edit: June 28, 2013, 08:34:47 PM by Aurel »