PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Rolf Brandt on February 09, 2012, 07:47:57 AM

Title: Icon in Tabcontrol
Post by: Rolf Brandt on February 09, 2012, 07:47:57 AM
How can I assign / change an icon to a Tabcontrol at runtime?

Background: One of the Tabs contains a listview which is populated from a database. Whenever a change occurs the icon should change to alert the user.

Rolf
Title: Re: Icon in Tabcontrol
Post by: Rolf Brandt on February 12, 2012, 02:53:18 AM
No idea anybody?
Title: Re: Icon in Tabcontrol
Post by: Paul Squires on February 12, 2012, 08:35:57 AM
Hi Rolf, I am still travelling. Will get home tonight around midnight. I should be able to help tomorrow. Maybe try checking the generated source for how FF assigns icons to the tabs.
Title: Re: Icon in Tabcontrol
Post by: Rolf Brandt on February 12, 2012, 09:55:57 AM
Thanks Paul.
Title: Re: Icon in Tabcontrol
Post by: Elias Montoya on February 12, 2012, 05:38:48 PM

I didnt saw this before, I would have suggested probably the same as paul. :)
Title: Re: Icon in Tabcontrol
Post by: Rolf Brandt on February 13, 2012, 06:07:46 AM
This is what I did so far:
1. I assigned an image to the TabControl in the Designer.
2. At the end of the  FormCreate event I get the hWnd of the associated imagelist and add two more imagages.


   ihwnd = TabCtrl_GetImageList(HWND_FRMMAIN_TABCONTROL1)
   indx = ImageList_AddIcon (hWndITabCtrl, LoadIcon (App.hInstance, "IMAGE_RED16"))
   indx = ImageList_AddIcon (hWndITabCtrl, LoadIcon (App.hInstance, "IMAGE_BLUE16"))


3. Try to set the image index to another image. (From Josè's Wrappers)


r = TabCtrl_SetImageIndex(HWND_FRMMAIN_TABCONTROL1, 1)

At compile time I get this error:
"Parameter mismatches definition"

Rolf

Title: Re: Icon in Tabcontrol
Post by: José Roca on February 13, 2012, 08:51:51 AM
Quote
Code: [Select]
r = TabCtrl_SetImageIndex(HWND_FRMMAIN_TABCONTROL1, 1)
At compile time I get this error:
"Parameter mismatches definition"

There is a third parameter that I have forgot to include in the documentation:
iImage - Zero-based index in the tab control's image list, or -1 if there is no image for the tab.
Title: Re: Icon in Tabcontrol
Post by: Rolf Brandt on February 13, 2012, 09:07:28 AM
OK, my code so far is:


         Local r As Long
         Local ihwnd As Dword
         Local TabTcItem   As TC_ITEM
         Local ztmp        As Asciiz * %MAX_PATH
         ihwnd = TabCtrl_GetImageList(HWND_FRMMAIN_TABCONTROL1)
         r = TabCtrl_SetImageIndex(HWND_FRMMAIN_TABCONTROL1,0,ihwnd)
         TabTcItem.iImage = 0
         TabCtrl_SetItem(HWND_FRMMAIN_TABCONTROL1, 1, TabTcItem)


Unfortunately it just erases the icon from the TabControl.

???
Title: Re: Icon in Tabcontrol
Post by: José Roca on February 13, 2012, 09:40:06 AM
The code is incorrect. You have to build an image list with images for each tab page and set the imagelist with TabCtrl_SetImageList.

If you have done it, the 3rd parameter in TabCtrl_SetImageIndex is not the handle of the image listm but the zero-based index of the image in the image list.

That is, you have to pass the handle of the tab control, the zero-based index of the tab and the zero based-index of the image in the image list.
Title: Re: Icon in Tabcontrol
Post by: Rolf Brandt on February 13, 2012, 09:43:10 AM
OK, understood. But is it possible to change the image for Tab0 at runtime?

Rolf
Title: Re: Icon in Tabcontrol
Post by: José Roca on February 13, 2012, 11:38:50 AM
With

TabCtrl_SetImageIndex(HWND_FRMMAIN_TABCONTROL1,0,iImage)

where iImage is the zero-based index of the image in the image list you have set for the tab control.
Title: Re: Icon in Tabcontrol
Post by: Rolf Brandt on February 13, 2012, 11:46:03 AM
Yep - Works now.
Thanks a lot, Josè!

Rolf