prob if is XP skin support activ

Just starting out? Need help? Post your questions and find answers here.
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

prob if is XP skin support activ

Post by nicolaus »

Hello,

Why the follow code dont work with XP skin support is active?
The code is from the CodeArchiv.

Code works without XP Skin active:

Code: Select all

#ODA_DRAWENTIRE = 1
#ODA_FOCUS = 4
#ODA_SELECT = 2
#TME_CANCEL = $80000000
#TME_HOVER = 1
#TME_LEAVE = 2
#TME_NONCLIENT = $10
#TME_QUERY = $40000000
#DFCS_HOT = $1000
;#DFCS_TRANSPARENT = 4800
#ODS_INACTIVE = $80
#ODS_HOTLIGHT = $40
#ODS_NOFOCUSRECT = $200
#WM_MOUSEHOVER = $2A1
#WM_MOUSELEAVE = $2A3
#MyWindow = 0
Enumeration
  #MyButton1 = 100
  #MyButton2
  #MyButton3
EndEnumeration
#DoHover = 1
#DoLeave = 2
  
; --> Declare Globals
Global doWhat, oldCallback, buttonBrushLeave, buttonBrushClick, buttonBrushHover, buttonBrushDisable

; --> For tracking mouse
Structure myTRACKMOUSEEVENT
  cbSize.l
  dwFlags.l
  hwndTrack.l
  dwHoverTime.l
EndStructure
Global mte.myTRACKMOUSEEVENT
mte\cbSize = SizeOf(myTRACKMOUSEEVENT)

; --> Create button background brushes
buttonBrushLeave = CreateSolidBrush_(GetSysColor_(#COLOR_BTNFACE))
buttonBrushClick = CreateSolidBrush_(RGB(207, 203, 147))
buttonBrushHover = CreateSolidBrush_(RGB($D9,$DA,$BA))
buttonBrushDisable = CreateSolidBrush_(GetSysColor_(#COLOR_GRAYTEXT))
Global hFont
hFont = LoadFont(1,"Verdana",10,#PB_Font_HighQuality|#PB_Font_Bold)

Macro LOWORD(Value)
  Value & $FFFF
EndMacro
Macro HIWORD(Value)
  (Value >> 16) & $FFFF
EndMacro

; --> Main WindowCallback
Procedure myWindowCallback(hwnd, msg, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_DRAWITEM
      *dis.DRAWITEMSTRUCT = lParam
      If *dis\CtlType = #ODT_BUTTON
        buttonNum = *dis\CtlID
        ; --> Default button attributes
        SetBkMode_(*dis\hdc, #TRANSPARENT)
        doWhatBrush = buttonBrushLeave
        doFlags = #DFCS_FLAT | #DFCS_BUTTONPUSH | #DFCS_MONO | #DFCS_ADJUSTRECT
        Select *dis\itemState

          Case #ODS_DISABLED 
            hOldFont = SelectObject_(*dis\hdc,hFont)
            SetTextColor_(*dis\hdc,GetSysColor_(#COLOR_GRAYTEXT))
            
          Case 0
            ; --> DoHover or DoLeave
            If *dis\itemAction = 1 And doWhat = #DoHover
              ; --> DoHover
              doWhatBrush = buttonBrushHover
              hOldFont = SelectObject_(*dis\hdc,hFont)
              SetTextColor_(*dis\hdc,RGB($A,$24,$50))
              
              doFlags = #DFCS_BUTTONPUSH | #DFCS_MONO | #DFCS_ADJUSTRECT
            ElseIf *dis\itemAction = 1 And doWhat = #DoLeave
              ; --> DoLeave
              doWhatBrush = buttonBrushLeave
              doFlags = #DFCS_FLAT | #DFCS_BUTTONPUSH | #DFCS_MONO | #DFCS_ADJUSTRECT
            EndIf
          Case #ODS_FOCUS 
            ; --> ClickDown
            doWhatBrush = buttonBrushClick
            hOldFont = SelectObject_(*dis\hdc,hFont)
            SetTextColor_(*dis\hdc,RGB($35,$87,$3))
            doFlags = #DFCS_BUTTONPUSH | #DFCS_PUSHED | #DFCS_ADJUSTRECT
          Case #ODS_FOCUS | #ODS_SELECTED 
            ; --> ClickUp
            doWhatBrush = buttonBrushClick
            hOldFont = SelectObject_(*dis\hdc,hFont)
            SetTextColor_(*dis\hdc,RGB($7A,$58,$10))
            doFlags = #DFCS_BUTTONPUSH | #DFCS_PUSHED | #DFCS_ADJUSTRECT
        EndSelect
      EndIf
      DrawFrameControl_(*dis\hdc, *dis\rcItem, #DFCS_BUTTON3STATE, doFlags)
      FillRect_(*dis\hdc, *dis\rcItem, doWhatBrush)
      
      DrawText_(*dis\hdc, GetGadgetText(buttonNum), Len(GetGadgetText(buttonNum)), *dis\rcItem, #DT_CENTER | #DT_SINGLELINE | #DT_VCENTER)
  EndSelect
  ProcedureReturn Result
EndProcedure

; --> ButtonCallback
Procedure myButtonCallback(hwnd, msg, wParam, lParam)
  Shared mouseLeave, hover, hot
  Result = CallWindowProc_(oldCallback, hwnd, msg, wParam, lParam)
  buttonID = GetDlgCtrlID_(hwnd)
  Select msg
    Case #WM_MOUSEMOVE
      If wParam <> #MK_LBUTTON And mouseLeave = 0
        mouseLeave = 1
        doWhat = #DoHover
        ; --> Force #WM_DRAWITEM
        InvalidateRect_(GadgetID(buttonID), 0, 0)
        ; Track mouse leaving button
        mte\dwFlags = #TME_LEAVE
        mte\hwndTrack = GadgetID(buttonID)
        TrackMouseEvent_(mte)
      EndIf
    Case #WM_MOUSELEAVE 
      mouseLeave = 0
      doWhat = #DoLeave
      ; --> Force #WM_DRAWITEM
      InvalidateRect_(GadgetID(buttonID), 0, 0)
    Case #WM_LBUTTONDOWN
      ; --> Set flag to reset previous down botton
      doWhat = #DoLeave
  EndSelect
  ProcedureReturn Result
EndProcedure
If OpenWindow(#MyWindow, 100, 100, 250, 200, "Custom Hover Buttons", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(#MyWindow))
  SetWindowCallback(@myWindowCallback())
  CreateStatusBar(0, WindowID(#MyWindow))
  StringGadget(0, 75, 10, 100, 20, "Ownerdraw Buttons", #PB_String_BorderLess | #PB_String_ReadOnly)
  ButtonGadget(#MyButton1, 75, 50, 100, 20, "Testing",#PB_Button_Toggle)
  ButtonGadget(#MyButton2, 75, 80, 100, 20, "Customized",#PB_Button_Toggle)
  ButtonGadget(#MyButton3, 75, 110, 100, 20, "Buttons")
  ; --> Remove #BS_PUSHBUTTON and add #BS_OWNERDRAW to buttons
  For B = #MyButton1 To #MyButton3
    bStyle = GetWindowLong_(GadgetID(B), #GWL_STYLE)
    SetWindowLong_(GadgetID(B), #GWL_STYLE, bStyle &~#BS_PUSHBUTTON | #BS_OWNERDRAW)
    oldCallback = SetWindowLong_(GadgetID(B), #GWL_WNDPROC, @myButtonCallback())
  Next B
  SendMessage_(GadgetID(#MyButton2),#BM_CLICK,0,0)

  Repeat
    Event = WaitWindowEvent()

    Select Event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            StatusBarText(0, 0, "No Button seelcted")
          Case #MyButton1
            StatusBarText(0, 0, "Selected button ID# " + Str(#MyButton1) + " text is: Testing")
          Case #MyButton2
            StatusBarText(0, 0, "Selected button ID# " + Str(#MyButton2) + " text is: Customized")
          Case #MyButton3
            StatusBarText(0, 0, "Selected button ID# " + Str(#MyButton3) + " text is: Buttons")
        EndSelect
    EndSelect
  Until Event = #PB_Event_CloseWindow
EndIf
DeleteObject_(buttonBrushLeave)
DeleteObject_(buttonBrushClick)
DeleteObject_(buttonBrushHover)
End
This code works only with XP skin support is active but if you look into the Callback you see that the events (after CASE) are very crasy and not the right events for a button:

Code: Select all

#ODA_DRAWENTIRE = 1
#ODA_FOCUS = 4
#ODA_SELECT = 2
#TME_CANCEL = $80000000
#TME_HOVER = 1
#TME_LEAVE = 2
#TME_NONCLIENT = $10
#TME_QUERY = $40000000
#DFCS_HOT = $1000
;#DFCS_TRANSPARENT = 4800
#ODS_INACTIVE = $80
#ODS_HOTLIGHT = $40
#ODS_NOFOCUSRECT = $200
#WM_MOUSEHOVER = $2A1
#WM_MOUSELEAVE = $2A3
#MyWindow = 0
Enumeration
  #MyButton1 = 100
  #MyButton2
  #MyButton3
EndEnumeration
#DoHover = 1
#DoLeave = 2
  
; --> Declare Globals
Global doWhat, oldCallback, buttonBrushLeave, buttonBrushClick, buttonBrushHover, buttonBrushDisable

; --> For tracking mouse
Structure myTRACKMOUSEEVENT
  cbSize.l
  dwFlags.l
  hwndTrack.l
  dwHoverTime.l
EndStructure
Global mte.myTRACKMOUSEEVENT
mte\cbSize = SizeOf(myTRACKMOUSEEVENT)

; --> Create button background brushes
buttonBrushLeave = CreateSolidBrush_(GetSysColor_(#COLOR_BTNFACE))
buttonBrushClick = CreateSolidBrush_(RGB(207, 203, 147))
buttonBrushHover = CreateSolidBrush_(RGB($D9,$DA,$BA))
buttonBrushDisable = CreateSolidBrush_(GetSysColor_(#COLOR_GRAYTEXT))
Global hFont
hFont = LoadFont(1,"Verdana",10,#PB_Font_HighQuality|#PB_Font_Bold)

Macro LOWORD(Value)
  Value & $FFFF
EndMacro
Macro HIWORD(Value)
  (Value >> 16) & $FFFF
EndMacro

; --> Main WindowCallback
Procedure myWindowCallback(hwnd, msg, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_DRAWITEM
      *dis.DRAWITEMSTRUCT = lParam
      If *dis\CtlType = #ODT_BUTTON
        buttonNum = *dis\CtlID
        ; --> Default button attributes
        SetBkMode_(*dis\hdc, #TRANSPARENT)
        doWhatBrush = buttonBrushLeave
        doFlags = #DFCS_FLAT | #DFCS_BUTTONPUSH | #DFCS_MONO | #DFCS_ADJUSTRECT
        Select *dis\itemState
          Case 772 
            hOldFont = SelectObject_(*dis\hdc,hFont)
            SetTextColor_(*dis\hdc,GetSysColor_(#COLOR_GRAYTEXT))
                    
          Case #EN_CHANGE
            ; --> DoHover or DoLeave
            If *dis\itemAction = 1 And doWhat = #DoHover
              ; --> DoHover
              doWhatBrush = buttonBrushHover
              hOldFont = SelectObject_(*dis\hdc,hFont)
              SetTextColor_(*dis\hdc,RGB($A,$24,$50))
              
              doFlags = #DFCS_BUTTONPUSH | #DFCS_MONO | #DFCS_ADJUSTRECT
            ElseIf *dis\itemAction = 1 And doWhat = #DoLeave
              ; --> DoLeave
              doWhatBrush = buttonBrushLeave
              doFlags = #DFCS_FLAT | #DFCS_BUTTONPUSH | #DFCS_MONO | #DFCS_ADJUSTRECT
            EndIf
          Case #WM_PALETTEISCHANGING
            ; --> ClickDown
            doWhatBrush = buttonBrushClick
            hOldFont = SelectObject_(*dis\hdc,hFont)
            SetTextColor_(*dis\hdc,RGB($35,$87,$3))
            doFlags = #DFCS_BUTTONPUSH | #DFCS_PUSHED | #DFCS_ADJUSTRECT
          Case #WM_PALETTECHANGED 
            ; --> ClickUp
            doWhatBrush = buttonBrushClick
            hOldFont = SelectObject_(*dis\hdc,hFont)
            SetTextColor_(*dis\hdc,RGB($7A,$58,$10))
            doFlags = #DFCS_BUTTONPUSH | #DFCS_PUSHED | #DFCS_ADJUSTRECT
            
        EndSelect
      EndIf
      DrawFrameControl_(*dis\hdc, *dis\rcItem, #DFCS_BUTTON3STATE, doFlags)
      FillRect_(*dis\hdc, *dis\rcItem, doWhatBrush)
      
      DrawText_(*dis\hdc, GetGadgetText(buttonNum), Len(GetGadgetText(buttonNum)), *dis\rcItem, #DT_CENTER | #DT_SINGLELINE | #DT_VCENTER)
  EndSelect
  ProcedureReturn Result
EndProcedure

; --> ButtonCallback
Procedure myButtonCallback(hwnd, msg, wParam, lParam)
  Shared mouseLeave, hover, hot
  Result = CallWindowProc_(oldCallback, hwnd, msg, wParam, lParam)
  buttonID = GetDlgCtrlID_(hwnd)
  Select msg
    Case #WM_MOUSEMOVE
      If wParam <> #MK_LBUTTON And mouseLeave = 0
        mouseLeave = 1
        doWhat = #DoHover
        ; --> Force #WM_DRAWITEM
        InvalidateRect_(GadgetID(buttonID), 0, 0)
        ; Track mouse leaving button
        mte\dwFlags = #TME_LEAVE
        mte\hwndTrack = GadgetID(buttonID)
        TrackMouseEvent_(mte)
      EndIf
    Case #WM_MOUSELEAVE 
      mouseLeave = 0
      doWhat = #DoLeave
      ; --> Force #WM_DRAWITEM
      InvalidateRect_(GadgetID(buttonID), 0, 0)
    Case #WM_LBUTTONDOWN
      ; --> Set flag to reset previous down botton
      doWhat = #DoLeave
  EndSelect
  ProcedureReturn Result
EndProcedure
If OpenWindow(#MyWindow, 100, 100, 250, 200, "Custom Hover Buttons", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(#MyWindow))
  SetWindowCallback(@myWindowCallback())
  CreateStatusBar(0, WindowID(#MyWindow))
  StringGadget(0, 75, 10, 100, 20, "Ownerdraw Buttons", #PB_String_BorderLess | #PB_String_ReadOnly)
  ButtonGadget(#MyButton1, 75, 50, 100, 20, "Testing",#PB_Button_Toggle)
  ButtonGadget(#MyButton2, 75, 80, 100, 20, "Customized",#PB_Button_Toggle)
  ButtonGadget(#MyButton3, 75, 110, 100, 20, "Buttons")
  ; --> Remove #BS_PUSHBUTTON and add #BS_OWNERDRAW to buttons
  For B = #MyButton1 To #MyButton3
    bStyle = GetWindowLong_(GadgetID(B), #GWL_STYLE)
    SetWindowLong_(GadgetID(B), #GWL_STYLE, bStyle &~#BS_PUSHBUTTON | #BS_OWNERDRAW)
    oldCallback = SetWindowLong_(GadgetID(B), #GWL_WNDPROC, @myButtonCallback())
  Next B
  SendMessage_(GadgetID(#MyButton2),#BM_CLICK,0,0)

  Repeat
    Event = WaitWindowEvent()

    Select Event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            StatusBarText(0, 0, "No Button seelcted")
          Case #MyButton1
            StatusBarText(0, 0, "Selected button ID# " + Str(#MyButton1) + " text is: Testing")
          Case #MyButton2
            StatusBarText(0, 0, "Selected button ID# " + Str(#MyButton2) + " text is: Customized")
          Case #MyButton3
            StatusBarText(0, 0, "Selected button ID# " + Str(#MyButton3) + " text is: Buttons")
        EndSelect
    EndSelect
  Until Event = #PB_Event_CloseWindow
EndIf
DeleteObject_(buttonBrushLeave)
DeleteObject_(buttonBrushClick)
DeleteObject_(buttonBrushHover)
End
Wat dose the XP Skin support with the events?

Thanks
Nico
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

The first code works without a problem. With skins en- & disabled. The second doesn't work in both modes. It just shows the buttons in their initial state.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

Fluid Byte wrote:The first code works without a problem. With skins en- & disabled. The second doesn't work in both modes. It just shows the buttons in their initial state.
Ok thanks for test, now i have a question. Do you have the XP skin activ at your Windows?

I have the normal (old "skin" mode like Windows 2000) activ and if i test teh first code with XP skin support enabled (at the compiler options of PB) i cant see the stats of the buttons if i click it.
If i use the second code it works.

So have we any way to check if the XP skin is activatet in the OS?

Thanks,
Nico
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

First code works fine with or without XP Skins in Windows Classic mode and/or XP Theme mode.

Second code fails just as Fluid Byte said.
nicolaus wrote:If i use the second code it works.
That surprises me because callback code has some flaws.

Within your Select *dis\itemState you have Case #EN_CHANGE, Case #WM_PALETTEISCHANGING, and Case #WM_PALETTECHANGED. Are you saying those are all valid button states :?: What exactly are you catching with Case 772 :?:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

@nicolaus: I've made some modifications to my original code from 2004. See if this works for you. :)

Code: Select all

;/**************************************************************** 
;/ Title:         Ownerdraw Hover Buttons 
;/ Author:        Sparkie 
;/ Date:          January 11, 2008 (original code December 22, 2004) 
;/ Ref:           http://www.purebasic.fr/english/viewtopic.php?p=76316#76316 
;/ OS Support:    Microsoft Windows All 
;/ PB Support:    PureBasic 4.0 and later 
;/ Notes:         Andre added the #ODS_DISABLED support
;/ License:       Free to use, optimize, and modify as desired 
;/**************************************************************** 

#TME_HOVER = 1 
#TME_LEAVE = 2 
#TME_NONCLIENT = $10 
#TME_QUERY = $40000000 
#DoHover = 1 
#DoLeave = 2 
#MyWindow = 0 

Enumeration 
  #MyButton1 = 100 
  #MyButton2 
  #MyButton3 
EndEnumeration 

Structure ButtonData 
  oldCallback.l 
  brushLeave.l 
  brushClick.l 
  brushHover.l 
  brushDisabled.l 
EndStructure 

;... For tracking mouse 
Structure myTRACKMOUSEEVENT 
  cbSize.l 
  dwFlags.l 
  hwndTrack.l 
  dwHoverTime.l 
EndStructure 

;... Declare Globals 
Global mte.myTRACKMOUSEEVENT, doWhat 
mte\cbSize = SizeOf(myTRACKMOUSEEVENT) 

;... Create button background brushes 
buttonBrushLeave = CreateSolidBrush_(RGB(237, 233, 177)) 
buttonBrushClick = CreateSolidBrush_(RGB(207, 203, 147)) 
buttonBrushHover = CreateSolidBrush_(RGB(255, 100, 100)) 
buttonBrushDisabled = CreateSolidBrush_(RGB(200, 200, 200)) 
bData.ButtonData 
bData\brushHover = buttonBrushHover 
bData\brushLeave = buttonBrushLeave 
bData\brushClick = buttonBrushClick 
bData\brushDisabled = buttonBrushDisabled 

;... Main WindowCallback 
Procedure myWindowCallback(hwnd, msg, wParam, lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_DRAWITEM 
      *dis.DRAWITEMSTRUCT = lParam 
      If *dis\CtlType = #ODT_BUTTON 
        buttonNum = *dis\CtlID 
        *bData.ButtonData = GetGadgetData(buttonNum) 
        ;... Default button attributes 
        SetBkMode_(*dis\hdc, #TRANSPARENT) 
        doWhatBrush = *bData\brushLeave 
        doFlags = #DFCS_FLAT | #DFCS_BUTTONPUSH | #DFCS_MONO | #DFCS_ADJUSTRECT 
        Select *dis\itemState 
          Case 0 
            ;... DoHover or DoLeave 
            If *dis\itemAction = 1 And doWhat = #DoHover 
              ;... DoHover 
              doWhatBrush = *bData\brushHover 
              doFlags = #DFCS_BUTTONPUSH | #DFCS_MONO | #DFCS_ADJUSTRECT 
            ElseIf *dis\itemAction = 1 And doWhat = #DoLeave 
              ;... DoLeave 
              doWhatBrush = *bData\brushLeave 
              doFlags = #DFCS_FLAT | #DFCS_BUTTONPUSH | #DFCS_MONO | #DFCS_ADJUSTRECT 
            EndIf 
          Case #ODS_DISABLED 
            SetTextColor_(*dis\hdc, RGB(125, 125, 125)) 
            doWhatBrush = *bData\brushDisabled 
          Case #ODS_FOCUS 
            ;... ClickDown 
            doWhatBrush = *bData\brushClick 
            doFlags = #DFCS_BUTTONPUSH | #DFCS_PUSHED | #DFCS_ADJUSTRECT 
          Case #ODS_FOCUS | #ODS_SELECTED 
            ;... ClickUp 
            doWhatBrush = *bData\brushClick 
            doFlags = #DFCS_BUTTONPUSH | #DFCS_PUSHED | #DFCS_ADJUSTRECT 
        EndSelect 
      EndIf 
      DrawFrameControl_(*dis\hdc, *dis\rcItem, #DFC_BUTTON, doFlags) 
      FillRect_(*dis\hdc, *dis\rcItem, doWhatBrush) 
      DrawText_(*dis\hdc, GetGadgetText(buttonNum), Len(GetGadgetText(buttonNum)), *dis\rcItem, #DT_CENTER | #DT_SINGLELINE | #DT_VCENTER) 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

;... ButtonCallback 
Procedure myButtonCallback(hwnd, msg, wParam, lParam) 
  Shared mouseLeave, hover, hot 
  
  buttonID = GetDlgCtrlID_(hwnd) 
  *bData.ButtonData = GetGadgetData(buttonID) 
  
  Select msg 
    Case #WM_MOUSEMOVE 
      If wParam <> #MK_LBUTTON And mouseLeave = 0 
        mouseLeave = 1 
        doWhat = #DoHover 
        ;... Force #WM_DRAWITEM 
        InvalidateRect_(GadgetID(buttonID), 0, 0) 
        ; Track mouse leaving button 
        mte\dwFlags = #TME_LEAVE 
        mte\hwndTrack = GadgetID(buttonID) 
        TrackMouseEvent_(mte) 
      EndIf 
    Case #WM_MOUSELEAVE 
      mouseLeave = 0 
      doWhat = #DoLeave 
      ;... Force #WM_DRAWITEM 
      InvalidateRect_(GadgetID(buttonID), 0, 0) 
    Case #WM_LBUTTONDOWN 
      ;... Set flag to reset previous down botton 
      doWhat = #DoLeave 
  EndSelect 
  ProcedureReturn CallWindowProc_(*bData\oldCallback, hwnd, msg, wParam, lParam) 
EndProcedure 

If OpenWindow(#MyWindow, 100, 100, 250, 200, "Custom Hover Buttons", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(#MyWindow)) 
  SetWindowCallback(@myWindowCallback()) 
  CreateStatusBar(0, WindowID(#MyWindow)) 
  StringGadget(0, 75, 10, 100, 20, "Ownerdraw Buttons", #PB_String_BorderLess | #PB_String_ReadOnly) 
  ButtonGadget(#MyButton1, 75, 50, 100, 20, "Testing") 
  ButtonGadget(#MyButton2, 75, 80, 100, 20, "Customized") 
  ButtonGadget(#MyButton3, 75, 110, 100, 20, "Buttons") 
  ;... Remove #BS_PUSHBUTTON and add #BS_OWNERDRAW to buttons 
  
  For b = #MyButton1 To #MyButton3 
    bStyle = GetWindowLong_(GadgetID(b), #GWL_STYLE) 
    SetWindowLong_(GadgetID(b), #GWL_STYLE, bStyle &~#BS_PUSHBUTTON | #BS_OWNERDRAW) 
    bData\oldCallback = SetWindowLong_(GadgetID(b), #GWL_WNDPROC, @myButtonCallback()) 
    SetGadgetData(b, bData) 
  Next b 
  
  Repeat 
    event = WaitWindowEvent() 
    Select event 
      Case #PB_Event_Gadget 
        Select EventGadget() 
          Case 0 
            StatusBarText(0, 0, "No Button seelcted") 
          Case #MyButton1 
            StatusBarText(0, 0, "Selected button ID# " + Str(#MyButton1) + " text is: Testing") 
          Case #MyButton2 
            StatusBarText(0, 0, "Selected button ID# " + Str(#MyButton2) + " text is: Customized") 
          Case #MyButton3 
            StatusBarText(0, 0, "Selected button ID# " + Str(#MyButton3) + " text is: Buttons") 
        EndSelect 
    EndSelect 
  Until event = #PB_Event_CloseWindow 
EndIf 
DeleteObject_(buttonBrushLeave) 
DeleteObject_(buttonBrushClick) 
DeleteObject_(buttonBrushHover) 
DeleteObject_(buttonBrushDisabled) 
End 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

@Sparkie
I have test your code with PB 4.02, PB 4.10 and PB 4.20 beta1 and i have every time the same prob. If i activate the XP Skin support in the Compiler options and create the exe, i cant press any buttons.

At my Windows XP pro (SP2 and all updates installed) i have the normal Windows klassik style active like this:
Image

I have build a test exe with your orginal code ( with PB 4.02 ), please can you test this exe at your system with the Windows klassik style is activ?

xp_buttontest_org.exe

Thanks,
Nico
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

Sparkie wrote:.....
Within your Select *dis\itemState you have Case #EN_CHANGE, Case #WM_PALETTEISCHANGING, and Case #WM_PALETTECHANGED. Are you saying those are all valid button states :?: What exactly are you catching with Case 772 :?:
I have debug the *dis\itemState with XP support active in the compiler options and have look into the winuser.h wat the event numbers is. so i have found the constantes like this #EN_CHANGE, #WM_PALETTEISCHANGING, #WM_PALETTECHANGED and 772.
772 is the event for a disabled button.

regrads,
Nico
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Your exe works just fine for me nicolaus :?

[img]http://www.heysparkie.com/images\nicolaus.jpg[/img]
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

Sparkie wrote:Your exe works just fine for me nicolaus :?

[img]http://www.heysparkie.com/images\nicolaus.jpg[/img]

Hm thats very crasy, if i test the exe i see no new state of the button.
Ok thanks for this time, i must look into my os wat is frong with it.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

See if you get the same results as I do with this code. I just cannot understand how you are able to run your second code from ^above^ and get it to work. :?

Code: Select all

Debug #ODS_DISABLED               ; 4
Debug #ODS_FOCUS                  ; 16
Debug #ODS_FOCUS | #ODS_SELECTED  ; 17
Debug "*****"
Debug #EN_CHANGE                  ; 768
Debug #WM_PALETTEISCHANGING       ; 784
Debug #WM_PALETTECHANGED          ; 785
Output should read

Code: Select all

4
16
17
*****
768
784
785
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

Sparkie wrote:See if you get the same results as I do with this code. I just cannot understand how you are able to run your second code from ^above^ and get it to work. :?

Code: Select all

Debug #ODS_DISABLED               ; 4
Debug #ODS_FOCUS                  ; 16
Debug #ODS_FOCUS | #ODS_SELECTED  ; 17
Debug "*****"
Debug #EN_CHANGE                  ; 768
Debug #WM_PALETTEISCHANGING       ; 784
Debug #WM_PALETTECHANGED          ; 785
Output should read

Code: Select all

4
16
17
*****
768
784
785
I cant also understand wat is frong. If i use the XP Skin support i have only the events like this:
772, 768, 784, 785

but i dont know why!

No i start my laptop also with Windows XP and want test it at this maschien. I think the system at my main PC is not ok.

regards,
Nico
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

Pk i have test it at my laptop and at this system it works fine. So my system at my working PC is not ok i thnik so.
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: prob if is XP skin support activ

Post by doctorized »

Is there a way to add multiline support? Adding #PB_Button_MultiLine flag didn't help.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: prob if is XP skin support activ

Post by RASHAD »

- Modern theme Enabled\Disabled support
- Multi line support

Tested PB 5.70 x86 - Windows 10 x74

Code: Select all


;/****************************************************************
;/ Title:         Ownerdraw Hover Buttons
;/ Author:        Sparkie
;/ Date:          January 11, 2008 (original code December 22, 2004)
;/ Modifier :     RASHAD
;/ Date:          8/7/2019
;/ Ref:           http://www.purebasic.fr/english/viewtopic.php?p = 76316#76316
;/****************************************************************

#TME_HOVER = 1
#TME_LEAVE = 2
#TME_NONCLIENT = $10
#TME_QUERY = $40000000
#DoHover = 1
#DoLeave = 2
#MyWindow = 0

Enumeration
  #MyButton1 = 100
  #MyButton2
  #MyButton3
EndEnumeration

Structure ButtonData
  oldCallback.i
  brushLeave.l
  brushClick.l
  brushHover.l
  brushDisabled.l
EndStructure

;... Declare Globals
Global mte.TRACKMOUSEEVENT, doWhat,buttonBrushClick2
mte\cbSize = SizeOf(TRACKMOUSEEVENT)

;... Create button background brushes
buttonBrushLeave = CreateSolidBrush_(RGB(237, 233, 177))
buttonBrushClick = CreateSolidBrush_(RGB(207, 203, 147))
buttonBrushClick2 = CreateSolidBrush_(RGB(140, 253, 137))
buttonBrushHover = CreateSolidBrush_(RGB(254, 250, 194))
buttonBrushDisabled = CreateSolidBrush_(RGB(227, 227, 227))
bData.ButtonData
bData\brushHover = buttonBrushHover
bData\brushLeave = buttonBrushLeave
bData\brushClick = buttonBrushClick
bData\brushDisabled = buttonBrushDisabled

;... Main WindowCallback
Procedure myWindowCallback(hwnd, msg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_DRAWITEM
      *dis.DRAWITEMSTRUCT = lParam
      If *dis\CtlType = #ODT_BUTTON
        buttonNum = *dis\CtlID
        *bData.ButtonData = GetGadgetData(buttonNum)
        ;... Default button attributes
        SetBkMode_(*dis\hdc, #TRANSPARENT)
        doWhatBrush = *bData\brushLeave
        doFlags = #DFCS_FLAT | #DFCS_BUTTONPUSH | #DFCS_MONO | #DFCS_ADJUSTRECT
        If *dis\itemState >= $300
          *dis\itemState = *dis\itemState ! $300
        EndIf             
        Select *dis\itemState 
          Case #ODS_SELECTED
            ;... DoHover or DoLeave
            If *dis\itemAction = 1 And doWhat = #DoHover
              ;... DoHover
              SetTextColor_(*dis\hdc, RGB(255, 0, 0))
              doWhatBrush = *bData\brushHover
              doFlags = #DFCS_BUTTONPUSH | #DFCS_MONO | #DFCS_ADJUSTRECT
            ElseIf *dis\itemAction = 1 And doWhat = #DoLeave
              ;... DoLeave
              SetTextColor_(*dis\hdc, RGB(255, 0, 0))
              doWhatBrush = *bData\brushLeave
              doFlags = #DFCS_FLAT | #DFCS_BUTTONPUSH | #DFCS_MONO | #DFCS_ADJUSTRECT
            EndIf
          Case #ODS_DISABLED
            SetTextColor_(*dis\hdc, RGB(125, 125, 125))
            doWhatBrush = *bData\brushDisabled
            
          Case *dis\itemState & #ODS_FOCUS
            ;... ClickDown
            SetTextColor_(*dis\hdc, RGB(255, 0, 0))
            doWhatBrush = *bData\brushLeave
            doFlags = #DFCS_BUTTONPUSH | #DFCS_MONO | #DFCS_ADJUSTRECT
            ;drawFocus = 1
            If *dis\itemAction = 2 And doWhat = #DoLeave
              ;... DoHover
              doWhatBrush = *bData\brushHover
            EndIf
            If *dis\itemAction = 1 And doWhat = #DoHover
              ;... DoHover
              doWhatBrush = *bData\brushHover
            EndIf
          Case*dis\itemState & ( #ODS_FOCUS | #ODS_SELECTED)
            ;... ClickUp
            SetTextColor_(*dis\hdc, RGB(255, 0, 0))
            If buttonNum = #MyButton1
              doWhatBrush = buttonBrushClick2
            Else
              doWhatBrush = *bData\brushClick
            EndIf
            doFlags = #DFCS_BUTTONPUSH | #DFCS_PUSHED | #DFCS_ADJUSTRECT
        EndSelect
      EndIf

      DrawFrameControl_(*dis\hdc, *dis\rcItem, #DFC_BUTTON, doFlags)
      SetRect_(r.RECT,0,0,100,40)
      DrawEdge_(*dis\hdc, r,#EDGE_ETCHED	,#BF_RECT	)
      FillRect_(*dis\hdc, *dis\rcItem, doWhatBrush)
      *dis\rcItem\top = 2
      SelectObject_(*dis\hdc,FontID(0))
      DrawText_(*dis\hdc, GetGadgetText(buttonNum), Len(GetGadgetText(buttonNum)), *dis\rcItem, #DT_CENTER |  #DT_WORDBREAK )
      ;       If drawFocus = 1
      ;         DrawFocusRect_(*dis\hDC, *dis\rcItem)
      ;       EndIf
  EndSelect
  ProcedureReturn result
EndProcedure

;... ButtonCallback
Procedure myButtonCallback(hwnd, msg, wParam, lParam)
  Shared mouseLeave, hover, hot

  buttonID = GetDlgCtrlID_(hwnd)
  *bData.ButtonData = GetGadgetData(buttonID)

  Select msg
    Case #WM_MOUSEMOVE
      If wParam <> #MK_LBUTTON And mouseLeave = 0
        mouseLeave = 1
        doWhat = #DoHover
        ;... Force #WM_DRAWITEM
        InvalidateRect_(GadgetID(buttonID), 0, 0)
        ; Track mouse leaving button
        mte\dwFlags = #TME_LEAVE
        mte\hwndTrack = GadgetID(buttonID)
        TrackMouseEvent_(mte)
      EndIf
    Case #WM_MOUSELEAVE
      mouseLeave = 0
      doWhat = #DoLeave
      ;... Force #WM_DRAWITEM
      InvalidateRect_(GadgetID(buttonID), 0, 0)
    Case #WM_LBUTTONDOWN
      ;... Set flag to reset previous down botton
      doWhat = #DoLeave
  EndSelect
  ProcedureReturn CallWindowProc_(*bData\oldCallback, hwnd, msg, wParam, lParam)
EndProcedure

LoadFont(0,"Tahoma",10,#PB_Font_StrikeOut)

If OpenWindow(#MyWindow, 0,0,400,300, "Custom Hover Buttons", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
  SetWindowCallback(@myWindowCallback())
  CreateStatusBar(0, WindowID(#MyWindow))
  AddStatusBarField(350)
  
  ButtonGadget(#MyButton1, 10, 10, 100, 40, "Testing"+#LF$+"RASHAD" )
  ButtonGadget(#MyButton2, 10, 60, 100, 40, "Customized"+#LF$+"RASHAD")
  ButtonGadget(#MyButton3, 10, 110, 100, 40, "Buttons"+#LF$+"RASHAD")
  ;... Remove #BS_PUSHBUTTON and add #BS_OWNERDRAW to buttons

  For b = #MyButton1 To #MyButton3
    bStyle = GetWindowLongPtr_(GadgetID(b), #GWL_STYLE)
    SetWindowLongPtr_(GadgetID(b), #GWL_STYLE, bStyle & ~#BS_PUSHBUTTON | #BS_OWNERDRAW)
    bData\oldCallback = SetWindowLongPtr_(GadgetID(b), #GWL_WNDPROC, @myButtonCallback())
    SetGadgetData(b, bData)
  Next b
  
DisableGadget(#MyButton2,1)
SetCursorPos_(WindowX(0),WindowY(0))
Repeat
    event = WaitWindowEvent()
    Select event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            StatusBarText(0, 0, "No Button selected")
          Case #MyButton1
            StatusBarText(0, 0, "Selected button ID# " + Str(#MyButton1) + " text is: Testing")
          Case #MyButton2
            StatusBarText(0, 0, "Selected button ID# " + Str(#MyButton2) + " text is: Customized")
          Case #MyButton3
            StatusBarText(0, 0, "Selected button ID# " + Str(#MyButton3) + " text is: Buttons")
        EndSelect
    EndSelect
Until event = #PB_Event_CloseWindow
EndIf
DeleteObject_(buttonBrushLeave)
DeleteObject_(buttonBrushClick)
DeleteObject_(buttonBrushHover)
DeleteObject_(buttonBrushDisabled)
Edit :Quick hack
Edit 2 : Use special font
Last edited by RASHAD on Mon Jul 08, 2019 9:10 pm, edited 2 times in total.
Egypt my love
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: prob if is XP skin support activ

Post by doctorized »

It is really nice, thank you very much! I would like one more thing. Is there a way to change colors under some condition after clicking?


EDIT: I noticed something, a bug I think. When I press F5 to run the app and the mouse is over the area where a button appears, doesn't matter which one of the enabled ones, then both enabled buttons have the hover color.

EDIT 2: Wouldn't it be nice to be able to set specific font?
Post Reply