It is currently Wed Jun 19, 2013 6:53 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Change toolbar toggleitem image?
PostPosted: Sat Apr 02, 2011 5:00 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3013
If I have a toolbar item that is a toggle, is there a way to change the image in toggle on and toggle off mode?

Since it isn't a gadget, setgadgetstate with an imageid doesn't work to change the image on it.

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Change toolbar toggleitem image?
PostPosted: Sat Apr 02, 2011 12:10 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 1506
Hi Fangles
As a start

# 1
Code:
If OpenWindow(1,300,400,200,60,"Toolbarproblem",#PB_Window_SystemMenu)
  TB = CreateToolBar(1,WindowID(1))
 
    ToolBarStandardButton(0, #PB_ToolBarIcon_New)
    ToolBarSeparator()
    ToolBarStandardButton(1, #PB_ToolBarIcon_Cut,#PB_ToolBar_Toggle)   
    ToolBarSeparator()

  Repeat
    Event = WaitWindowEvent()

    Select Event
   
      Case #PB_Event_Menu
        Select EventMenu()
          Case 1
            If Run = 1
              SendMessage_(TB,#TB_CHANGEBITMAP,1,1)
            Else
              SendMessage_(TB,#TB_CHANGEBITMAP,1,3)
            EndIf
            Run = Run ! 1
        EndSelect
     
      Case #PB_Event_CloseWindow
        Quit = 1
       
    EndSelect

  Until Quit = 1
EndIf
End       



# 2
Code:
Dim Img(2)

For x=0 To 2
  CreateImage(x,16,16)
Next

StartDrawing(ImageOutput(0))
Box(0, 0, 16,16,$0779F8)
StopDrawing()

StartDrawing(ImageOutput(1))
Box(0, 0, 16,16,$0103FE)
StopDrawing()

StartDrawing(ImageOutput(2))
Box(0, 0, 16,16,$FC0203)
StopDrawing()

If OpenWindow(0,300,400,200,60,"Toolbar Images",#PB_Window_SystemMenu)
  TB = CreateToolBar(0,WindowID(0))
  For x=0 To 2
    ToolBarImageButton(x,ImageID(x))
  Next
   
Img(0)=SendMessage_(TB,#TB_GETBITMAP,1,0)
Img(1)=SendMessage_(TB,#TB_GETBITMAP,2,0)

Repeat
    Event = WaitWindowEvent()

    Select Event
   
      Case #PB_Event_Menu
        Select EventMenu()
          Case 1
            If Run = 1
              SendMessage_(TB,#TB_CHANGEBITMAP,1,Img(0))
            Else
              SendMessage_(TB,#TB_CHANGEBITMAP,1,Img(1))
            EndIf
            Run = Run ! 1
        EndSelect
     
      Case #PB_Event_CloseWindow
        Quit = 1
       
    EndSelect

  Until Quit = 1
EndIf
End       


_________________
Egypt my love


Top
 Profile  
 
 Post subject: Re: Change toolbar toggleitem image?
PostPosted: Sat Apr 02, 2011 12:14 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3013
Thank you RASHAD, it seems as if you are always rescuing me lately.:):):)

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Change toolbar toggleitem image?
PostPosted: Sat Apr 02, 2011 12:39 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 1506
Fangles
I told you before that I am in debt :)
I will stop when I will get balanced
Do not worry :)

_________________
Egypt my love


Top
 Profile  
 
 Post subject: Re: Change toolbar toggleitem image?
PostPosted: Sat Apr 02, 2011 12:46 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3013
RASHAD wrote:
Fangles
I told you before that I am in debt :)
I will stop when I will get balanced
Do not worry :)


Thanks...Do you need a dumb slave to do things for you? (grin). brain is small but available:):):)

/me falls off the chair.

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Change toolbar toggleitem image?
PostPosted: Sun Feb 19, 2012 5:38 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3013
Damnit, my old posts are embarrasing when I don't remember them

Rashad, is there a way to use a toggle toolbar button such as:

ToolBarImageButton(#ToolBar, ImageID(MyImage), #PB_ToolBar_Toggle)

With an image from CatchImage/DataSection ? (I'm sure I saw something somewhere and cannot find it)

This is how I normally have my images.

Enumeration 1
#Image_addresses_switchon
#Image_addresses_switchoff
EndEnumeration

CatchImage(#switchon, ?_switchon)
CatchImage(#switchoff, ?_switchoff)

DataSection
_switchon : IncludeBinary "LedGreenOn16x16.ico"
_switchoff : IncludeBinary "LedGreenOff16x16.ico"
EndDataSection

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Change toolbar toggleitem image?
PostPosted: Sun Feb 19, 2012 9:28 am 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 1506
Hi Fangles
Long time no talking to you
Hope you are in a good shape old man, and your Lady too

Code:
 #TB_SETLISTGAP = #WM_USER+96
;
Enumeration 1
#switchoff
#switchon
EndEnumeration

CatchImage(#switchoff, ?_switchon)
CatchImage(#switchon, ?_switchoff)

Procedure MAKELONG(low, high)
  ProcedureReturn low | (high<<16)
EndProcedure


If OpenWindow(0,0,0,800,600,"Toolbar Change Images",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  TB = CreateToolBar(0,WindowID(0)) 
 
  SendMessage_(TB, #TB_SETBUTTONSIZE, 0, MAKELONG(40,32))            ;MAKELONG(Width,Height) of Button
  SendMessage_(TB, #TB_AUTOSIZE, 0, 0)
  SendMessage_(TB,#TB_SETINDENT,10,0)                                ;Set Indent
  SendMessage_(TB,#TB_SETLISTGAP,100,0)
 
  ToolBarImageButton(1,ImageID(#switchoff),#PB_ToolBar_Toggle)
 
  iHwnd = SendMessage_(TB, #TB_GETIMAGELIST, 0, 0)
  index0=ImageList_AddIcon_(iHwnd,ImageID(#switchoff))
  index1=ImageList_AddIcon_(iHwnd,ImageID(#switchon)) 
 
Repeat
    Event = WaitWindowEvent()

    Select Event
   
      Case #PB_Event_Menu
        Select EventMenu()
          Case 1             
               SendMessage_(TB,#TB_CHANGEBITMAP,1,index0+GetToolBarButtonState(0, 1))
               
          Case 2
               
               
        EndSelect
     
      Case #PB_Event_CloseWindow
        Quit = 1
       
    EndSelect

  Until Quit = 1
EndIf
End


DataSection
_switchon : IncludeBinary "LedGreenOn16x16.ico"
_switchoff : IncludeBinary "LedGreenOff16x16.ico"
EndDataSection       


_________________
Egypt my love


Top
 Profile  
 
 Post subject: Re: Change toolbar toggleitem image?
PostPosted: Sun Feb 19, 2012 11:50 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3013
Thanks RASHAD, you've saved me again. And for once, I actually understand the solution (been a long time coming..)

As for the rest, PM has been sent to explain things.

Thanks once again.

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye