May 13, 2024, 10:15:01 AM

News:

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


Treeview images

Started by aurelCB, June 02, 2011, 01:24:15 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aurelCB

Hi...
I know that i must use this api-s if i want use images in treview control:
'for treeview imaages
DECLARE IMPORT, CreateImageList ALIAS ImageList_Create(MinCx AS INT,MinCy AS INT,flags AS INT,cInitial AS INT,cGrow AS INT),INT
DECLARE IMPORT, AddIconImgList ALIAS ImageList_AddIcon(himl AS INT,hIcon AS INT),INT
DECLARE IMPORT, _ImageList_GetIcon ALIAS ImageList_GetIcon(HIMAGELIST AS INT,ImgIndex AS INT,hbmMask AS POINTER),INT
DECLARE IMPORT, _ImageList_Draw ALIAS ImageList_Draw(HIMAGELIST AS INT,ImgIndex AS INT,hDCDest AS INT,xDest AS INT,yDest AS INT,lStyle AS INT),INT
DECLARE IMPORT, _ImageList_Destroy ALIAS ImageList_Destroy(himl AS INT),INT


But if i understand correctly i must use Icon instead of BMP?
And if i use icon do i must delete image on end of program?
Or maby is somewhere better and quicker option..?
thanks advance...

Aurel

LarryMc

Aurel
Did you look at these twp for ideas?
http://www.ionicwind.com/forums/index.php?topic=2606.msg22160#msg22160
http://www.ionicwind.com/forums/index.php?topic=1336.msg12573#msg12573
Here's something I played with ( I wasn't the original author)
$include "windowssdk.inc"
$include "commctrl.inc"
autodefine "off"
WINDOW d1
OpenWindow d1,0,0,295,230,@caption,d1,"Advanced TreeView demo",&handler
CONTROL d1,@TREEVIEW,"Static",18,3,252,188,0x50800027|TVS_CHECKBOXES,1
UINT TreeBkColor, TvLastHitItems
UINT TVhwnd         :' handle to tree
UINT hImageList     :' handle to imagelist
UINT handle[15]     :' item handles
TVhwnd = GetDlgItem(d1.hwnd, 1)
AddItems()
TreeBkColor = rgb(210,210,210)
SetWindowColor d1, TreeBkColor
SendMessage d1, TVM_SETINDENT, 8, 0, 1
SendMessageA(TVhwnd, TVM_SETBKCOLOR, 0, TreeBkColor)
SendMessageA(TVhwnd, TVM_SETLINECOLOR, 0, 0)
SendMessageA(TVhwnd, TVM_SETTEXTCOLOR, 0, 0x0000FF)
SendMessageA(TVhwnd, TVM_SETITEMHEIGHT, 40, 0)
'messagebox 0, hex$(TreeView_GetTextColor(TVhwnd)), ""
While hImageList=0
   'hImageList = ImageList_LoadImage(0, GetStartPath+"tree.bmp", 10/*each image size*/, 2/*images*/, 0x808080/*color mask*/, IMAGE_BITMAP, LR_LOADFROMFILE|LR_LOADTRANSPARENT)
   hImageList = ImageList_LoadImage(0, GetStartPath+"0025.bmp", 80/*each image size*/, 1/*images*/, 0x000000/*color mask*/, IMAGE_BITMAP, LR_LOADFROMFILE|LR_LOADTRANSPARENT)

   IF hImageList = 0
      IF URLDownloadToFileA(0, "http://people.freenet.de/ibasic/tree.bmp", GetStartPath+"tree.bmp", 0, 0)
         hImageList=1
      Endif
   Endif
Wend
starttimer d1, 500
'SendMessageA(TVhwnd, TVM_SETIMAGELIST, TVSIL_NORMAL, hImageList)
SendMessageA(TVhwnd, TVM_SETIMAGELIST, TVSIL_STATE, hImageList)
'TreeView_Collapse(TVhwnd, handle[0])
TreeView_SetCheckState(TVhwnd, handle[0], 1)
TreeView_SetCheckState(TVhwnd, handle[1], 1)
TreeView_SetCheckState(TVhwnd, handle[2], 1)
TreeView_SetCheckState(TVhwnd, handle[3], 1)
TreeView_SetCheckState(TVhwnd, handle[4], 1)
TreeView_SetCheckState(TVhwnd, handle[5], 1)
TreeView_SetItemState(TVhwnd, handle[0], TVIS_BOLD, TVIS_BOLD)
TreeView_SetItemState(TVhwnd, handle[1], TVIS_BOLD, TVIS_BOLD)
TreeView_SetItemState(TVhwnd, handle[2], TVIS_BOLD, TVIS_BOLD)
TreeView_SetItemState(TVhwnd, handle[3], TVIS_BOLD, TVIS_BOLD)
TreeView_SetItemState(TVhwnd, handle[4], TVIS_BOLD, TVIS_BOLD)
TreeView_SetItemState(TVhwnd, handle[5], TVIS_BOLD, TVIS_BOLD)
WaitUntil d1.hwnd=0
ImageList_Destroy(hImageList)

sub TreeView_SetItemState(HWND hwndTV,HTREEITEM hItem,UINT state,UINT stateMask),UINT
TVITEM tvi
tvi.mask = TVIF_STATE
tvi.hItem = hItem
tvi.state = state
tvi.stateMask = stateMask
return SendMessageA(hwndTV, TVM_SETITEM, 0, &tvi)
endsub

sub TreeView_SetCheckState(HWND hwndTV,HTREEITEM hItem,BOOL fCheck),UINT
'return TreeView_SetItemState(hwndTV, hItem, INDEXTOSTATEIMAGEMASK(IIF(fCheck,2,1)), TVIS_STATEIMAGEMASK)
return TreeView_SetItemState(hwndTV, hItem, INDEXTOSTATEIMAGEMASK(IIF(fCheck,1,1)), TVIS_STATEIMAGEMASK)

endsub

sub TreeView_GetCheckState(HWND hwndTV, HTREEITEM hItem),UINT
return (SendMessageA(hwndTV, TVM_GETITEMSTATE, hItem, TVIS_STATEIMAGEMASK) >> 12) -1
endsub

'-------------------------
Sub handler
   POINT pt
   Select @message
      Case @idcreate
         CenterWindow d1
      Case @idtimer
         setcaption d1, "item [0] checked: "+str$(TreeView_GetCheckState(TVhwnd, handle[0]))
      Case @IDCLOSEWINDOW
         CloseWindow d1
      Case @IDCONTROL
         Select @CONTROLID
            Case 1
               Select @NOTIFYCODE

                  case @nmrclick
                     GetCursorPos(&pt)
                     ScreenToCLient(d1.hwnd, &pt)
                     contextmenu d1, pt.x, pt.y
                     menuitem "nix! :)", 0, 1000
                     endmenu
               EndSelect
         EndSelect
   EndSelect
   Return
EndSub
'-------------------------


'-------------------------

'-------------------------
Sub AddItems
'   UINT handle[9]
   handle[0] = tvInsertItem(d1, 1, "root item 1", 0)
   handle[1] = tvInsertItem(d1, 1, "root item 2", 0)
   handle[2] = tvInsertItem(d1, 1, "root item 3", 0)
   handle[3] = tvInsertItem(d1, 1, "root item 4", 0)
   handle[4] = tvInsertItem(d1, 1, "root item 5", 0)
   handle[5] = tvInsertItem(d1, 1, "root item 6", 0)

  ' SendMessageA(TVhwnd, TVM_EXPAND, TVE_EXPAND, handle[0])
   'SendMessageA(TVhwnd, TVM_EXPAND, TVE_EXPAND, handle[1])
   'SendMessageA(TVhwnd, TVM_EXPAND, TVE_EXPAND, handle[2])
   Return
EndSub


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

aurelCB

Hi Larry....
Yes i look into every posibile treeview example which i found on forum
and search trough google for examples,there is also one example from DLib
which is simpliest but i cannot figured how work becose use little bit weird
shape of syntax with Poke ::)
Thank you ,i must study this more , i think that Tab control is complex but
treeview looks like a nightmare... :-\

Aurel
   

aurelCB

Huh..i try this but i constantly recive error that i dont have defined tvhendle?
'
' tv-images

DECLARE IMPORT,SHBrowseForFolder(param1:UINT),INT
DECLARE IMPORT,SHGetPathFromIDList(param1:UINT, param2:UINT),INT
DECLARE IMPORT,CoTaskMemFree(param1:INT),INT
DECLARE IMPORT,ZeroMemory Alias RtlZeroMemory(dat:INT,length:INT),INT
DECLARE IMPORT,SendMessageA(hWnd:UINT, message:UINT, wParam:INT, lparam:UINT),UINT



CONST WM_USER = 0x400
CONST BFFM_SETSELECTION = WM_USER + 102
CONST BFFM_INITIALIZED = 1
CONST BFFM_VALIDATEFAILED = 3
CONST BIF_RETURNFSANCESTORS = 8
CONST BIF_RETURNONLYFSDIRS = 1
CONST BIF_NEWDIALOGSTYLE = 0x40
CONST BIF_DONTGOBELOWDOMAIN = 2

CONST TView = 100
CONST Max_Path = 260

CONST TV_FIRST = 0x1100
CONST TVS_CHECKBOXES = 0x100
CONST TVM_SETBKCOLOR = (TV_FIRST + 29)
CONST TVM_SETLINECOLOR = (TV_FIRST + 40)
CONST TVM_SETTEXTCOLOR = (TV_FIRST + 30)
CONST TVM_SETITEMA = (TV_FIRST + 13)
Const TVM_INSERTITEMW = (TV_FIRST + 50)
'Region TreeViewImageListFlags
Const TVSIL_NORMAL = 0
Const TVSIL_STATE = 2

'Region TreeViewItem Flags
Const TVIF_NONE = 0x0000
Const TVIF_TEXT = 0x0001
Const TVIF_IMAGE = 0x0002
Const TVIF_PARAM = 0x0004
Const TVIF_STATE = 0x0008
Const TVIF_HANDLE = 0x0010
Const TVIF_SELECTEDIMAGE = 0x0020
Const TVIF_CHILDREN = 0x0040
Const TVIF_INTEGRAL = 0x0080
Const I_CHILDRENCALLBACK = -1
Const LPSTR_TEXTCALLBACK = -1
Const ILC_MASK = 0x0001
Const ILC_COLOR = 0x0000
Const ILC_COLORDDB = 0x00FE

TYPE TV_ITEM
    UINT       mask
    UINT     hItem
    UINT       state
    UINT       stateMask
    POINTER    pszText
    int        cchTextMax
    int        iImage
    int        iSelectedImage
    int        cParent
    UINT       lParam
ENDTYPE

INT tvControl
DEF w1:WINDOW
OPENWINDOW w1,0,0,400,300,@minbox,0,"Treeview",&main
SETWINDOWCOLOR w1,RGB(220,220,230)
'tv_create
tvControl=CONTROLEX w1,"SysTreeView32","",4,40,236,200,@BORDER,@EXCLIENTEDGE,1
'load icon
INT sIcon
sIcon=LOADIMAGE(getstartpath+"subico.ico", @imgicon)
'add_item
AddTreeViewItem(tvControl,0,"Item 1",sIcon,0)

'-----------------------------
waituntil w1=0
end
'------------------------------
SUB main
SELECT  @CLASS
CASE @IDCLOSEWINDOW
CLOSEWINDOW w1

CASE @IDCREATE
CENTERWINDOW w1

ENDSELECT

RETURN
ENDSUB
'function add_item
'AddTreeViewItem(_tvhandle,_tvpos,_tvstring.s,_tvicon,_tvselect)
SUB AddTreeViewItem(tvhandle:INT,tvpos:INT,tvstring:STRING,tvicon:INT,tvselect:INT),INT
/*TYPE TV_ITEM
    UINT       mask
    UINT     hItem
    UINT       state
    UINT       stateMask
    POINTER    pszText
    int        cchTextMax
    int        iImage
    int        iSelectedImage
    int        cParent
    UINT       lParam
ENDTYPE */

TV_ITEM tvi
'ZeroMemory(tvi,LEN(TV_ITEM))
tvi.cParent = 0
tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE
tvi.pszText = tvstring
tvi.stateMask = 0
tvi.hitem = tvpos
    tvi.iImage = tvicon
tvi.iSelectedImage = 0
RETURN SendMessage(tvhendle,TVM_INSERTITEMW,0,&tvi)

ENDSUB

LarryMc

 :D :D
That's because you don't have tvhendle defined.
But you do have tvhandle defined.

SUB AddTreeViewItem(tvhandle:INT,tvpos:INT,tvstring:STRING,tvicon:INT,tvselect:INT),INT

It's only old people like me that should have problems like that. ;D
You're way too young to have 'Senior Moments'. ;D ;D

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

aurelCB

 ;D
No that is becose english is not my native languge and i mix up some things ..

LarryMc

I know, that's why I was teasing you.

I think you, Sapero, and others who speak 2 or more languages do quite well.
Most times ya'll do better than I do!!

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

aurelCB

I know ... >:(   .... ;)
However Larry i found one great piece of code for treeview with bitmaps
on CodingMonkeys by King64.Works great.. :)
by the way i also found few examples on Purebasic forum which i dont know
how to convert properly :-\ .This examples use icons with 16 colors...

Aurel

Brian

Aurel,

I also had the treeview and other stuff from King64. I've modified them for IWB2, and
posted them here in a zip file. Unzip the whole folder into your projects folder.
Then make sure you copy kpx.incc to the iwbdev\bin folder, and kpx.lib to the
iwbdev\libs folder.

You can also copy the help file, if you wish, to the iwbdev\help folder

They work for me. Best of luck,

Brian