Si a alguien le es útil, os aseguro que se puede mejorar mucho más
Saludos
- Code: Select all Expand view
//----------------------------------------------------------------------------//
// Author : ( c ) Cristobal Navarro Lopez
// Date : 04/2017
// Updated : 10/2022
//----------------------------------------------------------------------------//
#include "Fivewin.ch"
#define WM_NCPAINT 0x085 //133
#define WM_NCLBUTTONDOWN 0x0A1
#define WM_NCLBUTTONUP 0x0A2
#define WM_NCLBUTTONDBLCLK 0x0A3
#define WM_NCRBUTTONDOWN 0x0A4
#define WM_LBUTTONDBLCLK 0x203
#define RDW_NOFRAME 2048
#define RDW_VALIDATE 8
#define RDW_NOCHILDREN 64
Static oWnd
Function Main()
Fw_SetUnicode( .T. )
oWnd := TCWnd():New( 120, 120, 500, 780, "My Title", WS_CLIPCHILDREN, , ;
,,,,,,,,, .T., .F., .T., .T., .T.,, "oWnd",, .T. )
oWnd:bValid := { || oWnd:SetButtons( .T. ), .T. }
oWnd:SetColor( CLR_WHITE, METRO_STEEL )
oWnd:bValid := { || oWnd:SetButtons( .T. ), .T. }
ACTIVATE WINDOW oWnd //CENTERED
Return nil
//----------------------------------------------------------------------------//
//
//----------------------------------------------------------------------------//
CLASS TCWnd FROM TWindow
CLASSDATA lRegistered AS LOGICAL INIT .F.
DATA oOldMnu
DATA cFont INIT "Calibri"
DATA nHFont INIT 14
DATA lShowHideMnu INIT .F.
DATA oBtnExitUI
DATA oBtnMaxiUI
DATA oBtnMiniUI
DATA nPaint INIT 0
DATA lSkin INIT .F.
DATA wParam
DATA lParam
METHOD HandleEvent( nMsg, nWParam, nLParam )
METHOD NcPaint()
METHOD SetButtons()
ENDCLASS
//----------------------------------------------------------------------------//
METHOD SetButtons( lEnd ) CLASS TCWnd
DEFAULT lEnd := .F.
if !lEnd
if Empty( ::oBtnExitUI )
::oBtnExitUI := GDIBmp():New( "..\icons\red.ico" )
endif
if Empty( ::oBtnMaxiUI )
::oBtnMaxiUI := GDIBmp():New( "..\icons\yellow.ico" )
endif
if Empty( ::oBtnMiniUI )
::oBtnMiniUI := GDIBmp():New( "..\icons\gray.ico" )
endif
else
::oBtnExitUI:End()
::oBtnMaxiUI:End()
::oBtnMiniUI:End()
endif
Return nil
//----------------------------------------------------------------------------//
METHOD NcPaint( hRgnd ) CLASS TCWnd
local hDC := GetWindowDC( if( Empty( hRgnd ), ::hWnd, hRgnd ) )
local oBrush
local oBrush1
local oBrush2
local oBrush3
local oGraphics
local nR := nRgbRed( ::nClrPane )
local nG := nRgbGreen( ::nClrPane )
local nB := nRgbBlue( ::nClrPane )
local nRT := nRgbRed( ::nClrText )
local nGT := nRgbGreen( ::nClrText )
local nBT := nRgbBlue( ::nClrText )
local nHTitle := GetSysMetrics( 4 ) + 1
local nHMenu := GetSysMetrics( 15 )
local oPen := Pen():New( 255, 220, 220, 220, 1, .T. )
oBrush2 := Brush():NewSolidBrush( 255, nRT, nGT, nBT )
oBrush1 := Brush():NewSolidBrush( 255, nR, nG, nB )
oBrush := Brush():NewSolidBrush( 255, 200, 200, 200 )
oBrush3 := Brush():NewSolidBrush( 255, 0, 255, 0 )
::nPaint++
if ::nPaint = 1
::SetButtons()
::cCaption := "Titulo A"
endif
oGraphics := Graphics():New( hDC )
//if ::nPaint = 1
oGraphics:DrawRect( , oBrush1, 0, nHTitle + 1 + if( Empty( ::oBar ), 0, ::oBar:nHeight ) + ;
if( !Empty( ::oMenu ), nHMenu, 0 ),;
::nWidth, ::nHeight - nHTitle - if( Empty( ::oBar ), 0, ::oBar:nHeight ) - ;
if( !Empty( ::oMenu ), nHMenu, 0 ) )
oGraphics:DrawRect( , oBrush , 0, 0, ::nWidth, nHTitle + 1 )
oGraphics:DrawText( 1, Int( ( ::nWidth - hb_Utf8Len( ::cCaption ) * 14 ) / 2 ) , ;
::cCaption, ::cFont, ::nHFont, oBrush2 )
oGraphics:DrawImage( ::oBtnExitUI, Int( ( nHTitle - 16 ) / 2 ) + 1, 4, 16, 16 )
oGraphics:DrawImage( ::oBtnMaxiUI, Int( ( nHTitle - 16 ) / 2 ) + 1, 4 + 20, 16, 16 )
oGraphics:DrawImage( ::oBtnMiniUI, Int( ( nHTitle - 16 ) / 2 ) + 1, 4 + 40, 16, 16 )
oGraphics:Destroy()
ReleaseDc( if( Empty( hRgnd ), ::hWnd, hRgnd ), hDC )
oBrush:Destroy()
oBrush1:Destroy()
oBrush2:Destroy()
oBrush3:Destroy()
oPen:Destroy()
RedrawWindow( ::hWnd, { 0, 0, ::nWidth, nHTitle }, hrgnd, nOR( RDW_VALIDATE, RDW_NOFRAME, RDW_NOCHILDREN ) ) //, RDW_NOERASE ) )
Return nil
//----------------------------------------------------------------------------//
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TCWnd
local lContinue := .T.
local lSetFocus := .T.
local nCol
local nRow
local nMsgDef
local nHTitle := GetSysMetrics( 4 ) + 2
local aPoint := { 0, 0 }
local n
local uRet
Do Case
Case nMsg == WM_NCPAINT
::wParam := nWParam
lContinue := .F.
Case nMsg == WM_SETFOCUS
lContinue := .F.
lSetFocus := .T.
::wParam := Nil
Case nMsg == WM_KILLFOCUS
lContinue := .F.
::wParam := Nil
Case nMsg == WM_NCRBUTTONDOWN
nCol := GetXParam( nLParam )
nRow := GetYParam( nLParam )
aPoint := ScreenToClient( ::hWnd, { nRow, nCol } )
//lContinue := .F.
Case nMsg == WM_NCLBUTTONDOWN //WM_NCLBUTTONUP //
nCol := GetXParam( nLParam )
nRow := GetYParam( nLParam )
aPoint := ScreenToClient( ::hWnd, { nRow, nCol } )
if aPoint[ 1 ] < 0
// Area Caption
endif
Case nMsg == WM_NCLBUTTONDBLCLK
nCol := GetXParam( nLParam )
nRow := GetYParam( nLParam )
aPoint := ScreenToClient( ::hWnd, { nRow, nCol } )
if aPoint[ 2 ] >= 4 .and. aPoint[ 2 ] <= 20
::End()
endif
if aPoint[ 2 ] > 20 .and. aPoint[ 2 ] <= 40
MsgInfo( "Green" )
endif
if aPoint[ 2 ] > 40 .and. aPoint[ 2 ] <= 60
MsgInfo( "Gray" )
endif
lContinue := .F.
::wParam := Nil
Case nMsg == WM_LBUTTONDBLCLK
// No funciona en el caption
nCol := GetXParam( nLParam )
nRow := GetYParam( nLParam )
//lContinue := .F.
::wParam := Nil
Otherwise
::wParam := Nil
lContinue := .T.
EndCase
if !lContinue
::NcPaint( ::wParam )
uRet := ::Super:HandleEvent( nMsg, nWParam, nLParam )
if lSetFocus
::SetFocus()
endif
endif
return if( !lContinue, 0, ::Super:HandleEvent( nMsg, nWParam, nLParam ) )
//----------------------------------------------------------------------------//
#pragma BEGINDUMP
#include "windows.h"
#include "hbapi.h"
HB_FUNC( REDRAWWINDOW ) // ( hWnd )
{
HWND hwnd = ( HWND ) hb_parnl( 1 ) ;
PRECT rect = ( PRECT ) hb_parvnl( 2 );
HRGN hrgn = ( HRGN ) hb_parnl( 3 );
INT flags = hb_parni( 4 );
hb_retl( RedrawWindow( ( HWND ) hwnd, ( PRECT ) rect, ( HRGN ) hrgn, flags ) );
}
#pragma ENDDUMP