Icon in Tabcontrol

Started by Rolf Brandt, February 09, 2012, 07:47:57 AM

Previous topic - Next topic

Rolf Brandt

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
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

Rolf Brandt

Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

Paul Squires

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.
Paul Squires
PlanetSquires Software

Rolf Brandt

#3
Thanks Paul.
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

Elias Montoya


I didnt saw this before, I would have suggested probably the same as paul. :)
Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Rolf Brandt

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

Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

José Roca

#6
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.

Rolf Brandt

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.

???
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

José Roca

#8
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.

Rolf Brandt

OK, understood. But is it possible to change the image for Tab0 at runtime?

Rolf
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

José Roca

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.

Rolf Brandt

Yep - Works now.
Thanks a lot, Josè!

Rolf
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)