FadingButtonPanel als Include mit Skins

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
legion
Beiträge: 467
Registriert: 08.10.2006 18:04
Computerausstattung: Intel Core i5-6500 @ 4x 3.6GHz mit Windows 10 Pro, Intel Core-i7 mit Ubuntu 18.04 bionic, x86_64 Linux 4.18.0-16-generic, Microsoft Surface Pro - Windows 10 Pro
Wohnort: Wien
Kontaktdaten:

FadingButtonPanel als Include mit Skins

Beitrag von legion »

Hallo !

Hier mal wieder eine kleine Spielerei von mir.
Die 3 Timer Lösung ist sicher nicht optimal, aber mir ist nichts
besseres eingefallen.

Ich betrachte die Include als unfertig, trotzdem möchte ich sie euch
nicht vorenthalten. Vielleicht kann ja der eine oder andere was aus
diesem Source brauchen oder findet Zeit die Include zu verbessern.

Lg. Legion

Download FadingButtonPanel Demo und Skins

Bild

Include:

Code: Alles auswählen

Prototype AlphaBlend(DestDC,x1,y1,w1,h1,SourceDC,x2,y2,w2,h2,BF)
Msimg32 = OpenLibrary(#PB_Any, "msimg32.dll")
If Msimg32
 Global AlphaBlend_.AlphaBlend = GetFunction(msimg32, "AlphaBlend")
EndIf 

;EnableExplicit

#TME_HOVER       = 1
#TME_LEAVE       = 2
#TRUE_COLOR      = 24
#AC_SRC_OVER     = 0
#AC_SRC_ALPHA    = 1

Enumeration
 #GroundPicture
 #HoverPicture
 #DownPicture
 #TempImage
 #Temp_Hover_Image
 #Temp_Ground_Image
 #Temp_Down_Image
 #Fader1_1_Image
 #Fader1_2_Image
 #Fader2_1_Image
 #Fader2_2_Image
 #Fader3_1_Image
 #Fader3_2_Image
EndEnumeration

Structure FBSTRUCT ; Eigenschaften eines FadingButtons
 FBHwnd.l
 FBText.s 
 FBDisable.b
 FBIcon.l
EndStructure

Structure MMTRACKMOUSEEVENT
 cbSize.l
 dwFlags.l
 hwndTrack.l
 dwHoverTime.l
EndStructure

Global *mywnd_FBP.CWPSTRUCT
Global myRect_FBP.RECT
Global *mymsg_FBP.MSG
Global PB_Callback_intern
Global Dim FBA.FBSTRUCT(5)
Global HWND_FBP,Grundcontainer,Weite_FBP,Oben_FBP,Links_FBP,WndProcHook_FBP,BCounter
Global Unten_FBP,MsgProcHook_FBP,ox,oy,oh,ContainerWidth,ButtonOffset,AllButtonHight,ButtonHeight,ButtonWidth 
Global FadeInHWND1,FadeOutHWND1,FadeInHWND2,FadeOutHWND2,FadeInHWND3,FadeOutHWND3
Global Timer1Aktiv.b,Timer2Aktiv.b,Timer3Aktiv.b,Skin

Procedure CreateAllGroundPictures(Width,Height)
 Protected SkinImage,ImageDC,TempDC
 Protected x1=2,y1=2,w1=78,h1=41,x2=2,y2=44,w2=78,h2=83,x3=2,y3=87,w3=78,h3=126
 
 If     Skin = $3D3D3D : SkinImage = CatchImage(#PB_Any,?SKIN1)
 ElseIf Skin = $FDFDFD : SkinImage = CatchImage(#PB_Any,?SKIN2)
 ElseIf Skin = $E0E0E0 : SkinImage = CatchImage(#PB_Any,?SKIN3)
 ElseIf Skin = $FDE8D5 : SkinImage = CatchImage(#PB_Any,?SKIN4)
 ElseIf Skin = $D4D4D4 : SkinImage = CatchImage(#PB_Any,?SKIN5)
 ElseIf Skin = $FFFFFF : SkinImage = CatchImage(#PB_Any,?SKIN6)
 Else
  SkinImage = CatchImage(#PB_Any,?SKIN1)
 EndIf  
 
 
 CreateImage(#GroundPicture,Width,Height,#TRUE_COLOR)
 CreateImage(#HoverPicture,Width,Height,#TRUE_COLOR)
 CreateImage(#DownPicture,Width,Height,#TRUE_COLOR)
 CreateImage(#TempImage,Width,Height,#TRUE_COLOR)
 CreateImage(#Temp_Hover_Image,Width,Height,#TRUE_COLOR)
 CreateImage(#Temp_Ground_Image,Width,Height,#TRUE_COLOR)
 CreateImage(#Temp_Down_Image,Width,Height,#TRUE_COLOR)
 CreateImage(#Fader1_1_Image,Width,Height,#TRUE_COLOR)
 CreateImage(#Fader1_2_Image,Width,Height,#TRUE_COLOR)
 CreateImage(#Fader2_1_Image,Width,Height,#TRUE_COLOR)
 CreateImage(#Fader2_2_Image,Width,Height,#TRUE_COLOR)
 CreateImage(#Fader3_1_Image,Width,Height,#TRUE_COLOR)
 CreateImage(#Fader3_2_Image,Width,Height,#TRUE_COLOR)
  
 ImageDC = StartDrawing(ImageOutput(#GroundPicture))
 TempDC  = CreateCompatibleDC_(ImageDC)
 SelectObject_(TempDC,ImageID(SkinImage))
 
 BitBlt_(ImageDC,0,0,5,Height,TempDC,x1,y1,#SRCCOPY);linke Bildseite
 StretchBlt_(ImageDC,5,0,Width-10,Height,TempDC,w1/2,y1,1,Height,#SRCCOPY);mittlerer Teil
 BitBlt_(ImageDC,Width-5,0,5,Height,TempDC,w1-4,y1,#SRCCOPY);rechte Bildseite (Knopf) 
 StopDrawing()
 
 ImageDC = StartDrawing(ImageOutput(#HoverPicture))
 SelectObject_(TempDC,ImageID(SkinImage))
 
 BitBlt_(ImageDC,0,0,5,Height,TempDC,x2,y2,#SRCCOPY);linke Bildseite
 StretchBlt_(ImageDC,5,0,Width-10,Height,TempDC,w2/2,y2,1,Height,#SRCCOPY);mittlerer Teil
 BitBlt_(ImageDC,Width-5,0,5,Height,TempDC,w2-4,y2,#SRCCOPY);rechte Bildseite (Knopf) 
 StopDrawing() 
 
 ImageDC = StartDrawing(ImageOutput(#DownPicture))
 SelectObject_(TempDC,ImageID(SkinImage))
 
 BitBlt_(ImageDC,0,0,5,Height,TempDC,x3,y3,#SRCCOPY);linke Bildseite
 StretchBlt_(ImageDC,5,0,Width-10,Height,TempDC,w3/2,y3,1,Height,#SRCCOPY);mittlerer Teil
 BitBlt_(ImageDC,Width-5,0,5,Height,TempDC,w3-4,y3,#SRCCOPY);rechte Bildseite (Knopf) 
 StopDrawing()  

 DeleteDC_(TempDC)
EndProcedure

Procedure CreateDownTextImage(hWnd)
 Protected i,TextColor,Text$,Icon
 If BCounter >= 1
  For i = 0 To BCounter -1
   If FBA(i)\FBHwnd = hWnd
    Text$ = FBA(i)\FBText
    Icon  = FBA(i)\FBIcon
   EndIf  
  Next i 
   
  If     Skin = $3D3D3D : TextColor = $000000
  ElseIf Skin = $FDFDFD : TextColor = $8B4C0F
  ElseIf Skin = $E0E0E0 : TextColor = $000000
  ElseIf Skin = $FDE8D5 : TextColor = $000000
  ElseIf Skin = $D4D4D4 : TextColor = $000000
  ElseIf Skin = $FFFFFF : TextColor = $000000
  Else
    TextColor = $000000
  EndIf
  
   CopyImage(#DownPicture,#Temp_Down_Image)   

   
   StartDrawing(ImageOutput(#Temp_Down_Image))
   DrawingMode(#PB_2DDrawing_Transparent)
   DrawingFont(FontID(0))
   If Icon <> 0
    DrawImage(Icon,6,5)
    DrawText(46,12,Text$,TextColor)
   Else
    DrawText(16,10,Text$,TextColor)
   EndIf  
   StopDrawing()  

 EndIf
EndProcedure

Procedure CreateHoverTextImage(hWnd)
 Protected i,TextColor,Text$,Icon
 If BCounter >= 1
  For i = 0 To BCounter -1
   If FBA(i)\FBHwnd = hWnd
    Text$ = FBA(i)\FBText
    Icon  = FBA(i)\FBIcon
   EndIf  
  Next i 
   
   CopyImage(#GroundPicture,#Temp_Ground_Image)
   CopyImage(#HoverPicture,#Temp_Hover_Image)
   
   If     Skin = $3D3D3D : TextColor = $FFFFFF
   ElseIf Skin = $FDFDFD : TextColor = $8B4C0F
   ElseIf Skin = $E0E0E0 : TextColor = $6C6C6C
   ElseIf Skin = $FDE8D5 : TextColor = $000000
   ElseIf Skin = $D4D4D4 : TextColor = $000000
   ElseIf Skin = $FFFFFF : TextColor = $000000
   Else
     TextColor = $FFFFFF
   EndIf   

   StartDrawing(ImageOutput(#Temp_Ground_Image))
   DrawingMode(#PB_2DDrawing_Transparent)
   DrawingFont(FontID(0))
   If Icon <> 0
    DrawImage(Icon,5,4)
    DrawText(45,11,Text$,TextColor)
   Else
    DrawText(15,11,Text$,TextColor)
   EndIf  
   StopDrawing()
   
   If     Skin = $3D3D3D : TextColor = $000000
   ElseIf Skin = $FDFDFD : TextColor = $8B4C0F
   ElseIf Skin = $E0E0E0 : TextColor = $000000
   ElseIf Skin = $FDE8D5 : TextColor = $000000
   ElseIf Skin = $D4D4D4 : TextColor = $000000
   ElseIf Skin = $FFFFFF : TextColor = $000000
   Else
     TextColor = $000000
   EndIf  
   
   StartDrawing(ImageOutput(#Temp_Hover_Image))
   DrawingMode(#PB_2DDrawing_Transparent)
   DrawingFont(FontID(0))
   If Icon <> 0
    DrawImage(Icon,5,4)
    DrawText(45,11,Text$,TextColor)
   Else
    DrawText(15,11,Text$,TextColor)
   EndIf 
   StopDrawing()    

 EndIf
EndProcedure

Procedure DrawLButtonDown(hwnd);Gedrückte Taste wird gezeichnet
 Protected ConDC,TempDC
   ConDC = GetDC_(hwnd)
   TempDC = CreateCompatibleDC_(ConDC)
   SelectObject_(TempDC,ImageID(#Temp_Down_Image))
   BitBlt_(ConDC,0,0,180,40,TempDC,0,0,#SRCCOPY)
   ReleaseDC_(HWND_FBP,ConDC) : DeleteDC_(TempDC)
EndProcedure

Procedure DrawLButtonUp(hwnd);Selektierte Taste wird gezeichnet
 Protected ConDC,TempDC
   ConDC = GetDC_(hwnd)
   TempDC = CreateCompatibleDC_(ConDC)
   SelectObject_(TempDC,ImageID(#Temp_Hover_Image))
   BitBlt_(ConDC,0,0,180,40,TempDC,0,0,#SRCCOPY)
   ReleaseDC_(HWND_FBP,ConDC) : DeleteDC_(TempDC)
EndProcedure

Procedure DrawGroundButton();Grundbild wird auf alle Tasten gezeichnet
 Protected i,ConDC,ImageDC,TempDC,TextColor
 If BCounter >= 1
  For i = 0 To BCounter -1   
  
   If     Skin = $3D3D3D : TextColor = $FFFFFF
   ElseIf Skin = $FDFDFD : TextColor = $8B4C0F
   ElseIf Skin = $E0E0E0 : TextColor = $6C6C6C
   ElseIf Skin = $FDE8D5 : TextColor = $000000
   ElseIf Skin = $D4D4D4 : TextColor = $000000
   ElseIf Skin = $FFFFFF : TextColor = $000000
   Else
     TextColor = $FFFFFF
   EndIf     

   CopyImage(#GroundPicture,#TempImage)
   StartDrawing(ImageOutput(#TempImage))
   DrawingMode(#PB_2DDrawing_Transparent)
   DrawingFont(FontID(0))
   If FBA(i)\FBIcon <> 0
    DrawImage(FBA(i)\FBIcon,5,4)
    DrawText(45,11,FBA(i)\FBText,TextColor)
   Else
    DrawText(15,11,FBA(i)\FBText,TextColor)
   EndIf   
   StopDrawing()
   ConDC = GetDC_(FBA(i)\FBHwnd)
   TempDC = CreateCompatibleDC_(ConDC)
   SelectObject_(TempDC,ImageID(#TempImage))
   BitBlt_(ConDC,0,0,180,40,TempDC,0,0,#SRCCOPY)
   ReleaseDC_(FBA(i)\FBHwnd,ConDC) : DeleteDC_(TempDC)
  Next i
 EndIf
EndProcedure

Procedure BlendImages(Hwnd,Image1,Image2,AlphaWert,AlphaFormat)
 Protected WinHDC,TempDC,BackImageID,NewImageHDC,BF,*BF.BLENDFUNCTION = @BF  
  *BF\BlendOp = #AC_SRC_OVER
  *BF\BlendFlags = 0
  *BF\SourceConstantAlpha = AlphaWert
  *BF\AlphaFormat = AlphaFormat
  WinHDC = GetDC_(Hwnd) : TempDC = CreateCompatibleDC_(WinHDC) 
  BackImageID = CreateImage(#PB_Any,ImageWidth(Image1),ImageHeight(Image1)) 
  NewImageHDC = StartDrawing(ImageOutput(BackImageID))
  SelectObject_(TempDC,ImageID(Image1))
  BitBlt_(NewImageHDC,0,0,ImageWidth(Image1),ImageHeight(Image1),TempDC,0,0,#SRCCOPY)  
  SelectObject_(TempDC,ImageID(Image2))
  AlphaBlend_(NewImageHDC,0,0,ImageWidth(Image1),ImageHeight(Image1),TempDC,0,0,ImageWidth(Image2),ImageHeight(Image2),BF)  
  StopDrawing()  
  SelectObject_(TempDC,ImageID(BackImageID))
  BitBlt_(WinHDC,0,0,ImageWidth(Image1),ImageHeight(Image1),TempDC,0,0,#SRCCOPY)
  ReleaseDC_(Hwnd,WinHDC) : DeleteDC_(TempDC) : FreeImage(BackImageID)
EndProcedure

Procedure Fading1()  
 Static FadeCounter,SHWND 
 If FadeInHWND1 <> 0
   SHWND = FadeInHWND1
   Timer1Aktiv = 1
   CopyImage(#Temp_Ground_Image,#Fader1_1_Image)
   CopyImage(#Temp_Hover_Image,#Fader1_2_Image)
   If Not FadeCounter >= 255
    BlendImages(FadeInHWND1,#Fader1_1_Image,#Fader1_2_Image,FadeCounter,0)
    FadeCounter+15
   EndIf
 EndIf

 If FadeOutHWND1 <> 0 Or (FadeInHWND1 = 0 And FadeCounter > 15)
   Timer1Aktiv = 1
   If Not FadeCounter <= 0  
    BlendImages(SHWND,#Fader1_1_Image,#Fader1_2_Image,FadeCounter,0)
    FadeCounter-15
   Else
    KillTimer_(WindowID(0),1)
    Timer1Aktiv = 0
    SHWND = 0
   EndIf 
 EndIf
EndProcedure

Procedure Fading2()  
 Static FadeCounter,SHWND

 If FadeInHWND2 <> 0
   SHWND = FadeInHWND2
   If Not FadeCounter >= 255
    Timer2Aktiv = 1
    CopyImage(#Temp_Ground_Image,#Fader2_1_Image)
    CopyImage(#Temp_Hover_Image,#Fader2_2_Image)
    BlendImages(FadeInHWND2,#Fader2_1_Image,#Fader2_2_Image,FadeCounter,0)
    FadeCounter+15
   EndIf
 EndIf

 If FadeOutHWND2 <> 0 Or (FadeInHWND2 = 0 And FadeCounter > 0)
   Timer2Aktiv = 1
   If Not FadeCounter <= 0  
    BlendImages(SHWND,#Fader2_1_Image,#Fader2_2_Image,FadeCounter,0)
    FadeCounter-15
   Else
    KillTimer_(WindowID(0),2)
    Timer2Aktiv = 0
    SHWND = 0
   EndIf 
 EndIf
EndProcedure

Procedure Fading3()  
 Static FadeCounter,SHWND
 
 If FadeInHWND3 <> 0
   SHWND = FadeInHWND3
   If Not FadeCounter >= 255
    Timer3Aktiv = 1
    CopyImage(#Temp_Ground_Image,#Fader3_1_Image)
    CopyImage(#Temp_Hover_Image,#Fader3_2_Image)
    BlendImages(FadeInHWND3,#Fader3_1_Image,#Fader3_2_Image,FadeCounter,0)
    FadeCounter+15
   EndIf
 EndIf

 If FadeOutHWND3 <> 0 Or (FadeInHWND3 = 0 And FadeCounter > 0)
   Timer3Aktiv = 1
   If Not FadeCounter <= 0  
    BlendImages(SHWND,#Fader3_1_Image,#Fader3_2_Image,FadeCounter,0)
    FadeCounter-15
   Else
    KillTimer_(WindowID(0),3)
    Timer3Aktiv = 0
    SHWND = 0
   EndIf 
 EndIf
EndProcedure

Procedure EraseBackground()
 If IsGadget(Grundcontainer)
  SetWindowPos_(GadgetID(Grundcontainer),#HWND_TOP,Links_FBP,Oben_FBP,ContainerWidth,Unten_FBP,0)
  If Unten_FBP < GetGadgetAttribute(Grundcontainer,#PB_ScrollArea_InnerHeight)
   ContainerWidth = 217
  Else
   ContainerWidth = 200
  EndIf
 EndIf
EndProcedure

Procedure Paint()
 If IsGadget(Grundcontainer)
 SetWindowPos_(GadgetID(Grundcontainer),#HWND_TOP,Links_FBP,Oben_FBP,ContainerWidth,Unten_FBP,0)
 EndIf
EndProcedure

Procedure GetPBCallback(HWND)
  ProcedureReturn GetClassLong_(HWND,#GCL_WNDPROC)
EndProcedure

Procedure CallWndProc_FBP(code,wParam,lParam); Sendmessage Hook
Protected WndProcHook_FBP
*mywnd_FBP = lParam 
 If *mywnd_FBP\hwnd = HWND_FBP
  If *mywnd_FBP\message = #WM_ERASEBKGND : EraseBackground() : EndIf
 EndIf
 ProcedureReturn CallNextHookEx_(WndProcHook_FBP,code,wParam,lParam)
EndProcedure

Procedure GetMsgProc_FBP(code,wParam,lParam); Postmessage Hook
 Protected i,MsgProcHook_FBP
 ;Mauspositionen und Fenstergroesse bestimmen
 *mymsg_FBP = lParam 
 If *mymsg_FBP\hwnd = HWND_FBP
  GetClientRect_(*mymsg_FBP\hwnd ,myRect_FBP)
  Weite_FBP = myRect_FBP\right - myRect_FBP\left : Links_FBP = myRect_FBP\left +ox
  Oben_FBP  = myRect_FBP\top +oy  : Unten_FBP = myRect_FBP\bottom - myRect_FBP\top -oh
  If *mymsg_FBP\message = #WM_PAINT : Paint() : EndIf   
  If *mymsg_FBP\message = #WM_NCMOUSELEAVE  
   If IsGadget(Grundcontainer)
    SetWindowPos_(GadgetID(Grundcontainer),#HWND_TOP,Links_FBP,Oben_FBP,ContainerWidth,Unten_FBP,0)
   EndIf
  EndIf 
 EndIf  
 ProcedureReturn CallNextHookEx_(MsgProcHook_FBP,code,wParam,lParam)
EndProcedure

Procedure MouseMove(hWnd)
Protected TMME.MMTRACKMOUSEEVENT 
 TMME\cbSize = SizeOf(MMTRACKMOUSEEVENT)
 TMME\dwFlags = #TME_LEAVE | #TME_HOVER
 TMME\dwHoverTime = 10
 TMME\hwndTrack = hWnd
 TrackMouseEvent_(TMME)
EndProcedure

Procedure FButton_Callback(hWnd,Msg,wParam,lParam) ; Callback fuer Container
 Static LastHwnd
  Select Msg    
    Case #WM_MOUSELEAVE
     If LastHwnd = hWnd : LastHwnd = 0 : EndIf
      FadeInHWND1  = 0
      FadeOutHWND1 = hwnd
      FadeInHWND2  = 0
      FadeOutHWND2 = hwnd     
      FadeInHWND3  = 0
      FadeOutHWND3 = hwnd  
          
    Case #WM_MOUSEHOVER    
      Timer1:
      If Timer1Aktiv : Goto Timer2 : EndIf      
       CreateHoverTextImage(hWnd)
       SetTimer_(HWND_FBP,1,10,@Fading1())
       FadeOutHWND1 = 0
       FadeInHWND1  = hwnd
       Goto ExitTimer
      Timer2:
      If Timer2Aktiv : Goto Timer3 : EndIf
       CreateHoverTextImage(hWnd)
       SetTimer_(HWND_FBP,2,10,@Fading2())
       FadeOutHWND2 = 0
       FadeInHWND2  = hwnd 
       Goto ExitTimer
      Timer3:
      If Timer3Aktiv : Goto ExitTimer : EndIf
       CreateHoverTextImage(hWnd)
       SetTimer_(HWND_FBP,3,10,@Fading3())
       FadeOutHWND3 = 0
       FadeInHWND3  = hwnd       
      ExitTimer:       
      ProcedureReturn 0 
     
    Case #WM_MOUSEMOVE     
     If LastHwnd <> hWnd : LastHwnd = hwnd : MouseMove(hWnd) : EndIf 
     ProcedureReturn 0    
    
    Case #WM_LBUTTONUP
     DrawLButtonUp(hwnd)
     PostMessage_(HWND_FBP,#WM_LBUTTONUP,hwnd,0)
     ProcedureReturn 0
     
    Case #WM_LBUTTONDOWN
     CreateDownTextImage(hWnd)
     DrawLButtonDown(hwnd)
     PostMessage_(HWND_FBP,#WM_LBUTTONDOWN,hwnd,0)
     ProcedureReturn 0
     
    Case #WM_ERASEBKGND
     DrawGroundButton()
     ProcedureReturn 0

    Case #WM_DESTROY
     DeleteObject_( GetClassLong_(hWnd,#GCL_HBRBACKGROUND) )
     ProcedureReturn 0  
  EndSelect  
  If PB_Callback_intern
    ProcedureReturn CallWindowProc_(PB_Callback_intern,hWnd,Msg,wParam,lParam)
  Else
    ProcedureReturn DefWindowProc_(hWnd,Msg,wParam,lParam)
  EndIf  
EndProcedure

Procedure FadingButton(x,y,width,height,parent,backcolor)
  Protected window_class$,wc.WNDCLASSEX
  Static FButton_Count
  If backcolor = -1
    backcolor  = GetSysColor_(#COLOR_BTNFACE)
  EndIf
  window_class$ = "PGDR_FButton"+RSet(Hex(FButton_Count),3,"0")
  FButton_Count + 1 
  wc\cbSize        = SizeOf(WNDCLASSEX)
  wc\lpfnWndProc   = @FButton_Callback()
  wc\hInstance     = 0
  wc\hCursor       = LoadCursor_(0, #IDC_ARROW)
  wc\hbrBackground = CreateSolidBrush_(backcolor)
  wc\lpszClassName = @window_class$
  If RegisterClassEx_(@wc)
    ProcedureReturn CreateWindowEx_(0,window_class$,0,#WS_CHILD|#WS_VISIBLE,x,y,width,height,parent,0,GetModuleHandle_(0),0)
  EndIf
EndProcedure

Procedure InitButtonPanel(HWND,ButtonCount,Color,Width,Height,XOffset=0,YOffset=0,HeightOffset=0) 
 If HWND_FBP = 0
  HWND_FBP          = HWND
  BCounter          = 0
  ContainerWidth    = 200
  ButtonOffset      = 10
  AllButtonHight    = oy
  ButtonWidth       = Width
  ButtonHeight      = Height
  Skin              = Color
  ox = XOffset : oy = YOffset : oh = HeightOffset
  CreateAllGroundPictures(180,40)
  
  GetClientRect_(HWND_FBP,myRect_FBP)
  Unten_FBP = myRect_FBP\bottom - myRect_FBP\top -oh
  LoadFont(0,"Arial",10,#PB_Font_HighQuality)
  Global Dim FBA.FBSTRUCT(ButtonCount); Anzahl der Buttons
  PB_Callback_intern = GetPBCallback(HWND_FBP); internen PB-Callback ermitteln 

  ; Ein Hook auf Sendmessage und Postmessage 
  WndProcHook_FBP = SetWindowsHookEx_(#WH_CALLWNDPROC,@CallWndProc_FBP(),0,GetCurrentThreadId_())
  MsgProcHook_FBP = SetWindowsHookEx_(#WH_GETMESSAGE,@GetMsgProc_FBP(),0,GetCurrentThreadId_())  
  CreateGadgetList(HWND_FBP)
  Grundcontainer = ScrollAreaGadget(#PB_Any,Links_FBP,Oben_FBP,ContainerWidth,Unten_FBP,200,Unten_FBP,5,#PB_ScrollArea_BorderLess)
  SetGadgetColor(Grundcontainer,#PB_Gadget_BackColor,Color)
  ProcedureReturn GadgetID(Grundcontainer)
 Else
  ProcedureReturn 0
 EndIf  
EndProcedure

Procedure AddFadingButton(Text$,IconID = 0)
 Protected Scrollchild,Button
 If GadgetID(Grundcontainer) <> 0
  If BCounter >= 1
   ButtonOffset = ButtonOffset + ButtonHeight +5
  EndIf
  Scrollchild = FindWindowEx_(GadgetID(Grundcontainer), 0, "PureScrollAreaChild", "")
  AllButtonHight + ButtonHeight +5 
  Button = FadingButton(10,ButtonOffset,ButtonWidth,ButtonHeight,Scrollchild,$FFFFFF) 
  FBA(BCounter)\FBHwnd   = Button 
  FBA(BCounter)\FBText   = Text$
  FBA(BCounter)\FBIcon   = IconID  
  BCounter +1 
  SetGadgetAttribute(Grundcontainer,#PB_ScrollArea_InnerHeight,AllButtonHight+10)
  If Unten_FBP < AllButtonHight
   ContainerWidth = 217  
  Else
   ContainerWidth = 200
  EndIf 
  ProcedureReturn Button
 Else
  ProcedureReturn 0
 EndIf
EndProcedure

Procedure FadingButtonPanelFree()
 UnhookWindowsHookEx_(WndProcHook_FBP)
 UnhookWindowsHookEx_(MsgProcHook_FBP)
 FreeFont(0)
 FreeImage(#GroundPicture)
 FreeImage(#HoverPicture)
 FreeImage(#DownPicture)
 FreeImage(#TempImage)
 FreeImage(#Temp_Hover_Image)
 FreeImage(#Temp_Ground_Image)
 FreeImage(#Temp_Down_Image)
 FreeImage(#Fader1_1_Image)
 FreeImage(#Fader1_2_Image)
 FreeImage(#Fader2_1_Image)
 FreeImage(#Fader2_2_Image)
 FreeImage(#Fader3_1_Image)
 FreeImage(#Fader3_2_Image)  
EndProcedure

DataSection ; Die Bilder zum Aufbau der Buttons
SKIN1: IncludeBinary "DarkOrange.bmp"
SKIN2: IncludeBinary "LightGreen.bmp"
SKIN3: IncludeBinary "LightGrey.bmp"
SKIN4: IncludeBinary "OfficeBlue.bmp"
SKIN5: IncludeBinary "Vista.bmp"
SKIN6: IncludeBinary "Neutral.bmp"
EndDataSection

Demo:

Code: Alles auswählen

XIncludeFile "FadingButtonPanel.pbi"
#WindowOptions1 = #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_TitleBar|#PB_Window_MaximizeGadget
#WindowOptions2 = #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered
;Skins
#DarkOrange     = $3D3D3D
#LightGreen     = $FDFDFD
#LightGray      = $E0E0E0
#OfficeBlue     = $FDE8D5
#Vista          = $D4D4D4
#Neutral        = $FFFFFF

Global FB1,FB2,FB3,FB4,FB5,FB6,FB7,FB8,FB9,FB10,FB11,FB12

Procedure ExtractLargeIcon(IconNr)
 Protected IconId
 If ExtractIconEx_("Shell32.dll",IconNr, @IconID,0,1)
  ProcedureReturn IconId
 Else
  ProcedureReturn 0
 EndIf
EndProcedure

Procedure WCB(wnd,msg,wparam,lparam)
  Result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_LBUTTONUP
     If wparam = FB1  : Debug "FadingTestButton 1"  : EndIf
     If wparam = FB2  : Debug "FadingTestButton 2"  : EndIf
     If wparam = FB3  : Debug "FadingTestButton 3"  : EndIf
     If wparam = FB4  : Debug "FadingTestButton 4"  : EndIf
     If wparam = FB5  : Debug "FadingTestButton 5"  : EndIf
     If wparam = FB6  : Debug "FadingTestButton 6"  : EndIf
     If wparam = FB7  : Debug "FadingTestButton 7"  : EndIf
     If wparam = FB8  : Debug "FadingTestButton 8"  : EndIf
     If wparam = FB9  : Debug "FadingTestButton 9"  : EndIf
     If wparam = FB10 : Debug "FadingTestButton 10" : EndIf
     If wparam = FB11 : Debug "FadingTestButton 11" : EndIf
     If wparam = FB12 : Debug "FadingTestButton 12" : EndIf
  EndSelect
  ProcedureReturn Result
EndProcedure

HWND = OpenWindow(0,0,0,900,555,"FadingButtonPanel-Demo",#WindowOptions1|#WindowOptions2)
SetWindowCallback(@WCB())

If InitButtonPanel(HWND,12,#DarkOrange,180,40)
 FB1  = AddFadingButton("FadingTestButton 1",ExtractLargeIcon(4))
 FB2  = AddFadingButton("FadingTestButton 2",ExtractLargeIcon(13))
 FB3  = AddFadingButton("FadingTestButton 3",ExtractLargeIcon(15))
 FB4  = AddFadingButton("FadingTestButton 4",ExtractLargeIcon(16))
 FB5  = AddFadingButton("FadingTestButton 5",ExtractLargeIcon(22))
 FB6  = AddFadingButton("FadingTestButton 6",ExtractLargeIcon(27))
 FB7  = AddFadingButton("FadingTestButton 7",ExtractLargeIcon(1))
 FB8  = AddFadingButton("FadingTestButton 8",ExtractLargeIcon(17))
 FB9  = AddFadingButton("FadingTestButton 9",ExtractLargeIcon(23))
 FB10 = AddFadingButton("FadingTestButton 10",ExtractLargeIcon(24))
 FB11 = AddFadingButton("FadingTestButton 11",ExtractLargeIcon(31))
 FB12 = AddFadingButton("FadingTestButton 12",ExtractLargeIcon(38))
EndIf

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
FadingButtonPanelFree()
End
PB 5.71 LTS Windows 10 Pro & Ubuntu 18.04.2 LTS & Linux Mint 19.3
-----------------------------------------------------
Alles ist, wie man glaubt, dass es ist!
marco2007
Beiträge: 906
Registriert: 26.10.2006 13:19
Kontaktdaten:

Beitrag von marco2007 »

...wieder mal eine Meisterleistung :allright:

Wie hast Du die Bitmaps (Lightgreen, ..) gemacht? Programm?
Windows 11 - PB 6.03 x64
_________________________________
Benutzeravatar
legion
Beiträge: 467
Registriert: 08.10.2006 18:04
Computerausstattung: Intel Core i5-6500 @ 4x 3.6GHz mit Windows 10 Pro, Intel Core-i7 mit Ubuntu 18.04 bionic, x86_64 Linux 4.18.0-16-generic, Microsoft Surface Pro - Windows 10 Pro
Wohnort: Wien
Kontaktdaten:

Beitrag von legion »

Hallo !

Die Bitmaps sind nur eine Kombination aus Farbverläufen wo die
Kanten hervorgehoben wurden. Programm -> Ulead PhotoImpact !

Lg. Legion
PB 5.71 LTS Windows 10 Pro & Ubuntu 18.04.2 LTS & Linux Mint 19.3
-----------------------------------------------------
Alles ist, wie man glaubt, dass es ist!
Antworten