#include "FiveWin.ch"
#include "Constant.ch"
#define WM_NCHITTEST 132 // 0x84
#define WM_UPDATEUISTATE 296 // 0x0128
function Main()
local oWnd,o,oFont
DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-14
DEFINE WINDOW oWnd TITLE "Test"
o := TGroupBmp():New( 10, 10, 30, 100, "Test TGroupBmp",oWnd)
o:lTransparent:=.t.
o:nClrText := CLR_BLACK
o:nClrPane := CLR_WHITE
o:cBmp:="fivetech.BMP"
ACTIVATE WINDOW oWnd
return 0
//--------------------------------------------------------------------------------//
CLASS TGroupBmp FROM TControl
CLASSDATA lRegistered AS LOGICAL
DATA lOverClose
DATA cCaption
DATA cBmp
METHOD New( nTop, nLeft, nBottom, nRight, cLabel, oWnd, nClrText, nClrPane,;
lPixel, lDesign, oFont, lTransparent, nWidth, nHeight,cBmp) CONSTRUCTOR
METHOD Initiate( hDlg )
METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
METHOD Paint()
METHOD LButtonDown( nRow, nCol, nFlags )
METHOD MouseMove ( nRow, nCol, nFlags )
METHOD LButtonUp ( nRow, nCol, nFlags )
METHOD EraseBkGnd( hDC ) INLINE 1
METHOD HandleEvent( nMsg, nWParam, nLParam )
ENDCLASS
//--------------------------------------------------------------------------------------------//
METHOD New( nTop, nLeft, nBottom, nRight, cLabel, oWnd, nClrText, nClrPane,;
lPixel, lDesign, oFont, lTransparent, nWidth, nHeight,cBmp) CLASS TGroupBmp
DEFAULT nTop := 0, nLeft := 0, nBottom := 3, nRight := 3,;
oWnd := GetWndDefault(),;
nClrText := oWnd:nClrText, nClrPane := oWnd:nClrPane,;
lPixel := .f., lDesign := .f.,;
lTransparent := .f., oFont := oWnd:oFont
::nTop = nTop * If( lPixel, 1, GRP_CHARPIX_H ) // 14
::nLeft = nLeft * If( lPixel, 1, GRP_CHARPIX_W ) // 7
if nWidth != nil
::nRight = ::nLeft + nWidth
else
::nRight = nRight * If( lPixel, 1, GRP_CHARPIX_W ) // 7
endif
if nHeight != nil
::nBottom = ::nTop + nHeight
else
::nBottom = nBottom * If( lPixel, 1, GRP_CHARPIX_H ) // 14
endif
::cCaption = cLabel
* ::cBmp = cBmp
::oWnd = oWnd
::nStyle = nOR( WS_CHILD, WS_VISIBLE, BS_GROUPBOX,;
If( lDesign, nOr( WS_TABSTOP, WS_CLIPSIBLINGS ), 0 ) )
::nId = ::GetNewId()
::lUpdate = .f.
::lDrag = lDesign
::lTransparent = lTransparent
::SetColor( nClrText, nClrPane )
if lTransparent
::SetBrush( TBrush():New( "NULL" ) )
endIf
if ! Empty( oWnd:hWnd )
::Create( "BUTTON" )
oWnd:AddControl( Self )
else
oWnd:DefControl( Self )
endif
if oFont != nil
::SetFont( oFont )
endIf
if lDesign
::CheckDots()
endif
return Self
//--------------------------------------------------------------------------------------------//
METHOD Initiate( hDlg ) CLASS TGroupBmp
::Super:Initiate( hDlg )
if Empty( ::cCaption )
::cCaption = ::GetText()
else
::SetText( ::cCaption )
endif
return nil
//--------------------------------------------------------------------------------------------//
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TGroupBmp
local nResult
if ::lDrag .and. nMsg == WM_NCHITTEST // To have a standard behavior on Clicks
return DefWindowProc( ::hWnd, nMsg, nWParam, nLParam )
endif
if nMsg == WM_UPDATEUISTATE // Groups and contained controls were erased when pressing ALT
nResult = ::Super:HandleEvent( nMsg, nWParam, nLParam )
::oWnd:Refresh( .f. ) // EMG: added .f. to alleviate flickering
return nResult
endif
return ::Super:HandleEvent( nMsg, nWParam, nLParam )
//--------------------------------------------------------------------------------------------//
METHOD Paint() CLASS TGroupBmp
local aSize, hOldFont, oFont
local hBmp,nWBmp,nHBmp
local hBmpBtnNormal,nWBmpBtnNormal,nHBmpBtnNormal
local hBmpBtnClosed,nWBmpBtnClosed,nHBmpBtnClosed
hBmp := ReadBitmap( 0, ::cBmp )
hBmpBtnNormal :=BmpEBExpanded() //ReadBitmap( 0, )
hBmpBtnClosed :=BmpEBCollapsed()
if hBmp != 0
nWBmp := nBmpWidth( hBmp )
nHBmp := nBmpHeight( hBmp )
endif
if hBmpBtnNormal != 0
nWBmpBtnNormal := nBmpWidth( hBmpBtnNormal )
nHBmpBtnNormal := nBmpHeight( hBmpBtnNormal )
endif
CallWindowProc( ::nOldProc, ::hWnd, WM_PAINT, ::hDC, 0 )
//write Bitmap
if hBmp != 0
DrawMasked( ::hDC, hBmp, 0, 6 )
Endif
//if Lclosed
if hBmpBtnNormal != 0
DrawMasked( ::hDC, hBmpBtnNormal, 9, ::nWidth-20 )
Endif
//endif
//write caption
if IsAppThemed() .and. ! Empty( ::cCaption )
oFont = If( ::oFont != nil, ::oFont, ::oWnd:oFont )
ASize = GetLabelDim( ::hWnd, ::cCaption, oFont:hFont )
hOldFont = SelectObject( ::hDC, oFont:hFont )
SetBrushOrgEx( ::hDC, nBmpWidth( ::oBrush:hBitmap ) - ::nLeft, nBmpHeight( ::oBrush:hBitmap ) - ::nTop )
FillRect( ::hDC, { 0, 7, aSize[ 2 ] + 6, aSize[ 1 ] + 11 }, ::oBrush:hBrush )
SetBkMode( ::hDC, 1 )
TextOut( ::hDC, 0, 9, ::cCaption, Len( ::cCaption ) )
SelectObject( ::hDC, hOldFont )
endif
return 0
//--------------------------------------------------------------------------------------------//
METHOD LButtonDown( nRow, nCol, nFlags ) CLASS TGroupBmp
return 0
//--------------------------------------------------------------------------------------------//
METHOD MouseMove ( nRow, nCol, nFlags ) CLASS TGroupBmp
return 0
//--------------------------------------------------------------------------------------------//
METHOD LButtonUp ( nRow, nCol, nFlags ) CLASS TGroupBmp
return