Page 1 of 1

Set optional color in highlighted ButtonGadget/ButtonImage

Posted: Sun Jul 05, 2009 2:59 pm
by +18
When cursor is over of button, i need display my color instead common color in border.
sorry i don't know name of this area of button as exactly, it's shhow in below pic:

Image Click Image to Enlarge Image Hosting

Code: Select all

OpenWindow(0, 0, 0, 150, 100,"", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 

  ButtonGadget(0, 50, 35, 50, 30, "")

Repeat 
  ev=WaitWindowEvent() 
  
Until ev=#WM_CLOSE

Posted: Sun Jul 05, 2009 3:42 pm
by netmaestro
You could easily find yourself in the murky waters of ownerdraw here, but if you're sneaky you can play a trick to approximate it. It isn't perfect but it's close. Important: Only works with XP skins enabled. Your pic shows the button with skins enabled so this shouldn't limit you:

Code: Select all

#BCN_FIRST         = -1250 
#BCN_HOTITEMCHANGE = #BCN_FIRST+1 
#HICF_ENTERING     = 17 
#HICF_LEAVING      = 33 

Structure NMBCHOTITEM 
  hdr.NMHDR 
  flags.l 
EndStructure 

Procedure WinProc(hwnd, msg, wparam, lparam) 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_NOTIFY 
      *nmh.NMBCHOTITEM = lparam 
      If *nmh\hdr\hwndFrom = GadgetID(2) And *nmh\hdr\code = #BCN_HOTITEMCHANGE 
        Select *nmh\flags 
          Case #HICF_ENTERING 
            SetGadgetColor(0,#PB_Gadget_BackColor, #Red) 
          Case #HICF_LEAVING 
            SetGadgetColor(0,#PB_Gadget_BackColor, GetSysColor_(#COLOR_3DFACE)) 
        EndSelect 
      EndIf 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

OpenWindow(0, 0, 0, 150, 100,"", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
SetWindowCallback(@WinProc()) 

ContainerGadget(0,50,35,50,30) 
ContainerGadget(1,1,1,48,28) 
ButtonGadget(2, -1,-1, 50, 30, "")
CloseGadgetList() : CloseGadgetList()

Repeat 
  ev=WaitWindowEvent() 
  
Until ev=#PB_Event_CloseWindow 

Posted: Sun Jul 05, 2009 3:58 pm
by +18
Very nice sample, THX^1000000000000000000000000000000000000 :D
this code is perfect for my work and i don't need a complex owner draw code.
Only if it's possible, my optional color must cover on yellow border ???
have you a solution without owner drawing?

Re: Set optional color in highlighted ButtonGadget/ButtonIma

Posted: Sun Jul 05, 2009 4:00 pm
by Fluid Byte
+18 wrote:When cursor is over of button, i need display my color instead common color in border.
You must realize that this is not a color. It's the skin system of XP/Vista which uses bitmaps, not GDI with one colored simple shapes. You can not replace it unless you modify the image of the skin. You can only draw on top of it with GDI (which may be an image or 2D drawing).

I'd rather recommend to simply use pre-rendered images in combination with the ButtonImageGadget() which seems the easiest route.

Posted: Sun Jul 05, 2009 6:14 pm
by +18
OK Fluid Byte
THX for useful explanation