Problem with imagelists in a Toolbar, seemable false indexes

Windows specific forum
Franky
Enthusiast
Enthusiast
Posts: 213
Joined: Sat Apr 26, 2003 2:58 pm

Problem with imagelists in a Toolbar, seemable false indexes

Post by Franky »

Hi, sorry for enerving you :wink:

I hope, it´s the right place here, there a many apis in the source, so I´ve put it here

I tried to create a "blinking" toolbar, changing the image of a toolbarbutton every second with help of a timer.
For this I used tb_addbitmap to add an image to the list.
Normaly, it should return the index in the imagelist but it returns a wrong worth, as it seems.

Here´s the code:

Code: Select all

Global toolbar_id.l
Dim Imgs(1)


Procedure ErrorTimer()
          Static error.b
                error=1-error
                SendMessage_(toolbar_id,#tb_changebitmap,5,Imgs(error)) 
         ProcedureReturn 1
EndProcedure


;Creating the toolbaricons and drawing different colored circles
For a=0 To 6
      CreateImage(a,16,16)
Next

UseImage(0)
StartDrawing(ImageOutput())
      FrontColor(255,255,255)
          Circle(8,8,8) 
StopDrawing()


UseImage(1)
StartDrawing(ImageOutput())
      FrontColor(255,0,0)
          Circle(8,8,8) 
StopDrawing()

UseImage(2)
StartDrawing(ImageOutput())
      FrontColor(0,255,0)
          Circle(8,8,8) 
StopDrawing()

UseImage(3)
StartDrawing(ImageOutput())
      FrontColor(0,0,255)
          Circle(8,8,8) 
StopDrawing()

UseImage(4)
StartDrawing(ImageOutput())
      FrontColor(255,255,0)
          Circle(8,8,8) 
StopDrawing()

UseImage(5)
StartDrawing(ImageOutput())
      FrontColor(255,0,255)
          Circle(8,8,8) 
StopDrawing()

UseImage(6)
StartDrawing(ImageOutput())
      FrontColor(0,0,255)
          Circle(8,8,8) 
StopDrawing()

If OpenWindow(1,300,400,200,60,#PB_Window_SystemMenu,"Toolbarproblem")
             toolbar_id=CreateToolBar(1,WindowID())
                       For a=0 To 5 
                              ToolBarImageButton(a,UseImage(a))
                       Next 
                      egal.tbaddbitmap
                      egal\Hinst=0
                      egal\nID=UseImage(6) 
                      Imgs(1)=SendMessage_(toolbar_id,#tb_getbitmap,5,0) 
                      Imgs(0)=SendMessage_(toolbar_id,#tb_addbitmap,1,egal) 
                      SetTimer_(WindowID(1),0,1000,@ErrorTimer())
                      Repeat
                            event=WaitWindowEvent()
                      Until event=#WM_CLOSE
EndIf
End                  

Normaly, there should be first a pink and than a blue circle, but
there is a pink and than a white one :?

Anyone who can help me?
Give Up everything but trying!
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

I think you need to take into account the 14 default images in the ToolBar image list. By moving some things around and adding some code to your For..Next loop, it works fine. :)

Code: Select all

Global toolbar_id.l 
Dim Imgs(1) 


Procedure ErrorTimer() 
  Static error.b 
  error=1-error 
  SendMessage_(toolbar_id,#tb_changebitmap,5,Imgs(error)) 
  ProcedureReturn 1 
EndProcedure 


;Creating the toolbaricons and drawing different colored circles 
For a=0 To 6 
  CreateImage(a,16,16) 
Next 

UseImage(0) 
StartDrawing(ImageOutput()) 
FrontColor(255,255,255) 
Circle(8,8,8) 
StopDrawing() 


UseImage(1) 
StartDrawing(ImageOutput()) 
FrontColor(255,0,0) 
Circle(8,8,8) 
StopDrawing() 

UseImage(2) 
StartDrawing(ImageOutput()) 
FrontColor(0,255,0) 
Circle(8,8,8) 
StopDrawing() 

UseImage(3) 
StartDrawing(ImageOutput()) 
FrontColor(0,0,255) 
Circle(8,8,8) 
StopDrawing() 

UseImage(4) 
StartDrawing(ImageOutput()) 
FrontColor(255,255,0) 
Circle(8,8,8) 
StopDrawing() 

UseImage(5) 
StartDrawing(ImageOutput()) 
FrontColor(255,0,255) 
Circle(8,8,8) 
StopDrawing() 

UseImage(6) 
StartDrawing(ImageOutput()) 
FrontColor(0,0,255) 
Circle(8,8,8) 
StopDrawing() 

If OpenWindow(1,300,400,200,60,#PB_Window_SystemMenu,"Toolbarproblem") 
  toolbar_id=CreateToolBar(1,WindowID())
  egal.TBADDBITMAP 
  egal\Hinst=0 
  For a=0 To 5 
    ; -->  There are 14 default images, so add new images to ToolBar image list
    egal\nID=UseImage(a)
    SendMessage_(toolbar_id,#tb_addbitmap,1,egal)
    ToolBarImageButton(a,UseImage(a)) 
    FreeImage(a)
  Next 
  ; --> And add our additional Blue circle
  egal\nID=UseImage(6) 
  SendMessage_(toolbar_id,#tb_addbitmap,1,egal)
  FreeImage(6)
  Imgs(1)=SendMessage_(toolbar_id,#tb_getbitmap,5,0) 
  Imgs(0)=SendMessage_(toolbar_id,#tb_addbitmap,1,egal) 
  SetTimer_(WindowID(1),0,1000,@ErrorTimer()) 
  Repeat 
    event=WaitWindowEvent() 
  Until event=#WM_CLOSE 
EndIf 
End                  
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply