Announcement

Collapse
No announcement yet.

Repeated Question (Treeview Macros)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • LRantanen
    Guest replied
    Greg,

    thanks for the link. Although I'm not quite certain we are addressing the same issue - it might be so.

    I was already starting to think that I have finally lost my mind and chasing ghosts getting ready to head to a funny farm. I had tried to write a small program to demonstrate the matter and could not reproduce the problem. Everything seemed to work like expected.

    Then reading thru the thread you mentioned, it hit me: earlier I used GLOBAL variables and in my demostration program LOCALs. Back to PB/DLL and yes - there seems to be a difference between these two scopes. Globals do what I have tried to describe earlier, locals don't.

    I have attached a small program which demonstrates my point.

    Lasse Rantanen
    [email protected]

    Code:
    #COMPILE EXE
    $INCLUDE "WIN32API.INC"
     
    %IDL_CONSTANT   = 1000
    %IDL_LONG       = 1001
    %IDL_DWORD      = 1002
    %IDL_DWORDLONG  = 1003
    %IDL_LONG1      = 1004
    %IDL_DWORD1     = 1005
    %IDL_DWORDLONG1 = 1006
     
    %TVI_ROOT_DW1   = &HFFFF0000???
    %TVI_ROOT_DW2   = &H0FFFF0000
    %TVI_ROOT_L1    = &HFFFF0000
    %TVI_ROOT_L2    = &HFFFF0000&
     
    GLOBAL hDlg     AS LONG
    GLOBAL dwTest1  AS DWORD
    GLOBAL lTest1   AS LONG
     
    '------------------------------------------------------------------------------
    SUB SetLabels(iConst AS INTEGER)
     
        LOCAL dwTest   AS DWORD
        LOCAL lTest    AS LONG
        LOCAL sBits    AS STRING
        LOCAL i        AS INTEGER
     
        SELECT CASE iConst
            CASE 1
                dwTest = %TVI_ROOT_DW1
                lTest = %TVI_ROOT_DW1
                dwTest1 = %TVI_ROOT_DW1
                lTest1 = %TVI_ROOT_DW1
                CONTROL SET TEXT hDlg,%IDL_CONSTANT, "Define %TVI_ROOT = &HFFFF0000??? "
            CASE 2
                dwTest = %TVI_ROOT_DW2
                lTest = %TVI_ROOT_DW2
                dwTest1 = %TVI_ROOT_DW2
                lTest1 = %TVI_ROOT_DW2
                CONTROL SET TEXT hDlg,%IDL_CONSTANT, "Define %TVI_ROOT = &H0FFFF0000 "
            CASE 3
                dwTest = %TVI_ROOT_L1
                lTest = %TVI_ROOT_L1
                dwTest1 = %TVI_ROOT_L1
                lTest1 = %TVI_ROOT_L1
                CONTROL SET TEXT hDlg,%IDL_CONSTANT, "Define %TVI_ROOT = &HFFFF0000 "
            CASE 4
                dwTest = %TVI_ROOT_L2
                lTest = %TVI_ROOT_L2
                dwTest1 = %TVI_ROOT_L2
                lTest1 = %TVI_ROOT_L2
                CONTROL SET TEXT hDlg,%IDL_CONSTANT, "Define %TVI_ROOT = &HFFFF0000& "
        END SELECT
     
        sBits = ""
        FOR i= 31 TO 0 STEP -1
            sBits = sBits + TRIM$(STR$(BIT(lTest,i)))
        NEXT
        CONTROL SET TEXT hDlg, %IDL_LONG, sBits
     
        sBits = ""
        FOR i= 31 TO 0 STEP -1
            sBits = sBits + TRIM$(STR$(BIT(dwTest,i)))
        NEXT
        CONTROL SET TEXT hDlg, %IDL_DWORD, sBits
      
        lTest = dwTest
        sBits = ""
        FOR i= 31 TO 0 STEP -1
            sBits = sBits + TRIM$(STR$(BIT(lTest,i)))
        NEXT
        CONTROL SET TEXT hDlg, %IDL_DWORDLONG, sBits
     
        sBits = ""
        FOR i= 31 TO 0 STEP -1
            sBits = sBits + TRIM$(STR$(BIT(lTest1,i)))
        NEXT
        CONTROL SET TEXT hDlg, %IDL_LONG1, sBits
      
        sBits = ""
        FOR i= 31 TO 0 STEP -1
            sBits = sBits + TRIM$(STR$(BIT(dwTest1,i)))
        NEXT
        CONTROL SET TEXT hDlg, %IDL_DWORD1, sBits
     
        lTest1 = dwTest1
        sBits = ""
        FOR i= 31 TO 0 STEP -1
            sBits = sBits + TRIM$(STR$(BIT(lTest1,i)))
        NEXT
        CONTROL SET TEXT hDlg, %IDL_DWORDLONG1, sBits
    END SUB
     
    '------------------------------------------------------------------------------
     
    CALLBACK FUNCTION AssignDlgProc
     
        STATIC iStep AS INTEGER
     
        SELECT CASE CBMSG
     
            CASE %WM_COMMAND
                SELECT CASE CBCTL
     
                    CASE %IDOK
                        INCR iStep
                        IF iStep > 4 THEN iStep = 1
                        SetLabels iStep
     
                    CASE %IDCANCEL
                        DIALOG END CBHNDL
     
                END SELECT
     
        END SELECT
     
    END FUNCTION
    '------------------------------------------------------------------------------
     
    FUNCTION PBMAIN () AS LONG
     
        $REGISTER NONE
     
    ' ** Create a new dialog template
        DIALOG NEW 0, "Some Numeric Assigments", ,, 320, 190, 0, 0 TO hDlg
     
    ' ** Add controls to it
     
        CONTROL ADD LABEL,  hDlg, %IDL_CONSTANT, "",5,15,310,12, %SS_LEFT
        CONTROL ADD LABEL,  hDlg, -1, "Results with Local Variables",5,30,310,12, %SS_LEFT
     
        CONTROL ADD LABEL,  hDlg, -1, "lTest = %TVI_ROOT : BITS in lTest -> ",5,40,175,12, %SS_LEFT
        CONTROL ADD LABEL,  hDlg, %IDL_LONG, "",180,40,140,12, %SS_LEFT
     
        CONTROL ADD LABEL,  hDlg, -1, "dwTest = %TVI_ROOT : BITS in dwTest -> ",5,55,175,12, %SS_LEFT
        CONTROL ADD LABEL,  hDlg, %IDL_DWORD, "",180,55,140,12, %SS_LEFT
     
        CONTROL ADD LABEL,  hDlg, -1, "dwTest = %TVI_ROOT : lTest = dwTest : BITS in lTest -> ",5,70,175,12, %SS_LEFT
        CONTROL ADD LABEL,  hDlg, %IDL_DWORDLONG, "",180,70,140,12, %SS_LEFT
     
        ' Labels for global case
        CONTROL ADD LABEL,  hDlg, -1, "Results with Global Variables",5,105,310,12, %SS_LEFT
     
        CONTROL ADD LABEL,  hDlg, -1, "lTest = %TVI_ROOT : BITS in lTest -> ",5,115,175,12, %SS_LEFT
        CONTROL ADD LABEL,  hDlg, %IDL_LONG1, "",180,115,140,12, %SS_LEFT
     
        CONTROL ADD LABEL,  hDlg, -1, "dwTest = %TVI_ROOT : BITS in dwTest -> ",5,130,175,12, %SS_LEFT
        CONTROL ADD LABEL,  hDlg, %IDL_DWORD1, "",180,130,140,12, %SS_LEFT
     
        CONTROL ADD LABEL,  hDlg, -1, "dwTest = %TVI_ROOT : lTest = dwTest : BITS in lTest -> ",5,145,175,12, %SS_LEFT
        CONTROL ADD LABEL,  hDlg, %IDL_DWORDLONG1, "",180,145,140,12, %SS_LEFT
     
        CONTROL ADD BUTTON, hDlg, %IDOK, "Next", 115, 165, 40, 14, %BS_DEFAULT
        CONTROL ADD BUTTON, hDlg, %IDCANCEL, "Cancel", 165, 165, 40, 14
     
    ' ** Display the dialog
        DIALOG SHOW MODAL hDlg, CALL AssignDlgProc
     
    END FUNCTION

    Leave a comment:


  • Greg Turgeon
    replied
    <font face="courier new, courier" size="3"><pre>lasse--
    the following link details something that i learned about dwords (vs. longs)
    and might be relevant:

    [/CODE]


    ------------------
    -- greg
    [email protected]ve.com

    Leave a comment:


  • LRantanen
    Guest replied
    Lance,

    Ok, first you have to be careful as BIN$() only works with signed values in the LONG integer range... if you pass an large unsigned value it "overflows" and the result is "undefined".
    That I understand, but I did not use BIN$ to produce the binary representation. Instead I checked every bit with BIT and build the binary representation that way, so the overflow is not caused by BIN$ function.

    It looks like an overflow to me, too. But still, why assigning a constant causes an overflow and assigning a variable does not, even if both have similar bit pattern as far as I can tell and defined to be same type.

    Haven't developed my next problem yet so I keep coming back to this.

    Lasse Rantanen
    [email protected]

    Leave a comment:


  • Lance Edmonds
    replied
    I had the latest version of commctrl.inc file. In order to make sure I downloaded win32api.zip once more and it still reads %TVI_ROOT = &HFFFF0000??? etc. in commctrl.inc.
    Hmmm... Thats interesting... I checked my copy and I have it as &HFFFF0000&... ahha! a couple of days ago I reinstalled PB/DLL 6.0 from scratch and I was looking at the old files... I ask R&D to update this in the WIN32API.ZIP files.

    To see what happens when you assign different numeric constants to a long variable, I wrote following small code snippet which shows the bit pattern after the substitution.
    Ok, first you have to be careful as BIN$() only works with signed values in the LONG integer range... if you pass an large unsigned value it "overflows" and the result is "undefined".

    %DWTEST = &HFFFF0000????
    10000000000000000000000000000000
    -2147483648
    %DWTEST = &H0FFFF0000
    10000000000000000000000000000000
    -2147483648
    BIN$() overflow. Both of these are unsigned values beyond the LONG integer range.

    %DWTEST = &HFFFF0000
    11111111111111110000000000000000
    -65536
    %DWTEST = &HFFFF0000&
    11111111111111110000000000000000
    -65536
    Signed values in the LONG integer range.

    so lParam is expected to be an unsigned long integer.
    Yes. However, the equate definition specified an unsigned value, so internally, PB tried to convert it to a signed value before passing it to the API, but becaue it overflows the LONG range, PB passed an "undefined" value... that is what you (the programmer) told it to do, and it obeyed!

    My question still is: why does assigning a CONSTANT defined to be a DWORD to a LONG variable produce different result than assigning a VARIABLE defined to be a DWORD?
    See above.



    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]powerbasic.com</A>

    Leave a comment:


  • LRantanen
    Guest replied
    Lance,

    I had the latest version of commctrl.inc file. In order to make sure I downloaded win32api.zip once more and it still reads %TVI_ROOT = &HFFFF0000??? etc. in commctrl.inc.

    OK, but to matter under discussion. I hope I'm not boring you all by continuing this, but I still don't quite understand what happens.

    To see what happens when you assign different numeric constants to a long variable, I wrote following small code snippet which shows the bit pattern after the substitution.

    Code:
    	LOCAL BitArray AS STRING
    	LOCAL lTest    AS LONG
    	BitArray = ""
    	%DWTEST = &HFFFF0000??? ' <<< This is changed
    	lTest = %DWTEST
    	FOR i = 31 TO 0 STEP -1
        	BitArray = BitArray + STR$(BIT(lTest,i))
    	NEXT
    	                    
    	MSGBOX BitArray + $CrLf + STR$(lTest)
    Different defines produce following results

    Code:
    	%DWTEST = &HFFFF0000????
    	10000000000000000000000000000000
    	-2147483648
    	
    	%DWTEST = &H0FFFF0000
    	10000000000000000000000000000000
    	-2147483648
    	
    	%DWTEST = &HFFFF0000
    	11111111111111110000000000000000
    	-65536
    	
    	%DWTEST = &HFFFF0000&
    	11111111111111110000000000000000
    	-65536
    Now %TVM_DELETEITEM message expects SendMessage parameters be

    Code:
    	wParam = 0; 
    	lParam = (LPARAM) (HTREEITEM) hitem;
    In MS's header files these are defined to be
    Code:
    	typedef struct _TREEITEM FAR* HTREEITEM;
    	typedef DWORD LPARAM;
    so lParam is expected to be an unsigned long integer. This means that when trying to delete all items from a treeview control, Windows expects to see a bit pattern 11111111111111110000000000000000 (TVI_ROOT) as defined in header files.

    In commctrl.inc Treeview_DeleteAllItems macro is defined to be

    Code:
    FUNCTION TreeView_DeleteAllItems (BYVAL hWnd AS DWORD) AS LONG
        FUNCTION = SendMessage(hWnd, %TVM_DELETEITEM, 0, %TVI_ROOT)
    END FUNCTION
    In win32api.inc SendMessage is declared as follows

    Code:
    DECLARE FUNCTION SendMessage LIB "USER32.DLL" ALIAS "SendMessageA" (BYVAL hwnd AS LONG, BYVAL wMsg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
    so it's lParam is defined to be a long (signed integer).

    It seems to me that when substituting a constant to the lParam, something like the substitutions described above takes place and as result, first two cases produce wrong result, last two work OK (when speaking of bit patterns).

    To mess up things more (I know I'm probably not making my point very clear), making following change in the small program above, produces different results.

    Code:
    	LOCAL BitArray AS STRING
    	LOCAL lTest    AS LONG
    	LOCAL dwTemp   AS DWORD
                        
    	BitArray = ""
    	%DWTEST = &HFFFF0000??? <<< This is changed
    	dwTemp = %DWTEST
    	lTest = dwTemp
    	' Rest like above
    Every define for %DWTEST produces correct result - when speaking about bit patterns. This also makes the two macro definition - Treeview_DeleteItem ans Treeview_DeleteAllItems - to behave differently as described in earlier postings.

    My question still is: why does assigning a CONSTANT defined to be a DWORD to a LONG variable produce different result than assigning a VARIABLE defined to be a DWORD?

    PB/DLL is a great product, I just want to understand also this feature of it.

    Lasse Rantanen
    [email protected]

    Leave a comment:


  • Lance Edmonds
    replied
    It has to do with signed VS unsigned.
    Code:
    %A = &HFFFF0000??? ' unsigned DWORD value assigned to %A
    %B = &H0FFFF0000   ' unsigned DWORD value assigned to %B
    %C = &HFFFF0000    ' Signed LONG value
    %D = &HFFFF0000&   ' Signed LONG value
    BTW, the WIN32API.INC files have had this value defined as &HFFFF0000& for some time now... download the latest updates from ftp://ftp.powerbasic.com/pub/support/win32api.zip

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • LRantanen
    Guest replied
    Just one addition - when I said "have to doubt that statement" I meant in case of DWORD (???).

    Lasse Rantanen
    [email protected]

    ------------------

    Leave a comment:


  • LRantanen
    Guest replied
    Borje,

    yes it does make it work.

    Still, at least for me the original question remains unanswered - why? PB/DLL documentation says

    You can also force a constant to be stored with a given precision by following the constant with one of the variable type specifiers (%, &, &&, ?, ??, ???, !, #, ##, @, @@)
    I have to doubt that statement because the only way to make the original declares/defines to work was to replace %TVI_ROOT with a variable which was declared to be DWORD. And now Borje's finding also supports this - by removing the postfix type specifier seems to make &HFFFF0000 a DWORD.

    Lasse Rantanen
    [email protected]

    Leave a comment:


  • Borje Hagsten
    replied
    If you change

    %TVI_ROOT = &HFFFF0000???

    to

    %TVI_ROOT = &HFFFF0000

    in commctrl.inc, it works fine. I haven't tested the others, but
    my guess is the same goes for them all..


    ------------------

    Leave a comment:


  • LRantanen
    Guest replied
    Lance,

    these are copied from my version of COMMCTRL.INC dated Dec. 10, 1999.

    Lasse Rantanen
    [email protected]

    Code:
    TYPE TV_ITEM
        mask AS DWORD
        hItem AS DWORD
        STATE AS DWORD
        stateMask AS DWORD
        pszText AS ASCIIZ PTR
        cchTextMax AS LONG
        iImage AS LONG
        iSelectedImage AS LONG
        cChildren AS LONG
        lParam AS LONG
    END TYPE
     
    TYPE TVITEM
        mask AS DWORD
        hItem AS DWORD
        STATE AS DWORD
        stateMask AS DWORD
        pszText AS ASCIIZ PTR
        cchTextMax AS LONG
        iImage AS LONG
        iSelectedImage AS LONG
        cChildren AS LONG
        lParam AS LONG
    END TYPE
     
    ' only used for Get and Set messages.  no notifies
     
    TYPE TVITEMEX
        mask AS DWORD
        hItem AS DWORD
        STATE AS DWORD
        stateMask AS DWORD
        pszText AS ASCIIZ PTR
        cchTextMax AS LONG
        iImage AS LONG
        iSelectedImage AS LONG
        cChildren AS LONG
        lParam AS LONG
        iIntegral AS LONG
    END TYPE
     
    %TVI_ROOT               = &HFFFF0000???
    %TVI_FIRST              = &HFFFF0001???
    %TVI_LAST               = &HFFFF0002???
    %TVI_SORT               = &HFFFF0003???
     
    UNION TV_ITEM_UNION
        itemex AS TVITEMEX
        item AS TV_ITEM
    END UNION
     
    TYPE TV_INSERTSTRUCT
      hParent AS DWORD
      hInsertAfter AS DWORD
      item AS TV_ITEM_UNION
    END TYPE
     
    %TVM_INSERTITEM         = %TV_FIRST + 0
    %TVM_INSERTITEMW        = %TV_FIRST + 50
     
    FUNCTION TreeView_InsertItem (BYVAL hWnd AS LONG, lpis AS TV_INSERTSTRUCT) _
       AS DWORD
        FUNCTION = SendMessage(hWnd, %TVM_INSERTITEM, 0, VARPTR(lpis))
    END FUNCTION
     
    %TVM_DELETEITEM         = %TV_FIRST + 1
     
    FUNCTION TreeView_DeleteItem (BYVAL hWnd AS DWORD, BYVAL hitem AS DWORD) _
       AS LONG
        FUNCTION = SendMessage(hWnd, %TVM_DELETEITEM, 0, hitem)
    END FUNCTION
     
    FUNCTION TreeView_DeleteAllItems (BYVAL hWnd AS DWORD) AS LONG
        FUNCTION = SendMessage(hWnd, %TVM_DELETEITEM, 0, %TVI_ROOT)
    END FUNCTION

    Leave a comment:


  • Lance Edmonds
    replied
    Please post the structure for TV_ITEM_UNION and anything else that is necessaru to compile your code... Thanks!!!



    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • LRantanen
    Guest replied
    Lance,

    here is an example. Right click on main window to call the code to clear the treeview.

    As I said earlier, this is not a real problem as such, because the desired effect can be achieved easily. I just want to understand.

    Lasse Rantanen
    [email protected]

    Code:
    ' Eliminate unnecessary macros
    %NOANIMATE = 1
    %NODRAGLIST = 1
    %NOHEADER = 1
    %NOIMAGELIST = 1
    %NOLISTVIEW = 1
    %NOTABCONTROL = 1
    %NOTRACKBAR = 1
    '%NOTREEVIEW = 1
    %NOUPDOWN = 1
    
    $DIM ALL
    $COMPILE EXE
    $OPTION VERSION4
    
    $INCLUDE "WIN32API.INC"
    $INCLUDE "COMMCTRL.INC"
    
    '==========================================================
    '//* Constants
    %ID_TREEVIEW        = 1003
    %MAX_CATEGORY       = 32
    
    '//* structures
    TYPE tagLISTINFO
        hInst           AS LONG
        hWndMain        AS LONG
        hWndTreeView    AS LONG
    END TYPE
    
    GLOBAL g_ListInfo   AS tagLISTINFO
    
    GLOBAL hTRoot   AS DWORD
    GLOBAL hTPrev   AS DWORD
    GLOBAL hTParent AS DWORD
    
    '//* Function prototypes
    DECLARE FUNCTION InitInstance(BYVAL hInstance AS LONG, BYVAL iCmdShow AS LONG) AS INTEGER
    DECLARE FUNCTION InitApplication(BYVAL hInstance AS LONG) AS INTEGER
    DECLARE FUNCTION CreateControls(BYVAL hWndParent AS LONG) AS INTEGER
    DECLARE FUNCTION TV_CreateTreeView ( hWndParent AS LONG, hInst AS LONG) AS LONG
    DECLARE FUNCTION TV_AddOneItem( lpszText AS ASCIIZ PTR , BYVAL hwndTree AS LONG, index AS INTEGER) AS DWORD
    
    '==========================================================
    FUNCTION WINMAIN (BYVAL hInstance     AS LONG, _
                      BYVAL hPrevInstance AS LONG, _
                      lpCmdLine           AS ASCIIZ PTR, _
                      BYVAL iCmdShow      AS LONG) AS LONG
    
        LOCAL Msg   AS tagMSG
    
        InitApplication hInstance
        InitInstance hInstance, iCmdShow
        WHILE (GetMessage(Msg, %NULL, 0, 0) > 0)
            TranslateMessage Msg
            DispatchMessage Msg
        WEND
        FUNCTION = Msg.wParam
    END FUNCTION
    
    '==========================================================
    FUNCTION InitApplication(BYVAL hInstance AS LONG) AS INTEGER
    
        LOCAL wcNetwork     AS WndClassEx
        LOCAL szMenuName    AS ASCIIZ * 80
        LOCAL szClassName   AS ASCIIZ * 80
    
        szMenuName  = "NetworkMenu"
        szClassName = "NetworkWClass"
    
        wcNetwork.cbSize           = SIZEOF(wcNetwork)
        wcNetwork.style            = %CS_HREDRAW OR %CS_VREDRAW
        wcNetwork.lpfnWndProc      = CODEPTR( WndProc )
        wcNetwork.cbClsExtra       = 0
        wcNetwork.cbWndExtra       = 0
        wcNetwork.hInstance        = hInstance
        wcNetwork.hIcon            = LoadIcon(hInstance, BYVAL %NULL)
        wcNetwork.hCursor          = LoadCursor(%NULL, BYVAL %IDC_ARROW)
        wcNetwork.hbrBackground    = GetStockObject(%LTGRAY_BRUSH )
        wcNetwork.lpszMenuName     = VARPTR( szMenuName )
        wcNetwork.lpszClassName    = VARPTR( szClassName )
        wcNetwork.hIconSm          = LoadIcon( hInstance, BYVAL %NULL)
    
        FUNCTION = RegisterClassEx(wcNetwork)
    
    END FUNCTION
    
    '==========================================================
    FUNCTION InitInstance(BYVAL hInstance AS LONG, BYVAL iCmdShow AS LONG) AS INTEGER
    
        LOCAL hWnd AS LONG
    
        g_ListInfo.hInst = hInstance
        g_ListInfo.hWndMain = CreateWindow( "NetworkWClass", _
                                            "Treeview Test", _
                                            %WS_OVERLAPPEDWINDOW, _
                                            GetSystemMetrics ( %SM_CXSCREEN )/4, _
                                            GetSystemMetrics ( %SM_CYSCREEN )/4, _
                                            GetSystemMetrics ( %SM_CXSCREEN )/2, _
                                            GetSystemMetrics ( %SM_CYSCREEN )/2, _
                                            %NULL, _
                                            %NULL, _
                                            hInstance, _
                                            BYVAL %NULL)
        ShowWindow g_ListInfo.hWndMain, iCmdShow
        UpdateWindow g_ListInfo.hWndMain
        FUNCTION=%TRUE
    END FUNCTION
    
    '==========================================================
    FUNCTION WndProc (BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _
                      BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
        SELECT CASE wMsg
            CASE %WM_CREATE
                CreateControls hWnd
                FUNCTION = %NULL
                EXIT FUNCTION
            CASE %WM_RBUTTONUP
                ' This does not clear Treeview
                MSGBOX "About to call Treeview_DeleteAllItems"
                TreeView_DeleteAllItems g_ListInfo.hWndTreeview
                ' This does
                MSGBOX "About to call Treeview_DeleteItem"
                TreeView_DeleteItem g_ListInfo.hWndTreeview, %TVI_ROOT
            CASE %WM_DESTROY
                PostQuitMessage 0
                FUNCTION = %NULL
                EXIT FUNCTION
        END SELECT
        FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
    END FUNCTION
    
    '==========================================================
    FUNCTION CreateControls(BYVAL hWndParent AS LONG) AS INTEGER
    
        InitCommonControls
        g_ListInfo.hWndTreeview = TV_CreateTreeview(hWndParent, g_ListInfo.hInst)
        IF g_ListInfo.hWndTreeview = 0 THEN
            FUNCTION = %FALSE
            EXIT FUNCTION
        END IF
        FUNCTION = %TRUE
    END FUNCTION
    
    '==========================================================
    FUNCTION TV_CreateTreeView ( hWndParent AS LONG, hInst AS LONG) AS LONG
    
        LOCAL hwndTree      AS LONG
        LOCAL rcl           AS RECT
        LOCAL iLeft         AS INTEGER
        LOCAL iTop          AS INTEGER
        LOCAL iWidth        AS INTEGER
        LOCAL iHeight       AS INTEGER
    
        GetClientRect hWndParent, BYVAL VARPTR(rcl)
        iLeft = 0
        iTop = 0
        iWidth = (rcl.nRight - rcl.nLeft)/4
        iHeight = rcl.nBottom - rcl.nTop
        hwndTree = CreateWindowEx(  %WS_EX_CLIENTEDGE, _
                                    $WC_TREEVIEW , _
                                    "",_
                                    %WS_VISIBLE OR %WS_CHILD OR %WS_BORDER OR %TVS_HASLINES OR _
                                    %TVS_HASBUTTONS OR %TVS_LINESATROOT , _
                                    iLeft, iTop, iWidth, iHeight, _
                                    hWndParent, _
                                    %ID_TREEVIEW, _
                                    hInst, _
                                    BYVAL %NULL )
        CALL TV_InitTreeView(hInst, hwndTree)
        FUNCTION = hWndTree
    END FUNCTION
    
    '==========================================================
    SUB TV_InitTreeView (hInst AS LONG, hWndTree AS LONG)
    
        LOCAL szText    AS ASCIIZ*%MAX_CATEGORY
        LOCAL hItem    AS DWORD
        LOCAL iIndex    AS INTEGER
        
        hTParent = %TVI_ROOT
        hTPrev = %TVI_SORT
        FOR iIndex = 0 TO 3
            szText = "Item " + STR$(iIndex + 1)
            hItem = TV_AddOneItem (BYVAL VARPTR(szText),BYVAL hwndTree, iIndex)
        NEXT
    
    END SUB
    
    '==========================================================
    FUNCTION TV_AddOneItem( lpszText AS ASCIIZ PTR , BYVAL hwndTree AS LONG, index AS INTEGER) AS DWORD
    
        LOCAL hItem AS LONG
        LOCAL tvI AS TV_ITEM_UNION
        LOCAL tvIns AS TV_INSERTSTRUCT
    
        tvI.item.mask = %TVIF_CHILDREN OR %TVIF_HANDLE OR _
                          %TVIF_STATE OR %TVIF_TEXT
        tvI.item.pszText = lpszText
        tvIns.item = tvI
        tvIns.hInsertAfter = hTPrev
        tvIns.hParent = hTParent
        hItem = SendMessage(hwndTree, %TVM_INSERTITEM, 0, VARPTR(tvIns))
        FUNCTION = hItem
    END FUNCTION

    Leave a comment:


  • Lance Edmonds
    replied
    Lasse, you must have something else wrong... there is no operational difference between the two functions.

    Things can be confusing (for the programmer) when it comes to signed versus unsigned values, but as the bit pattern passed to the API is correct (in this case), the API executes correctly regardless of whether you pass &HFFFF0000??? or &HFFFF0000& to it.

    The value of TVI_ROOT is correct too (according to my VC++ header files).

    Post an compilable example fo the code that fails, and we'll see what we can spot.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • LRantanen
    Guest started a topic Repeated Question (Treeview Macros)

    Repeated Question (Treeview Macros)

    I have to repeat this question, because I am really interested to learn to use all the aspects of PB/DLL and I'm seemingly having some teething problems. I hope I'm not offending anybody by repeating this question so soon. I have always got good answers from this forum, so I believe somebody can explain this to me, too.

    In COMMCTRL.INC there is a define statement

    %TVI_ROOT = &HFFFF0000???

    I understand this so that TVI_ROOT is defined to be type DWORD (???).

    So given two following macro definitions from COMMCTRL.INC, why does the first one work and the second one not?

    Code:
    FUNCTION TreeView_DeleteItem (BYVAL hWnd AS DWORD, BYVAL hitem AS DWORD) _
       AS LONG
        FUNCTION = SendMessage(hWnd, %TVM_DELETEITEM, 0, hitem)
    END FUNCTION
    
    FUNCTION TreeView_DeleteAllItems (BYVAL hWnd AS DWORD) AS LONG
        FUNCTION = SendMessage(hWnd, %TVM_DELETEITEM, 0, %TVI_ROOT)
    END FUNCTION
    To work means here that making a call

    Code:
    	TreeView_DeleteItem hWndTreeView, %TVI_ROOT
    clears the Treeview and a call

    Code:
    	TreeView_DeleteAllItems hWndTreeView
    does not.

    Making the following modification makes macro TreeView_DeleteAllItems to do what I assume it to do.

    Code:
    FUNCTION TreeView_DeleteAllItems (BYVAL hWnd AS DWORD) AS LONG
        LOCAL dwItem AS DWORD
        dwItem = %TVI_ROOT
        FUNCTION = SendMessage(hWnd, %TVM_DELETEITEM, 0, dwItem)
    END FUNCTION
    Why?

    1. Am I assuming here something which is not true?

    2. Is there something wrong with typing of numeric constants in PB/DLL version 6.0 (and Win98)?

    I really hope someone could comment on this.

    TIA
    Lasse Rantanen
    [email protected]
Working...
X