Set optional color in highlighted ButtonGadget/ButtonImage

Just starting out? Need help? Post your questions and find answers here.
+18
Enthusiast
Enthusiast
Posts: 228
Joined: Fri Oct 24, 2008 2:07 pm

Set optional color in highlighted ButtonGadget/ButtonImage

Post 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
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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 
BERESHEIT
+18
Enthusiast
Enthusiast
Posts: 228
Joined: Fri Oct 24, 2008 2:07 pm

Post 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?
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: Set optional color in highlighted ButtonGadget/ButtonIma

Post 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.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
+18
Enthusiast
Enthusiast
Posts: 228
Joined: Fri Oct 24, 2008 2:07 pm

Post by +18 »

OK Fluid Byte
THX for useful explanation
Post Reply