Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

ListView with ImageList - SDK

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

  • ListView with ImageList - SDK

    please post discussions at:
    http://www.powerbasic.com/support/pb...ead.php?t=4225
    Code:
    '=============================================================================='
    '  listview demo with a imagelist sdk
    '  demonstrates creating and adding items to an listview control with icons
    '  please contact me at [email protected] if you have any questions
    '  
    '  this is entered into public domain by greg engle 4-28-01
    '============================================================================== 
    
    #compile exe
    #include "win32api.inc"
    #include "commctrl.inc"
    
    '#resource "c:\pbdll60\samples\tray\tray.pbr"
    #resource "d:\pbdll60\samples\tray\tray.pbr"
    
    %listview1 = 100
    
    function wndproc (byval hwnd as long, byval wmsg as long, _
                      byval wparam as long, byval lparam as long) export as long
        
        select case wmsg
            case %wm_destroy
                postquitmessage 0
        end select                           
    
    function = defwindowproc(hwnd, wmsg, wparam, lparam)
    end function
    
    function winmain (byval hinstance     as long, _
                      byval hprevinstance as long, _
                      lpcmdline           as asciiz ptr, _
                      byval icmdshow      as long) as long
       
      local rect as rect
      local msg         as tagmsg
      local wndclass    as wndclassex
      local szclassname as asciiz * 80
      local hwnd        as long
      local sziconname  as asciiz * 12
      local column as lv_column
      local aztitle as asciiz * 25
      local imagelist as dword
      local lvitem as lv_item
      local azitemtext as asciiz * 25
      local cc1 as init_common_controlsex
    
      cc1.dwsize=sizeof(cc1)
      cc1.dwicc=%icc_win95_classes
      initcommoncontrolsex cc1
      
      szclassname            = "sdk_listview"
      wndclass.cbsize        = sizeof(wndclass)
      wndclass.style         = %cs_hredraw or %cs_vredraw
      wndclass.lpfnwndproc   = codeptr( wndproc )
      wndclass.cbclsextra    = 0
      wndclass.cbwndextra    = 0
      wndclass.hinstance     = hinstance
      wndclass.hicon         = loadicon( hinstance, "face1")
      wndclass.hcursor       = loadcursor( %null, byval %idc_arrow )
      wndclass.hbrbackground = getstockobject( %gray_brush )
      wndclass.lpszmenuname  = %null
      wndclass.lpszclassname = varptr( szclassname )
      wndclass.hiconsm       = 0
      registerclassex wndclass
      hwndmain& = createwindowex(%ws_ex_topmost, _
                              szclassname, _              
                              "sample listview with imagelist example", _         
                              %ds_center _
                              or %ws_caption  _
                              or %ws_sysmenu , _          
                              0, _                       
                              0, _                       
                              700&, _                    
                              300&, _                    
                              %null, _                   
                              %null, _                   
                              hinstance, _               
                              byval %null)
      
      getclientrect hwndmain&, rect
      
      hlistview& = createwindow ( "syslistview32", _
                            ", _
                            %ws_border or %ws_child or %ws_visible or _
                            %lvs_report or %lvs_singlesel or %lvs_showselalways, _
                            0, _
                            0, _
                            rect.nright - 1, _
                            rect.nbottom - 1, _
                            hwndmain&, _
                            %listview1, _
                            hinstance, _
                            %null ) 
                                                                  
       aztitle = "listview - imagelist"
       column.mask = %lvcf_fmt or %lvcf_width or  %lvcf_text or %lvcf_subitem
       column.fmt = %lvcfmt_left
       column.cx = 300
       column.psztext = varptr(aztitle)
       listview_insertcolumn hlistview&, 0, column 
       
       imagelist = imagelist_create (16, 16, %ilc_colorddb or %ilc_mask, 0, 1)
       hicon1& = loadimage (getmodulehandle(byval 0&), "face1", %image_icon, 16, 16, %lr_defaultcolor)
       hicon2& = loadimage (getmodulehandle(byval 0&), "face2", %image_icon, 16, 16, %lr_defaultcolor)
       hicon3& = loadimage (getmodulehandle(byval 0&), "face5", %image_icon, 16, 16, %lr_defaultcolor)
       imagelist_addicon imagelist, hicon1&
       imagelist_addicon imagelist, hicon2&
       imagelist_addicon imagelist, hicon3&
       
       listview_setimagelist hlistview&, imagelist, %lvsil_small     'this example is using only small icons, 
                                                                     'but you can create another imagelist with 32x32 icons and call
                                                                     'listview_setimagelist with %lvsil_normal and when the listview is in 
                                                                     'normal state it will show the bigger icons
       azitemtext = "test1"
       lvitem.iimage = 0 
       lvitem.iitem = listview_getitemcount(hlistview&) 
       lvitem.mask = %lvcf_fmt or %lvcf_width or  %lvcf_text or %lvcf_subitem 
       lvitem.statemask = %lvis_focused
       lvitem.psztext = varptr(azitemtext)
       lstatus& = listview_insertitem (hlistview&, lvitem)
      
       azitemtext = "test2"
       lvitem.iimage = 1 
       lvitem.iitem = listview_getitemcount(hlistview&) 
       lvitem.mask = %lvcf_fmt or %lvcf_width or  %lvcf_text or %lvcf_subitem 
       lvitem.statemask = %lvis_focused
       lvitem.psztext = varptr(azitemtext)
       lstatus& = listview_insertitem (hlistview&, lvitem)
       
       azitemtext = "test3"
       lvitem.iimage = 2 
       lvitem.iitem = listview_getitemcount(hlistview&) 
       lvitem.mask = %lvcf_fmt or %lvcf_width or  %lvcf_text or %lvcf_subitem 
       lvitem.statemask = %lvis_focused
       lvitem.psztext = varptr(azitemtext)
       lstatus& = listview_insertitem (hlistview&, lvitem)
       
       
      showwindow hwndmain&, icmdshow
      updatewindow hwndmain&
      
        while istrue getmessage(msg, %null, 0, 0)
            translatemessage msg
            dispatchmessage msg
        wend
        sleep 1
      function = msg.wparam
    
    end function
    ------------------
    -greg

    [this message has been edited by gregery d engle (edited april 28, 2001).]
    -Greg
    [email protected]
    MCP,MCSA,MCSE,MCSD
Working...
X