Code: Select all
#include "fivewin.ch"
function Main()
local oWnd
DEFINE WINDOW oWnd TITLE "Click me for a desktop notification"
ACTIVATE WINDOW oWnd ;
ON CLICK Test(oWnd)
return nil
Function Test(oWnd)
Loca oTest
oTest:= TDesktopAlert():New(10, 10, 328, 73, oWnd)
return nil
CLASS TDesktopAlert FROM TWindow
CLASSDATA lRegistered AS LOGICAL
DATA cCaptionArea AS CHARACTER INIT ""
DATA cTextArea AS CHARACTER INIT ""
DATA cFooterArea AS CHARACTER INIT ""
DATA cImageArea
DATA oTimer, nTimer
DATA aBtnClose AS ARRAY INIT {0,0,0,0}
DATA lOverClose AS LOGICAL INIT .F.
DATA oBrushArea
DATA hRgn
DATA nClrPane AS NUMERIC INIT nRgb( 221, 236, 253 )
DATA nClrPane2 AS NUMERIC INIT nRgb( 95, 131, 179 )
DATA nClrText AS NUMERIC INIT CLR_BLACK
DATA nClrBorder AS NUMERIC INIT RGB(59,97,156)
METHOD New( nTop, nLeft, nWidth, nHeight, oWnd ) CONSTRUCTOR
METHOD Display() INLINE ::BeginPaint(),::Paint(),::EndPaint(),0
METHOD Paint()
METHOD BtnClose( hDC,nTop,nLeft )
METHOD MouseMove( nRow, nCol, nKeyFlags )
METHOD LButtonDown( nRow, nCol, nKeyFlags )
METHOD Default()
METHOD BtnDown( hDC,nTop,nLeft )
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( nTop, nLeft, nWidth, nHeight, oWnd, cCaptionArea,;
cImageArea,nClrPane,nClrPane2,nClrText ) CLASS TDesktopAlert
if nClrPane == nil; nClrPane := CLR_WHITE; endif
if nClrPane2 == nil; nClrPane2 := CLR_WHITE; endif
if nClrText == nil; nClrText := CLR_BLACK; endif
::nTop := nTop
::nLeft := nLeft
::nBottom := nTop + nHeight
::nRight := nLeft + nWidth
::oWnd := oWnd
::nClrPane := nClrPane
::nClrPane2 := nClrPane2
::nClrText := nClrText
::cCaptionArea := cCaptionArea
::cImageArea := cImageArea
::nStyle := nOr( WS_POPUP, WS_BORDER )
::Register()
if !Empty( oWnd:hWnd )
::Create()
::Default()
oWnd:AddControl( Self )
else
oWnd:DefControl( Self )
endif
if ! Empty( oWnd:hWnd )
::Default()
endif
return self
//------------------------------------------------------------------------------------------//
METHOD Default() CLASS TDesktopAlert
local rc := { 0, 0, 73, 323 }
Local hRgn
Local hRgn2
Local hRgn3
local o := self
* DEFAULT lShowDlg := .F.
::hRgn = CreateRoundRectRgn( { rc[ 1 ], rc[ 2 ], rc[ 3 ], rc[ 4 ] },;
5, 5 )
SetWindowRgn( ::hWnd, ::hRgn, .T. )
DeleteObject( ::hRgn )
return 0
//------------------------------------------------------------------------------------------//
METHOD MouseMove( nRow, nCol, nKeyFlags ) CLASS TDesktopAlert
::lOverClose := PtInRect( nRow, nCol, ::aBtnClose )
if ::lOverClose
::oWnd:End()
endif
return 0 //super:MouseMove( nRow, nCol, nKeyFlags )
//------------------------------------------------------------------------------------------//
METHOD LButtonDown( nRow, nCol, nKeyFlags ) CLASS TDesktopAlert
return 0
//------------------------------------------------------------------------------------------//
METHOD Paint() CLASS TDesktopAlert
local hDCMem := CreateCompatibleDC( ::hDC )
local rc := GetClientRect(::hWnd)
local nH := rc[3]-rc[1]
local nStart := Seconds()
if ::oTimer != nil
::oTimer:Deactivate()
::oTimer:End()
endif
::oWnd:SetPos( ScreenHeight() - 80, ScreenWidth( 0 ) - 350 )
DEFINE TIMER ::oTimer INTERVAL ::nTimer ;
ACTION If( Seconds() - nStart > 5, ::oWnd:End(),) OF Self
ACTIVATE TIMER ::oTimer
if ::lCloseBtn
::BtnClose( hDCMem, (nH/2)-4, rc[4]-12, ::lOverClose )
endif
SelectObject( hDCMem, hOldBmp )
DeleteDC( hDCMem )
return 0
//------------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------//
METHOD BtnClose( hDC,nTop,nLeft ) CLASS TDesktopAlert
::aBtnClose := closebutton( hDC, nTop, nLeft, ::lOverClose )
return 0
METHOD BtnDown( hDC,nTop,nLeft ) CLASS TDesktopAlert
::aBtndown := DropDownbutton( hDC, nTop, nLeft, ::lOverClose )
return 0
//------------------------------------------------------------------------------------------//
static function Line( hDC, nTop, nLeft, nBottom, nRight, nColor, nWidth )
local hPen, hOldPen
DEFAULT nColor := CLR_BLACK, nWidth := 1
hPen = CreatePen( PS_SOLID, nWidth, nColor )
hOldPen = SelectObject( hDC, hPen )
MoveTo( hDC, nLeft, nTop )
LineTo( hDC, nRight, nTop )
SelectObject( hDC, hOldPen )
DeleteObject( hPen )
return 0
//------------------------------------------------------------------------------------------//
Static Function closebutton( hDC, nTop, nLeft, lOver )
local oFont, hOldFont
local aRect
local nMode
// create a X button
DEFAULT lOver := .f.
nMode := SetBkMode( hDC, 1 )
oFont := TFont():New( "Marlett", 0, -10, .f.,.f.,,,,.f.,.f.,.f., 1 )
hOldFont := SelectObject( hDC, oFont:hFont )
aRect := {nTop,nLeft,nTop+10,nLeft+ 9}
TextOut( hDC, aRect[1]+1, aRect[2], "r" )
SelectObject( hDC, hOldFont )
oFont:End()
SetBkMode( hDC, nMode )
if lOver
Box(hDC,aRect)
endif
return aRect
//------------------------------------------------------------------------------------------//
Static Function DropDownbutton( hDC, nTop, nLeft, lOver )
local oFont, hOldFont
local aRect
local nMode
// create a X button
DEFAULT lOver := .f.
nMode := SetBkMode( hDC, 1 )
oFont := TFont():New( "Marlett", 0, -10, .f.,.f.,,,,.f.,.f.,.f., 1 )
hOldFont := SelectObject( hDC, oFont:hFont )
aRect := {nTop,nLeft,nTop+10,nLeft+ 9}
TextOut( hDC, aRect[1]+1, aRect[2], "u" )
SelectObject( hDC, hOldFont )
oFont:End()
SetBkMode( hDC, nMode )
if lOver
Box(hDC,aRect)
endif
return aRect
//-------------------------------------------------------------------------------------------//
#define GWL_EXSTYLE -20
#define WS_EX_LAYERED 524288
static function SetTransparent( oDlg )
SetWindowLong( oDlg:hWnd, GWL_EXSTYLE, nOr( GetWindowLong( oDlg:hWnd, GWL_EXSTYLE ), WS_EX_LAYERED ) )
SetLayeredWindowAttributes( oDlg:hWnd, 0, 180, 2 )
return nil
//----------------------------------------------------------------------------/