looking around the fivewin code I found the wrapper for use of theme data of windows, I used it some time ago for a my project in C++.
So I think it would be great if the btnbmp uses this procedures (and DrawFrameControl) to paint itself.
Here an example of result:
here an example of use:
- Code: Select all Expand view
- #include "fivewin.ch"
function main()
local oDlg, theme
DEFINE WINDOW oDlg FROM 0,0 TO 300,300 PIXEL TITLE "Test"
@ 10,10 SAY "custom" PIXEL
TThemed():New(30,10,oDlg)
@ 10,110 SAY "Button" PIXEL
@ 30,110 BUTTON "" SIZE 64,64 OF oDlg PIXEL
@ 110,10 SAY "BTNBMP" PIXEL
@ 130,10 BTNBMP SIZE 64,64 OF oDlg PIXEL
@ 110,110 SAY "BTNBMP 2007" PIXEL
@ 130,110 BTNBMP SIZE 64,64 OF oDlg PIXEL 2007
ACTIVATE WINDOW oDlg CENTERED
return nil
//----------------------------------------------------------------------------//
CLASS TThemed FROM TControl
DATA theme
DATA lMOver AS LOGICAL
DATA lMDown AS LOGICAL
CLASSDATA lRegistered AS LOGICAL
METHOD New( nRow, nCol, oWnd, nWidth, nHeight ) CONSTRUCTOR
METHOD End() INLINE ::Destroy()
METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
METHOD Destroy()
METHOD Paint()
METHOD MouseLeave( nRow, nCol, nFlags )
METHOD MouseMove( nRow, nCol, nKeyFlags )
METHOD LButtonDown( nRow, nCol )
METHOD LButtonUp( nRow, nCol )
METHOD HandleEvent( nMsg, nWParam, nLParam )
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( nRow, nCol, oWnd, nWidth, nHeight ) CLASS TThemed
DEFAULT nRow := 10, nCol := 10, oWnd := GetWndDefault(), nWidth := 64, nHeight := 64
::oWnd = oWnd
::nId = ::GetNewId()
::nStyle = nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP )
::nTop = nRow
::nLeft = nCol
::nBottom = ::nTop + nHeight - 1
::nRight = ::nLeft + nWidth
::lDrag = .F.
::lMOver = .F.
::lMDown = .F.
::theme = C5_OpenThemeData(oWnd:hWnd,"BUTTON")
::Register( nOR( CS_VREDRAW, CS_HREDRAW ) )
::Create()
oWnd:AddControl( Self )
return Self
METHOD Destroy() CLASS TThemed
if ::theme!=0
C5_CloseThemeData(::theme)
endif
return ::Super:Destroy()
METHOD MouseMove( nRow, nCol, nKeyFlags ) CLASS TThemed
if ! ::lMOver
::lMOver = .T.
::Refresh()
endif
TrackMouseEvent( ::hWnd, /*TME_LEAVE*/2 )
return 0
METHOD MouseLeave( nRow, nCol, nFlags ) CLASS TThemed
::lMOver = .F.
::Refresh()
return nil
METHOD LButtonDown( nRow, nCol ) CLASS TThemed
::lMDown = .T.
::Refresh()
return nil
METHOD LButtonUp( nRow, nCol ) CLASS TThemed
::lMDown = .F.
::Refresh()
return nil
// DrawThemeBackground constants
#define BP_PUSHBUTTON 1
#define PBS_NORMAL 1
#define PBS_HOT 2
#define PBS_PRESSED 3
// DrawFrameControl constants
#define DFC_BUTTON 4
#define DFCS_HOT 0x1000
#define DFCS_PUSHED 0x0200
#define DFCS_BUTTONPUSH 0x0010
METHOD Paint() CLASS TThemed
local oBrush
//local aInfo := ::DispBegin()
local nState
//FillRect( ::hDC, GetClientRect( ::hWnd ), ::oBrush:hBrush )
::PaintBack(::hDC)
if ::theme!=0
if ::lMOver
if ::lMDown
C5_DrawThemeBackground(::theme,::hDC, BP_PUSHBUTTON,PBS_PRESSED,GetClientRect( ::hWnd ),)
else
C5_DrawThemeBackground(::theme,::hDC, BP_PUSHBUTTON,PBS_HOT,GetClientRect( ::hWnd ),)
endif
else
C5_DrawThemeBackground(::theme,::hDC, BP_PUSHBUTTON,PBS_NORMAL,GetClientRect( ::hWnd ),)
endif
else
nState := DFCS_BUTTONPUSH
if ::lMOver
if ::lMDown
nState := nOR( nState, DFCS_PUSHED)
else
nState := nOR( nState, DFCS_HOT)
endif
endif
DrawFrameControl(::hDC,GetClientRect( ::hWnd ), DFC_BUTTON, nState)
endif
//::DispEnd( aInfo )
return
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TThemed
if nMsg == 794//WM_THEMECHANGED
if ::theme!=0
C5_CloseThemeData(::theme)
endif
::theme = C5_OpenThemeData(::oWnd:hWnd,"BUTTON")
::Refresh()
endif
if nMsg == 675//WM_MOUSELEAVE
::MouseLeave( nHiWord( nLParam ), nLoWord( nLParam ), nWParam )
endif
return ::Super:HandleEvent( nMsg, nWParam, nLParam )
anyone agree with me?
Antonino Perricone