Image List

From: Douglas Reid <douglas.reid_at_dunvegan.co.uk>
Date: Thu, 6 May 2010 08:04:37 +0100

Hello All,
I'm trying to create an image list which can thereafter be used in e.g., a ListView.

The call to ImageList_Add fails no matter how I try to previously load the image that is passed to it.

ImageList_Create appears to be returning a handle to an image list.
Apart from variant 4, use of LoadImage or LoadIcon appears to be returning a handle to an image.
Thus, it seems that the problem is with ImageList_Add or what is being passed to it being inappropriate in some way (perhaps an incompatible with the previously created image list?).

cat.ico is a 32 x 32 file (it came with a Microsoft example).
To make it easy to find by the programme, it is located in the same directory.
On that basis, is it okay to just use Z" cat.ico" ? Or, do I need to specify a full path name?
I also copied to the root directory and tried as: Z" c:\cat.ico"

I tried also the alternatives of LoadIcon and the more general LoadImage which has superceded it.

For other variants, I tried using predefined names such as OBM_RGARROW
(These can be seen at the bottom of http://msdn.microsoft.com/en-us/library/ms648045(v=VS.85).aspx )

Books and Microsoft examples generally show use of MAKEINTRESOURCE to prepare an integer in some way such that it is appropriate to pass to LoadIcon, etc.
My understanding is that this just ensures that the upper 16 bits are zeros.

Petzold in Chapter 10, "Programming Windows 95" explains about resource files by which icons and images can be made available to a programme.
This relates to C-programming and involves stuff being in files such as resource.h and I am unable to understand how a similar approach could be used in SwiftForth.

My variant 4 was clearly doomed to failure since something like 500 CONSTANT CAT_ICO could only be meaningful if provided in a certain context such as in a "resource file" of some sort. Otherwise any constant in a programme could be inappropriately linked to an icon or image file that happens to have the same number.

SwiftForth itself uses NULL 101 LoadIcon
i.e., the constant 101 relates to the SwiftForth logo icon.

How could one similarly relate constants to one's own icons e.g., 500 being associated with cat.ico to result in a cat being seen?!

sf.ico can't be found as a separate file so presumably has been integrated into the exe file in some way?
How could one do similarly in an own application with cat.ico ?

Best Regards,
Douglas

{ --------------------------------------------------------------------
ImageListB.f

Infrastructure to support collections of images of same size,
each of which can be referred to by its index.
Used by ListView, TreeView and other controls

---------------------------------------------------------------------- }
\ Function: MAKEINTRESOURCE ( wInteger -- res ) \ "Not found" (note that this is a Windows macro)
\ Implementation of a Windows macro of same name:
: MAKEINTRESOURCE ( n -- n')
   $0000FFFF AND
   ;

\ ImageList_Create function. Creates a new image list.
\ HIMAGELIST ImageList_Create(
\ int cx,
\ int cy,
\ UINT flags,
\ int cInitial,
\ int cGrow
\ );

Function: ImageList_Create ( cx cy flags cInitial cGrow -- res )

\ 0 ILC_COLOR
\ 4 ILC_COLOR4
\ 8 ILC_COLOR8
\ 16 ILC_COLOR16
\ 24 ILC_COLOR24
\ 32 ILC_COLOR32
\ 254 ILC_COLORDDB
\ 1 ILC_MASK
\ ? ILC_MIRROR
\ ? ILC_PERITEMMIRROR

\ --------------------------------------------------------------------
\ ImageList_Add Function Adds an image or images to an image list.
\ Copyint ImageList_Add(
\ __in HIMAGELIST himl,
\ __in HBITMAP hbmImage,
\ __in_opt HBITMAP hbmMask
\ );

Function: ImageList_Add ( himl hbmImage hbmMask -- res )

\ --------------------------------------------------------------------
\ LoadImage Function
\ Loads an icon, cursor, animated cursor, or bitmap.
\ CopyHANDLE LoadImage(
\ __in HINSTANCE hinst,
\ __in LPCTSTR lpszName,
\ __in UINT uType,
\ __in int cxDesired,
\ __in int cyDesired,
\ __in UINT fuLoad
\ );

Function: LoadImage ( hinst lpszName uType cxDesired cyDesired fuLoad -- res )

\ uType:
\ 0 IMAGE_BITMAP
\ 2 IMAGE_CURSOR
\ 1 IMAGE_ICON

\ fuLoad:
\ 0 LR_DEFAULTCOLOR
\ 8192 LR_CREATEDIBSECTION
\ 64 LR_DEFAULTSIZE
\ 16 LR_LOADFROMFILE
\ 4096 LR_LOADMAP3DCOLORS
\ 32 LR_LOADTRANSPARENT
\ 1 LR_MONOCHROME
\ 32768 LR_SHARED
\ 128 LR_VGACOLOR

32751 CONSTANT OBM_RGARROW

\ --------------------------------------------------------------------
NULL VALUE hImageList \ Image list handle
NULL VALUE hImage \ Image handle
NULL VALUE ImageIndex \ Index of image added to ImageList

500 CONSTANT CAT_ICO
501 CONSTANT DOG_ICO
502 CONSTANT FISH_ICO

: InitListViewImageList ( -- )
   32 32 ( cx cy)
   ILC_COLOR ( cx cy flags)
   \ ILC_COLOR32 ( cx cy flags)
   3 0 ( cx cy flags cInitial=3 cGrow=0) \ Increase numbers if more to be added!
   ImageList_Create ( hImageList|null)
   DUP TO hImageList

\ { ------- Variant 1 -------------------------------------------------
   NULL ( hImageList hinst=NULL)
   \ Z" cat" ( hImageList hinst Zaddr)
   \ Z" cat.ico" ( hImageList hinst Zaddr)
   Z" c:\cat.ico" ( hImageList hinst Zaddr)
   IMAGE_ICON ( hImageList hinst Zaddr uType)
   \ IMAGE_BITMAP
   0 0 ( hImageList hinst Zaddr uType cxDesired cyDesired)
   \ 32 32
   LR_LOADFROMFILE ( hImageList hinst Zaddr uType cxDesired cyDesired fuLoad)
   \ LR_SHARED OR
   LoadImage ( hImageList hImage|null)
\ -------------------------------------------------------------------- }

{ ------- Variant 2 -------------------------------------------------
   NULL ( hImageList hinst=NULL)
   OBM_RGARROW ( hImageList hinst=NULL n)
   \ MAKEINTRESOURCE ( hImageList hinst=NULL n')
   IMAGE_BITMAP ( hImageList hinst=NULL n' uType)
   0 0 ( hImageList hinst Zaddr uType cxDesired cyDesired)
   \ 32 32
   LR_LOADFROMFILE ( hImageList hinst Zaddr uType cxDesired cyDesired fuLoad)
   LR_SHARED OR
   LoadImage ( hImageList hImage|null)
-------------------------------------------------------------------- }

{ -------- Variant 3 -----------------------------------------------
   NULL
   IDI_APPLICATION
   MAKEINTRESOURCE
   LoadIcon
-------------------------------------------------------------------- }

{ ---------- Variant 4 ------------------------------------------------
   \ Unsurprisingly, this fails (returns 0):
   NULL
   CAT_ICO MAKEINTRESOURCE
   LoadIcon
-------------------------------------------------------------------- }

{ ---------- Variant 5 --------------------------------------------
   \ SwiftForth manual page 133:
   NULL
   101
   \ MAKEINTRESOURCE
   LoadIcon
---------------------- ---------------------------------------------- }

   DUP TO hImage

   NULL ( hImageList hImage NULL)
   ImageList_Add ( index|-1)
   TO ImageIndex \ Returning -1 :-(
   CR
   CR ." Value of hImageList: " hImageList . CR
   CR ." Value of hImageList: " hImage . CR
   CR ." Value of ImageIndex: " ImageIndex . CR

   \ Now should use DeleteObject:
   \ hImage DeleteObject DROP

   \ Now load and add next image to the image list ...
   ;

CR
CR .( Type InitListViewImageList to run.)
CR

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and
bug reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Thu May 06 2010 - 00:05:13 PDT


Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!

This archive was generated 06-Feb-2012. Archive updated nightly.