Announcement

Collapse
No announcement yet.

DeleteObject question

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

  • DeleteObject question

    In a specific program where I added multiple treeviews months ago, I'm just starting to get Windows errors. There is no error message number, just the prompt to send the info to MS and the event log shows the application stopped suddenly.

    On machines with more memory it doesn't occur. I'm thinking memory leak but should it show up now after all this time?

    I'm using an imagelist with the treeviews and some local handles are being created. What is the proper way to deleteobject when the handle is local and not global. Those I delete in wm_destroy.

    The error seems to occur when I call a DLL which checks the security level of user as to whether or not they can run the assigned program. This DLL has been in place with no error for 3 years. Real puzzle.

    Bob Mechler

  • #2
    This thread has two ways to test for memory leaks.

    If you are using treeviews with icons, are you getting rid of the icons (destroyicon) after adding them to the imagelist?
    Last edited by Chris Holbrook; 8 Jul 2008, 12:25 PM.

    Comment


    • #3
      Thanks for the DestroyIcon info. Never loaded them before into a treeview.

      Code:
              ' Create our icon image list for the TREEVIEW
      '        IF INSTR(FNUPRC$(MENU_KIND$),"NUMBERED") = 0 THEN
      '          hImageList& = ImageList_Create( 12, 12, %ILC_MASK OR %ILC_COLOR32, 5, 1 )
      '          hInstance& = GetModuleHandle(BYVAL %NULL)
      '          
      '          CALL ImageList_AddIcon(hImageList&, LoadIcon(hInstance&, "02_PROG_EN"))
      '          CALL ImageList_AddIcon(hImageList&, LoadIcon(hInstance&, "01_TNET"))
      '          CALL ImageList_AddIcon(hImageList&, LoadIcon(hInstance&, "03_PROG_DIS"))
      '          CALL ImageList_AddIcon(hImageList&, LoadIcon(hInstance&, "04_LEFT_MENU"))
      '          CALL ImageList_AddIcon(hImageList&, LoadIcon(hInstance&, "05_RIGHT_MENU"))
      '          CONTROL SEND hDlg,%ID_TREE1, %TVM_SETIMAGELIST, %TVSIL_NORMAL, hImageList&
      '        END IF
              IF INSTR(FNUPRC$(MENU_KIND$),"NUMBERED") = 0 THEN
                hImageList& = ImageList_Create( 12, 12, %ILC_MASK OR %ILC_COLOR32, 5, 1 )
                hInstance& = GetModuleHandle(BYVAL %NULL)
                hIcon& = LoadIcon(hInstance&, "02_PROG_EN")
                CALL ImageList_AddIcon(hImageList&,hIcon& )
                DestroyIcon hIcon&
                hIcon& = LoadIcon(hInstance&, "01_TNET")
                CALL ImageList_AddIcon(hImageList&,hIcon& )
                DestroyIcon hIcon&
                hIcon& = LoadIcon(hInstance&, "03_PROG_DIS")
                CALL ImageList_AddIcon(hImageList&,hIcon& )
                DestroyIcon hIcon&
                hIcon& = LoadIcon(hInstance&, "04_LEFT_MENU")
                CALL ImageList_AddIcon(hImageList&,hIcon& )
                DestroyIcon hIcon&
                hIcon& = LoadIcon(hInstance&, "05_RIGHT_MENU")
                CALL ImageList_AddIcon(hImageList&,hIcon& )
                DestroyIcon hIcon&
                CONTROL SEND hDlg,%ID_TREE1, %TVM_SETIMAGELIST, %TVSIL_NORMAL, hImageList&
              END IF
      Here is the change I made and I no longer have the problem.

      Thanks again.

      Bob Mechler

      Comment


      • #4
        Strange, The API docs say that icons loaded using LoadIcon do not need to be destroyed.

        I don't think the problem is associated with failing to destroy the icons.

        Yet, your destroying the icons may be fixing the problem for a different reason.

        LoadIcon called multiple times using the same resource name, does not load multiple instances of the icon. It loads it once and the rest of the time it simply returns the previous handle of the first instance (if I read the docs right).

        That said, if your app closes the dialog with the treeview at times and then recreated it again and the treeview code (and imagelist code) is executed multiple times in the app, a strange thing could happen.

        When researching the ImageList functions I found a strange bug in the ImageList_AddMasked function (adds a bitmap to imagelist). It is possible this bug appears in the ImageList_AddIcon function as well (I use use ImageList_ReplaceIcon instead of ImageList_Addicon which doesn't appear to have a problem).

        When adding a Bitmap handle to the ImageList, Windows appears to corrupt the original bitmap. It shouldn't be used again. If I need the original bitmap image, I use the CopyImage API function to create a copy and then add it to the imagelist and then destroy it.

        If ImageList_AddIcon has a similiar bug like ImageList_AddMasked, then possibly the original icons gets corrupted when added. If your imagelist code gets executed again in the app (ie. the dialog is closed and later recreated with the treeview again), the calls to LoadIcon simply reuse the original icon handle from the first call. If those icons are now corrupted, then reusing them may cause problems.

        By using DestroyIcon, you may be inadvertantly fixing the problem. Since you destroyed the original icon, LoadIcon must literally reload the icon again, rather than use the original instance of it. This means you get a clean icon handle when using it again.

        I can't say this for sure, since I have not tested ImageList_AddIcon to see if it has the same bug or not. I do know that ImageList_AddMasked does have this bug and it will corrupt the original bitmap once used.
        Last edited by Chris Boss; 8 Jul 2008, 01:51 PM.
        Chris Boss
        Computer Workshop
        Developer of "EZGUI"
        http://cwsof.com
        http://twitter.com/EZGUIProGuy

        Comment


        • #5
          My joy was short lived as it turns out.

          The problem went away for about 5 logins to the application and then returned. Many of the things you said in your post may apply to my app as I draw and redraw the treeview based on the contents each treeview would need to have. The treeviews are side by side with the left treeview representing menus and the right treeview changing to reflect the programs available in that menu.

          An older version of this program with the same icons doesn't have the problem. At least not bad enough to have it belly up.

          There are over 500 possible tree nodes for the right treeview, any subset of which might be displayed based on the left treeview. Oddly we have an option that does not use the icons, but menu numbers to satisfy those who've memorized the menu number choice to get to a program. That version has never failed. I've used that presentation option for months and it never caused the problem.

          The boss, first time she tried to run it, used the icon view and it crashed. I think the problem from that observation is how the icons are handled in my program.

          Thanks for your observations.

          Bob Mechler

          Comment


          • #6
            Question:

            Are you using the %TVS_CHECKBOXES style at all ?

            If so, there is another quirk with the Treeview when using this style (which I will explain if you are)
            Chris Boss
            Computer Workshop
            Developer of "EZGUI"
            http://cwsof.com
            http://twitter.com/EZGUIProGuy

            Comment


            • #7
              Here is the code I use for the two treeviews. The style you mentioned, I'm not using.

              Code:
                    IF CLASSIC_MENU = 0 THEN
                      'Treeviews did have a y value of 13 and a depth value of 193 prior to removing the header line
                      CONTROL ADD "SysTreeView32", hdlg,%ID_TREE1, "", 77, 5, 117, 198, _
                         %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR %TVS_HASBUTTONS OR %TVS_HASLINES OR _
                       %TVS_LINESATROOT OR %TVS_SHOWSELALWAYS OR %TVS_TRACKSELECT, %WS_EX_STATICEDGE
                      CONTROL SEND hdlg&, %ID_TREE1, %WM_SETFONT, hFontCap, 0
                      CONTROL HANDLE hdlg, %ID_TREE1 TO hTree&(1)
                      ' Create our icon image list for the TREEVIEW
                      IF INSTR(FNUPRC$(MENU_KIND$),"NUMBERED") = 0 THEN
                        hImageList& = ImageList_Create( 12, 12, %ILC_MASK OR %ILC_COLOR32, 5, 1 )
                        hInstance& = GetModuleHandle(BYVAL %NULL)
                        hIcon& = LoadIcon(hInstance&, "02_PROG_EN")
                        CALL ImageList_AddIcon(hImageList&,hIcon& )
                        DestroyIcon hIcon&
                        hIcon& = LoadIcon(hInstance&, "01_TNET")
                        CALL ImageList_AddIcon(hImageList&,hIcon& )
                        DestroyIcon hIcon&
                        hIcon& = LoadIcon(hInstance&, "03_PROG_DIS")
                        CALL ImageList_AddIcon(hImageList&,hIcon& )
                        DestroyIcon hIcon&
                        hIcon& = LoadIcon(hInstance&, "04_LEFT_MENU")
                        CALL ImageList_AddIcon(hImageList&,hIcon& )
                        DestroyIcon hIcon&
                        hIcon& = LoadIcon(hInstance&, "05_RIGHT_MENU")
                        CALL ImageList_AddIcon(hImageList&,hIcon& )
                        DestroyIcon hIcon&
                        CONTROL SEND hDlg,%ID_TREE1, %TVM_SETIMAGELIST, %TVSIL_NORMAL, hImageList&
                      END IF
              
                      '
                      'program treeview
                      '
                      CONTROL ADD "SysTreeView32", hdlg,%ID_TREE2, "", 196, 5, 165, 198, _
                       %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR %TVS_HASBUTTONS OR %TVS_HASLINES OR _
                       %TVS_LINESATROOT OR %TVS_SHOWSELALWAYS OR %TVS_TRACKSELECT,%WS_EX_STATICEDGE
                      CONTROL SEND hdlg&, %ID_TREE2, %WM_SETFONT, hFontCap, %True
                      CONTROL HANDLE hdlg, %ID_TREE2 TO hTree&(2)
                      CONTROL SEND hDlg,%ID_TREE2, %TVM_SETIMAGELIST, %TVSIL_NORMAL, hImageList&
                      '
                      TreeView_Default = -1
                    END IF

              Comment


              • #8
                Warning about using TVN_GETDISPINFO/LVN_GETDISPINFO:

                http://www.powerbasic.com/support/pbforums/showthread.php?t=13143
                kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                Comment


                • #9
                  Having read the comments above I decided to give my application - still in development - some stress testing with a lot of data. I'm getting a similar problem to Bob, every once in a while the application grabbed another 256K of memory and didn't let go, eventually it GPF'd. but it takes many refreshes of the TreeView before that happens. Maybe that's because my icons are small, 16x16.

                  Comment


                  • #10
                    In my code I'm applying the imagelist to both treeviews using the same handle. Could that be a problem.

                    Also the text is always set to %MAX_PATH.
                    DIM TmpAsciiz AS ASCIIZ * %MAX_PATH
                    pItem.pszText = VARPTR(TmpAsciiz)
                    pItem.cchTextMax = SIZEOF(TmpAsciiz)

                    Comment


                    • #11
                      Each of my icons is about 2500 bytes. Don't know if that is pertinent. I haven't been able to get 2 gig ram machines to crash but 1 gig machines do but only if the icons are added to the treeview.

                      Bob Mechler

                      Comment


                      • #12
                        Originally posted by BOB MECHLER View Post
                        ...but only if the icons are added to the treeview.
                        My app uses the icon identifier to drive click processing so I can't take the icons out, worse luck.

                        Comment


                        • #13
                          A few observations:

                          You use:

                          Code:
                          hImageList& = ImageList_Create( 12, 12, %ILC_MASK OR %ILC_COLOR32, 5, 1 )
                          You also load the icons using LoadIcon, which is only for loading icons which have the size defined by the operating system (SM_CXICON, SM_CYICON) which defaults to 32 x 32

                          If your imagelist defines the size at 12 x 12 pixels, but you load icons using Loadicon which should be 32 x 32, then Windows has to shrink the images when adding them to the imagelist. Loadicon may cause problems if you are attempting to load a 12 x 12 pixel icon.
                          Chris Boss
                          Computer Workshop
                          Developer of "EZGUI"
                          http://cwsof.com
                          http://twitter.com/EZGUIProGuy

                          Comment


                          • #14
                            I just have a couple comments:

                            1. Is the Tree completely expanded to every node? I know even big PCs can come to their knees with things like clicking the root node in regedit and pressing *. Might want to only allow so many nodes open at a time.

                            2. While icons may not have problems you can have issues with imagelists. I haven't used treeviews as much as listviews, but I know listviews can share imagelists which means they don't remove them when they are closed to leave them for other listviews, etc...then you need to destroy them when done. Image lists may also store copies of the icon too instead of reusing handles. When playing with shell imagelists I once loaded just the icons I needed for files I was showing by their handle and ran out of memory. I then found that I could use the system imagelist instead and have my app index into it which used no memory for my app. Sometimes deleting/removing objects when they don't need to be or shouldn't can cause issues too. It could even be the treeview deleting the imagelist when it closes and another treeview is still trying to use it.
                            sigpic
                            Mobile Solutions
                            Sys Analyst and Development

                            Comment


                            • #15
                              Also, from the API Docs:

                              "It is only necessary to call DestroyIcon for icons created with the CreateIconIndirect function"

                              "The icon must not be in use."
                              sigpic
                              Mobile Solutions
                              Sys Analyst and Development

                              Comment


                              • #16
                                I'll review the 12x12 issue vs 32x32 issue. I had to play with 32x32,16x16 and 12x12 was the best size. Might just need to retool the icons to be 12x12 and not use LoadIcon.

                                Maybe I'll change the setting from 12x12 back to 32x32 and see if the problem continues.

                                Bob Mechler

                                Comment


                                • #17
                                  Just noticed a scary thing, while running the memory display code to which I referred earlier - my own cheap & nasty version that is - when the app first loads and populates its TreeView, the memory in use ( workingSetSize got from GetProcessMemoryInfo) is &H3A6000. When minimized, it is &HEA000. When restored, it is &H18A000. Why?

                                  Comment


                                  • #18
                                    Maybe a lil overkill or off topic...but the only sure fire way of thinking of things
                                    What THALT shall create....Thall SHALT destroy

                                    If you hold to that premise, then you can start looking for things you thought were cleaned up, but sometimes aren't

                                    Sometimes its hard to do (because you just did not know something was created and not destroyed) but it sure cuts down on I can NOT find the problem...and the problem looks like it is in 1 area
                                    Engineer's Motto: If it aint broke take it apart and fix it

                                    "If at 1st you don't succeed... call it version 1.0"

                                    "Half of Programming is coding"....."The other 90% is DEBUGGING"

                                    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                                    Comment


                                    • #19
                                      I've eventually cut my app down to a minimum, compileable version below. There is something fishy about memory allocation. There's a loop in the WM_INITDIALOG handler which empties and refills the treeview as often as you like, as the number of iterations in increased the memory used fluctuates, but does not steadily increase:

                                      Code:
                                      one iteration: &h39C000
                                      ten : &h3A2000
                                      100 : &h362000
                                      1000: &h365000
                                      But it doesn't GPF, and it does use an imagelist, so Bob I hope there is something here to help.

                                      Code:
                                      '
                                      'TV memory problem - compile with PBWin 8.04 on XP
                                      '
                                      #COMPILE EXE
                                      #DIM ALL
                                      #INCLUDE "commctrl.inc"
                                      #INCLUDE "comdlg32.inc"
                                      #INCLUDE "process_memoryinfo.inc"
                                      
                                      %IDC_TV                = 1320
                                      %IDC_RETV_BN           = 1343
                                      
                                      GLOBAL icon_table, icon_column, icon_index, icon_lh, icon_wildcard, icon_col_ticked, _
                                             icon_table_ticked, icon_indexcol, icon_wildcardgrey, icon_sqlitehouse, _
                                             icon_project, icon_sql, icon_DBBlack AS LONG
                                      ' listview styles
                                      %DEFAULT_LV_STYLES = %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR %LVS_SHOWSELALWAYS OR %LVS_REPORT
                                      %DEFAULT_LV_EX_STYLES = %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_RIGHTSCROLLBAR
                                      
                                      '----------------------------------------------------------------------------------
                                      ' icon identifiers for treeview imagelist
                                      %ico_table          = 1
                                      %ico_column         = 2       ' dot
                                      '-------------------------------------------------------------------------------
                                      ' Icon stuff for DBTree v0.11
                                      '---------------------------------------------------------------
                                      
                                      TYPE TAGICONDIR
                                      
                                          idReserved  AS WORD '// Reserved (must be 0)
                                          idType      AS WORD '// Resource Type (1 For icons)
                                          idCount     AS WORD '// How many images?
                                      
                                      END TYPE
                                      
                                      TYPE TAGICONDIRENTRY
                                      
                                          bWidth          AS BYTE     '// Width, In Pixels, of the Image
                                          bHeight         AS BYTE     '// Height, In Pixels, of the Image
                                          bColorCount     AS BYTE     '// Number of colors In Image (0 If >=8bpp)
                                          bReserved       AS BYTE     '// Reserved ( must be 0)
                                          wPlanes         AS WORD     '// Color Planes
                                          wBitCount       AS WORD     '// Bits per pixel
                                          dwBytesInRes    AS DWORD    '// How many bytes In this resource?
                                          dwImageOffset   AS DWORD    '// Where In the file is this image?
                                      
                                      END TYPE
                                      
                                      '// Creates an icon using plain filedata, like the 766 Bytes .ICO files.
                                      '// Returns a iconhandle.
                                      FUNCTION SetIconFileBits( BYVAL lpMem AS LONG ) AS LONG
                                      
                                          DIM pIconDir        AS TAGICONDIR PTR
                                          DIM IconDirEntry    AS TAGICONDIRENTRY PTR
                                      
                                          pIconDir = lpMem
                                          IF @pIconDir.idCount < 1 THEN EXIT FUNCTION
                                          IconDirEntry = pIconDir + LEN( @pIconDir )
                                      
                                          FUNCTION = CreateIconFromResource( _
                                                BYVAL pIconDir + @IconDirEntry.dwImageOffset _
                                              , @IconDirEntry.dwBytesInRes _
                                              , @pIconDir.idType _
                                              , &H30000& _
                                              )
                                      
                                      END FUNCTION
                                      
                                      
                                      '//////////////////////////////////////////////////////////////////////////
                                      MACRO mBinDataStuff
                                          LOCAL a AS LONG
                                          LOCAL t, t2 AS STRING
                                          FOR a = 1 TO DATACOUNT: T = T & READ$( a ): NEXT a
                                          FOR a = 1 TO LEN( T ) STEP 2
                                              T2 = T2 & CHR$( VAL( "&H" & MID$( T, a , 2 ) ) )
                                          NEXT a
                                          FUNCTION = STRPTR(T2)
                                      END MACRO
                                      '-------------------------------------------------------------------------------
                                      '-------------------------------------------------------------------------------
                                      ' dbcolumn data
                                      FUNCTION BinBasColumn( ) AS DWORD
                                          mBinDataStuff
                                      
                                      DATA 0000010001001010100001000400280100001600000028000000100000002000000001
                                      DATA 00040000000000000000000000000000000000000000000000000000000000C4C4C400
                                      DATA 80FFFF004080FF0000FFFF00FFFFFF0000000000000000000000000000000000000000
                                      DATA 0000000000000000000000000000000000000000000000000000000000000000000000
                                      DATA 0000000000000000000000000000000000000000000000000000000000000000000000
                                      DATA 0003333000000000001113330000000000125133000000000012451300000000001222
                                      DATA 1300000000000111100000000000000000000000000000000000000000000000000000
                                      DATA 000000000000000000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000F87F
                                      DATA 0000F03F0000F03F0000F03F0000F03F0000F87F0000FFFF0000FFFF0000FFFF0000FF
                                      DATA FF0000
                                      
                                      
                                      
                                      END FUNCTION
                                      '-------------------------------------------------------------------------------
                                      FUNCTION BinBasTable AS DWORD
                                      
                                           mBinDataStuff
                                      
                                      DATA 0000010001001010100001000400280100001600000028000000100000002000000001
                                      DATA 00040000000000000000000000000000000000000000000000000000000000FF800000
                                      DATA 80400000FF808000000000000000000000000000000000000000000000000000000000
                                      DATA 0000000000000000000000000000000000000000000000000000000000011111113333
                                      DATA 3300010000033333333001022223333333300100000333333330010222233333333001
                                      DATA 0000033333333001022223333333300100000300000030010222222222201001000000
                                      DATA 0000001001111111111111100100000000000010010000000000001001111111111111
                                      DATA 100000000000000000FFFF000080030000BE010000A0010000BE010000A0010000BE01
                                      DATA 0000A0010000BEFD0000A0050000BFFD000080010000BFFD0000BFFD000080010000FF
                                      DATA FF0000
                                      
                                      END FUNCTION
                                      
                                      '-------------------------------------------------------------------------------
                                      FUNCTION BinBasLH AS DWORD
                                      
                                          mBinDataStuff
                                      
                                      DATA 0000010001001010100001000400280100001600000028000000100000002000000001
                                      DATA 0004000000000000000000000000000000000000000000000000000000000000008000
                                      DATA 0080000000B5FF00800000008000800080800000808080000000FF0000DD000000FFFF
                                      DATA 00FF2E2C00FF00FF00FFA37400C0C0C000FFFFFF00999999999999999999999999F0FF
                                      DATA FFBBBBFFFFFFFFFFFFBBBBFFFFFFFF1111BBBBFFFFFFFFBBBBBBBBBFFF0FFBBBBBBBBB
                                      DATA BFFFFFFBBBBBBBBBBFFFFFFBBBBBBBBBBBFFFFBBBBBBBBABBBFFFFBBBBBAAAAAABFFFF
                                      DATA BAAAAAAA333AA7A7AA333333AAABFFFFBAAAAAAAABBBBFFBBBBBBAAABBBBBBBBBBBBBB
                                      DATA BBBBBBBBBBBBBBBBBB0000000000000000000000000000000000000000000000000000
                                      DATA 0000000000000000000000000000000000000000000000000000000000000000000000
                                      DATA 000000
                                      
                                      END FUNCTION
                                      '-------------------------------------------------------------------------
                                      FUNCTION DBBTreeViewInsertItem(BYVAL hTree AS DWORD, BYVAL hParent AS DWORD, _
                                                                     sItem AS STRING, liconu AS LONG, licons AS LONG, bCB AS LONG) AS LONG
                                          LOCAL tTVItem   AS TV_ITEM
                                          LOCAL tTVInsert AS TV_INSERTSTRUCT
                                      
                                          '? sitem,%MB_TASKMODAL,"debug"
                                          IF hParent THEN
                                              tTVItem.mask      = %TVIF_CHILDREN OR %TVIF_HANDLE
                                              tTVItem.hItem     = hParent
                                              tTVItem.cchildren = 1
                                              TreeView_SetItem hTree, tTVItem
                                          END IF
                                      
                                          tTVInsert.hParent              = hParent
                                          tTVInsert.Item.Item.mask       = %TVIF_TEXT OR %TVIF_IMAGE OR %TVIF_SELECTEDIMAGE OR %TVIF_STATE OR %TVIF_HANDLE
                                          tTVInsert.Item.Item.pszText    = STRPTR(sItem)
                                          tTVInsert.Item.Item.cchTextMax = LEN(sItem)
                                          ttvinsert.Item.Item.iImage         = liconu
                                          ttvinsert.Item.Item.iSelectedImage = licons
                                          ttvinsert.Item.Item.stateMask      = %TVIS_STATEIMAGEMASK ' so we can change the checkbox state
                                          SHIFT LEFT BCB, 12
                                          ttvinsert.Item.Item.state          = bCB '
                                      
                                          FUNCTION = TreeView_InsertItem(hTree, tTVInsert)
                                      END FUNCTION
                                      '------------------------------------------------------------------------------
                                      FUNCTION DoTV(BYVAL hDlg AS DWORD, BYVAL lID AS LONG) AS LONG
                                          LOCAL i, j AS LONG
                                          LOCAL hCtl    AS DWORD
                                          LOCAL hRoot, hParent, hchild AS DWORD
                                      
                                          CONTROL HANDLE hDlg, lID TO hCtl
                                      
                                          FOR i = 1 TO 100
                                              hRoot = DBBTreeViewInsertItem(hCtl, %NULL, "Parent" + STR$(i), %ico_table, %ico_table, 3)' insert table in tree no CB
                                              FOR j = 1 TO RND(2,50)
                                                  hchild = DBBTreeViewInsertItem(hCtl, hroot, "Child" + STR$(j), %ico_column, %ico_column,3)' columnname
                                              NEXT
                                          NEXT
                                      END FUNCTION
                                      '------------------------------------------------------------------------------
                                      CALLBACK FUNCTION TVPROBLEM_dialogProc()
                                          STATIC hTVWnd           AS DWORD
                                          LOCAL s, s1             AS STRING
                                          LOCAL i, l, lresult     AS LONG
                                          LOCAL hCtl              AS DWORD ' hwnd for listview, etc
                                          LOCAL sz                AS ASCIIZ*260
                                          LOCAL psz               AS ASCIZ PTR
                                          LOCAL lpNmh             AS NMHDR PTR
                                          LOCAL lpTV              AS NM_TREEVIEW PTR
                                          LOCAL treeItem          AS TV_ITEM
                                          LOCAL pTVITEM           AS tv_item PTR
                                          LOCAL TVht              AS TV_HITTESTINFO
                                          LOCAL DWPOS             AS DWORD
                                          STATIC bITEMmode        AS LONG ' boolean
                                          STATIC hTreeImgLst      AS LONG
                                          LOCAL w, h, x AS LONG
                                          LOCAL pnmh              AS NMHDR PTR
                                          LOCAL pnm               AS NMLVCUSTOMDRAW PTR
                                          LOCAL dwGdiObj          AS DWORD ' for resource monitor
                                          STATIC hTimer           AS DWORD ' for resource monitor
                                          '
                                          %MSG_SETFOCUS = %WM_USER + 100
                                      
                                          SELECT CASE AS LONG CBMSG
                                              CASE %WM_INITDIALOG
                                                  hTimer = SetTimer(CBHNDL, 0, 1000, 0)
                                                  hTVWnd = getdlgitem(CBHNDL, %IDC_TV )
                                                  ' Add icons to image list
                                                  hTreeImgLst = ImageList_Create(16, 16, %ILC_COLOR32 OR %ILC_MASK, 4, 1)
                                                  l = GetModuleHandle(BYVAL 0)
                                                  destroyicon (ImageList_AddIcon (hTreeImgLst, icon_LH))
                                                  destroyicon (ImageList_AddIcon (hTreeImgLst, icon_table))
                                                  destroyicon (ImageList_AddIcon (hTreeImgLst, icon_column))
                                                  CONTROL SEND CBHNDL, %IDC_TV, %TVM_SETIMAGELIST, %TVSIL_NORMAL, hTreeImgLst ' set user image list
                                                  FOR i = 1 TO 10 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< PLAY WITH THIS VALUE
                                                                   '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< AND OBSERVE EFFECT ON MEMORY
                                                      Treeview_Deleteallitems(hTVWnd)
                                                      DoTV(CBHNDL, %IDC_TV )
                                                  NEXT
                                      '
                                              CASE %WM_LBUTTONDOWN
                                                  SendMessage CBHNDL, %WM_NCLBUTTONDOWN, %HTCAPTION, BYVAL %NULL  ' force drag
                                               '
                                              CASE %WM_COMMAND
                                                  SELECT CASE CBCTL
                                                  CASE %IDC_RETV_BN ' REFRESH TREEVIEW
                                                      IF CBCTLMSG = %BN_CLICKED THEN
                                                          GOSUB RefreshTV
                                                      END IF
                                                   '
                                              END SELECT
                                              '
                                              CASE %MSG_SETFOCUS
                                              '
                                              CASE %WM_DESTROY
                                                  imagelist_destroy hTreeImgLst
                                                  IF hTimer THEN KillTimer CBHNDL, hTimer
                                      '
                                              CASE %WM_SYSCOMMAND ' relay maximize/minimize to the TACE window
                                                  SELECT CASE CBWPARAM AND &HFFF0
                                                      CASE %SC_MINIMIZE
                                                          DIALOG SHOW STATE CBHNDL, %SW_MINIMIZE
                                                      CASE %SC_RESTORE
                                                  END SELECT
                                      
                                              CASE %WM_TIMER
                                                 dwGdiObj = GetGuiResources(GetCurrentProcess(), %GR_GDIOBJECTS)
                                                 lresult = Currentprocessmemory
                                                 DIALOG SET TEXT CBHNDL, "Mem= " + HEX$(lresult) +  " GDI OBJs=" + STR$(dwGdiObj)
                                          END SELECT
                                          EXIT FUNCTION
                                      
                                      RefreshTV:
                                          Treeview_deleteAllItems(hTVWnd)
                                          DoTV(CBHNDL, %IDC_TV )
                                          RETURN
                                      
                                      
                                      END FUNCTION
                                      '------------------------------------------------------------------------------
                                      FUNCTION TVPROBLEM(BYVAL hParent AS DWORD) AS LONG
                                          LOCAL hfont, hfont1, lRslt AS LONG
                                          LOCAL hDlg  AS DWORD
                                          LOCAL s AS STRING
                                      
                                          DIALOG NEW hParent, "TreeView Memory Problem ", _
                                                              50, 50, 175, 239, _
                                                              %WS_POPUP OR %WS_THICKFRAME OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR _
                                                              %WS_SYSMENU OR %DS_NOFAILCREATE OR %WS_CAPTION OR _
                                                              %WS_MINIMIZEBOX OR %DS_SETFONT, %WS_EX_CONTROLPARENT  TO hdlg
                                      
                                          DIALOG  SET COLOR   hDlg, -1, RGB(155, 255, 255)
                                          CONTROL ADD "SysTreeView32", hdlg, %IDC_TV, "SysTreeView32_1", _
                                                    5,5,165,200, _2, 16, 153, 175, _
                                                    %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _
                                                    %TVS_HASBUTTONS OR %TVS_HASLINES _ OR %TVS_CHECKBOXES _
                                                    OR %TVS_LINESATROOT OR %TVS_SHOWSELALWAYS, _
                                                    %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR _
                                                    %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
                                          CONTROL ADD BUTTON,  hDlg, %IDC_RETV_BN,        "Refresh TreeView",     2, 223, 68, 15
                                      '    CONTROL SET COLOR hdlg, %IDC_DBID_LAB, -1, &Hc0f0f0
                                      
                                          DIALOG SHOW MODAL hDlg, CALL TVPROBLEM_dialogProc TO lRslt
                                          FUNCTION = lRslt
                                      END FUNCTION
                                      '=================================================================================
                                      FUNCTION PBMAIN () AS LONG
                                          LOCAL i, hfile AS LONG
                                          LOCAL dwSize AS DWORD: dwSize=256
                                          LOCAL s AS STRING
                                          '
                                          InitCommonControls
                                          '
                                          Icon_LH            = SetIconFileBits(BinBasLH)
                                          Icon_Table         = SetIconFileBits(BinBasTable)
                                          Icon_Column        = SetIconFileBits(BinBasColumn)
                                          TVPROBLEM(0)
                                      
                                      END FUNCTION

                                      Comment


                                      • #20
                                        Thanks, Chris.

                                        Where I am so far. I changed the 12x12 to 32x32 and the problem stopped. The size of the icons where ridiculously big but it did not fail. I logged in at least 30 times and used the treeview navigating flawlessly to the called program. Maybe as Chris Boss says, my xp installation was corrupting the icons.

                                        Your code will be used, since I think it might be some insurance while adding more eye candy to what is a somewhat plain jane interface.

                                        I've been trying to convince the boss about the WinLife package for at least a year. She thinks the demo is too intense.

                                        This treeview spruce up of the text menu system is my first step. Hopefully I can try some or all of the suggestions and get the answer to reliably using the icons with a treeview.

                                        Bob Mechler

                                        Comment

                                        Working...
                                        X