Page 1 of 3

Desktop Alerts

PostPosted: Mon Mar 07, 2016 12:34 pm
by Silvio.Falconi
How I can create a small Desktop Alert ?

Desktop Alert is similar to the MessageBox colored ( with an icon or an image) and it can be show on bottom or on left or on right with a small animation

sample: (from web)
Image

Re: Desktop Alerts

PostPosted: Mon Mar 07, 2016 9:40 pm
by Antonio Linares
Silvio,

A first quick try:

Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local oWnd

   DEFINE WINDOW oWnd TITLE "Click me for a desktop notification"

   ACTIVATE WINDOW oWnd ;
      ON CLICK DesktopAlert( oWnd )

return nil

function DesktopAlert( oWnd )

   local oDlg, oBrush, hLogo := FWLogoBitMap()

   DEFINE BRUSH oBrush GRADIENT { { 1, nRgb( 221, 236, 253 ), nRgb( 95, 131, 179 ) } }

   DEFINE DIALOG oDlg STYLE nOr( WS_POPUP, WS_BORDER ) BRUSH oBrush
   
   ACTIVATE DIALOG oDlg ;
      ON INIT ( oDlg:SetPos( ScreenHeight() - 120, ScreenWidth() - 400 ),;
                oDlg:SetSize( 328, 73 ), BuildTimer( oDlg ) ) ;
      ON CLICK oDlg:End() ;          
      ON PAINT DrawBitmap( hDC, hLogo, 6, 6 ) ;
      VALID ( DeleteObject( hLogo ), .T. ) ;
      NOWAIT
     
   oBrush:End()  
   oWnd:SetFocus()
   
return nil  

function BuildTimer( oDlg )

   local oTimer, nStart := Seconds()
   
   DEFINE TIMER oTimer OF oDlg ;
      INTERVAL 10;
      ACTION If( Seconds() - nStart > 5, oDlg:End(),)
   
   ACTIVATE TIMER oTimer
   
return nil  


Image

Re: Desktop Alerts

PostPosted: Mon Mar 07, 2016 10:24 pm
by TimStone
Actually, a good idea. I can easily see this being useful. 2nd parameter could reference icon and 3rd parameter could contain text to display.

Tim

Re: Desktop Alerts

PostPosted: Mon Mar 07, 2016 11:34 pm
by cnavarro
A small improvement

Code: Select all  Expand view


#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oWnd

   DEFINE WINDOW oWnd TITLE "Click me for a desktop notification"

   ACTIVATE WINDOW oWnd ;
      ON CLICK DesktopAlert( oWnd )

return nil

//----------------------------------------------------------------------------//

function DesktopAlert( oWnd )

   local oDlg
   local oBrush
   local hLogo := FWLogoBitMap()

   DEFINE BRUSH oBrush GRADIENT { { 1, nRgb( 221, 236, 253 ), nRgb( 95, 131, 179 ) } }

   DEFINE DIALOG oDlg STYLE nOr( WS_POPUP, WS_BORDER ) BRUSH oBrush ;
      SIZE 328, 73

   ACTIVATE DIALOG oDlg ;
      ON INIT ( BuildTimer( oDlg ) ) ;
      ON CLICK oDlg:End() ;          
      ON PAINT DrawBitmap( hDC, hLogo, 6, 6 ) ;
      VALID ( DeleteObject( hLogo ), .T. ) ;
      NOWAIT
     
   oBrush:End()  
   oWnd:SetFocus()
   
return nil  

//----------------------------------------------------------------------------//

function BuildTimer( oDlg )

   local oTimer
   local nStart := Seconds()

   oDlg:SetPos( ScreenHeight() - 80, ScreenWidth() - 350 )
   DEFINE TIMER oTimer OF oDlg ;
      INTERVAL 10;
      ACTION If( Seconds() - nStart > 5, oDlg:End(),)
   
   ACTIVATE TIMER oTimer
   
return nil  

//----------------------------------------------------------------------------//

 

Re: Desktop Alerts

PostPosted: Mon Mar 07, 2016 11:39 pm
by Antonio Linares
With shadow effect :-)

Image

Code: Select all  Expand view
#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oWnd

   DEFINE WINDOW oWnd TITLE "Click me for a desktop notification"

   ACTIVATE WINDOW oWnd ;
      ON CLICK DesktopAlert( oWnd )

return nil

//----------------------------------------------------------------------------//

function DesktopAlert( oWnd )

   local oDlg
   local oBrush
   local hLogo := FWLogoBitMap()

   DEFINE BRUSH oBrush GRADIENT { { 1, nRgb( 221, 236, 253 ), nRgb( 95, 131, 179 ) } }

   DEFINE DIALOG oDlg STYLE nOr( WS_POPUP, WS_BORDER ) BRUSH oBrush ;
      SIZE 328, 73

   ACTIVATE DIALOG oDlg ;
      ON INIT ( oDlg:Shadow(), BuildTimer( oDlg ) ) ;
      ON CLICK oDlg:End() ;          
      ON PAINT DrawBitmap( hDC, hLogo, 6, 6 ) ;
      VALID ( DeleteObject( hLogo ), .T. ) ;
      NOWAIT
     
   oBrush:End()  
   oWnd:SetFocus()
   
return nil  

//----------------------------------------------------------------------------//

function BuildTimer( oDlg )

   local oTimer
   local nStart := Seconds()

   oDlg:SetPos( ScreenHeight() - 80, ScreenWidth( 0 ) - 350 )
   
   DEFINE TIMER oTimer OF oDlg ;
      INTERVAL 10;
      ACTION If( Seconds() - nStart > 5, oDlg:End(),)
   
   ACTIVATE TIMER oTimer
   
return nil  

//----------------------------------------------------------------------------//
 

Re: Desktop Alerts

PostPosted: Tue Mar 08, 2016 7:14 am
by Antonio Linares
With transparent and shadow effects:

Image

Code: Select all  Expand view
#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oWnd

   DEFINE WINDOW oWnd TITLE "Click me for a desktop notification"

   ACTIVATE WINDOW oWnd ;
      ON CLICK DesktopAlert( oWnd )

return nil

//----------------------------------------------------------------------------//

function DesktopAlert( oWnd )

   local oDlg
   local oBrush
   local hLogo := FWLogoBitMap()

   DEFINE BRUSH oBrush GRADIENT { { 1, nRgb( 221, 236, 253 ), nRgb( 95, 131, 179 ) } }

   DEFINE DIALOG oDlg STYLE nOr( WS_POPUP, WS_BORDER ) BRUSH oBrush ;
      SIZE 328, 73

   ACTIVATE DIALOG oDlg ;
      ON INIT ( SetTransparent( oDlg ), oDlg:Shadow(), BuildTimer( oDlg ) ) ;
      ON CLICK oDlg:End() ;          
      ON PAINT DrawBitmap( hDC, hLogo, 6, 6 ) ;
      VALID ( DeleteObject( hLogo ), .T. ) ;
      NOWAIT
     
   oBrush:End()  
   oWnd:SetFocus()
   
return nil  

//----------------------------------------------------------------------------//

function BuildTimer( oDlg )

   local oTimer
   local nStart := Seconds()

   oDlg:SetPos( ScreenHeight() - 80, ScreenWidth( 0 ) - 350 )
   
   DEFINE TIMER oTimer OF oDlg ;
      INTERVAL 10;
      ACTION If( Seconds() - nStart > 5, oDlg:End(),)
   
   ACTIVATE TIMER oTimer
   
return nil  

//----------------------------------------------------------------------------//

#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

//----------------------------------------------------------------------------//
 

Re: Desktop Alerts

PostPosted: Tue Mar 08, 2016 8:12 am
by Silvio.Falconi
Wonderful is the beginning.
Antonio thanks!!

Re: Desktop Alerts

PostPosted: Tue Mar 08, 2016 9:36 am
by Silvio.Falconi
Antonio,

I found a document where explain Desktop Alerts sections:

1. Caption Area and your sample have this
2. Drop-down, Pin, and Close buttons
3. Image and your sample have this
4. Text Area - easy to create
5. Alert Buttons down the IMAGE ( two smal buttons) probable made with icons
6. Footer Text


the Drop-Down button must have a menupopup with noptions as for a sample "snooze alert 15 minutes"
http://help.infragistics.com/Help/Doc/WinForms/2013.1/CLR4.0/HTML/WinDesktopAlert_The_Look_and_Feel_of_WinDesktopAlert.html

and I tried to create a small class TDesktopAlert and ask to YOU to help me to build it ( thanks!!)

I thinked to use a charcter with Marlet "r" to simulate close buttons see Function closebutton( hDC, nTop, nLeft, lOver )



Code: Select all  Expand view

 
#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 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()

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

    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

//------------------------------------------------------------------------------------------//


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


//-------------------------------------------------------------------------------------------//


    #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

    //----------------------------------------------------------------------------/

 

Re: Desktop Alerts

PostPosted: Tue Mar 08, 2016 9:41 am
by Antonio Linares
Silvio,

Could you post a screenshot of yours ?

Re: Desktop Alerts

PostPosted: Tue Mar 08, 2016 9:46 am
by Silvio.Falconi
not run also

I not Know as simulate a dialog into Paint method

Re: Desktop Alerts

PostPosted: Tue Mar 08, 2016 9:48 am
by Silvio.Falconi
I correct some bugs
But also I not see the dialog

Code: Select all  Expand view

 
#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

    //----------------------------------------------------------------------------/

Re: Desktop Alerts

PostPosted: Tue Mar 08, 2016 10:12 am
by Antonio Linares
Silvio,

You need to add

CLASSDATA lRegistered INIT .F.

Re: Desktop Alerts

PostPosted: Tue Mar 08, 2016 10:19 am
by Antonio Linares
Showing a text message:

Image

Code: Select all  Expand view
#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oWnd

   DEFINE WINDOW oWnd TITLE "Click me for a desktop notification"

   ACTIVATE WINDOW oWnd ;
      ON CLICK DesktopAlert( oWnd )

return nil

//----------------------------------------------------------------------------//

function DesktopAlert( oWnd )

   local oDlg, oBrush, oFont
   local hLogo := FWLogoBitMap()

   DEFINE FONT oFont NAME "Verdana" BOLD

   DEFINE BRUSH oBrush GRADIENT { { 1, nRgb( 221, 236, 253 ), nRgb( 95, 131, 179 ) } }

   DEFINE DIALOG oDlg STYLE nOr( WS_POPUP, WS_BORDER ) BRUSH oBrush ;
      SIZE 328, 73

   @ 0.6, 6 SAY "A desktop notification" OF oDlg TRANSPARENT FONT oFont

   ACTIVATE DIALOG oDlg ;
      ON INIT ( SetTransparent( oDlg ), oDlg:Shadow(), BuildTimer( oDlg ) ) ;
      ON CLICK oDlg:End() ;          
      ON PAINT DrawBitmap( hDC, hLogo, 9, 9 ) ;
      VALID ( DeleteObject( hLogo ), .T. ) ;
      NOWAIT
     
   oBrush:End()
   oFont:End()
   oWnd:SetFocus()
   
return nil  

//----------------------------------------------------------------------------//

function BuildTimer( oDlg )

   local oTimer
   local nStart := Seconds()

   oDlg:SetPos( ScreenHeight() - 80, ScreenWidth( 0 ) - 350 )
   
   DEFINE TIMER oTimer OF oDlg ;
      INTERVAL 10;
      ACTION If( Seconds() - nStart > 5, oDlg:End(),)
   
   ACTIVATE TIMER oTimer
   
return nil  

//----------------------------------------------------------------------------//

#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

//----------------------------------------------------------------------------//
 

Re: Desktop Alerts

PostPosted: Tue Mar 08, 2016 11:51 am
by Silvio.Falconi
I add btnclose and btndown
I add text area sample two rows

Code: Select all  Expand view
   #include "FiveWin.ch"

    //----------------------------------------------------------------------------//

    function Main()

       local oWnd

       DEFINE WINDOW oWnd TITLE "Click me for a desktop notification"

       ACTIVATE WINDOW oWnd ;
          ON CLICK DesktopAlert( oWnd )

    return nil

    //----------------------------------------------------------------------------//

    function DesktopAlert( oWnd )

       local oDlg, oBrush, oFont
       local hLogo := FWLogoBitMap()
       local oBtnClose
       local oBtnDown
       local oFontBody


       DEFINE FONT oFont NAME "Verdana" BOLD
       DEFINE FONT oFontBody NAME "Verdana"  SIZE 0, -9
       DEFINE BRUSH oBrush GRADIENT { { 1, nRgb( 221, 236, 253 ), nRgb( 95, 131, 179 ) } }

       DEFINE DIALOG oDlg STYLE nOr( WS_POPUP, WS_BORDER ) BRUSH oBrush ;
          SIZE 328, 73

       @ 0.6, 6 SAY "A desktop notification" OF oDlg TRANSPARENT FONT oFont


       @ 1.2, 6 SAY "This a sample text area."+CRLF+"This a sample text area." OF oDlg;
                     TRANSPARENT FONT oFontBody SIZE 100,30



      @ 0.6, oDlg:nWidth-175 BTNBMP oBtnClose FILENAME "C:\Work\fwh\bitmaps\16x16\cancel.bmp" ;
      SIZE 10, 10 OF oDlg NOBORDER ACTION oDlg:End()

       @ 0.6, oDlg:nWidth-185 BTNBMP oBtnDown FILENAME "C:\Work\fwh\bitmaps\16x16\darrow.bmp" ;
      SIZE 10, 10 OF oDlg NOBORDER ACTION oDlg:End()


       oBtnClose:ltransparent:=.t.
       oBtnDown:ltransparent:=.t.

       ACTIVATE DIALOG oDlg ;
          ON INIT ( SetTransparent( oDlg ), oDlg:Shadow(), BuildTimer( oDlg ) ) ;
          ON CLICK oDlg:End() ;          
          ON PAINT DrawBitmap( hDC, hLogo, 9, 9 ) ;
          VALID ( DeleteObject( hLogo ), .T. ) ;
          NOWAIT
         
       oBrush:End()
       oFont:End()
       oWnd:SetFocus()
       
    return nil  

    //----------------------------------------------------------------------------//

    function BuildTimer( oDlg )

       local oTimer
       local nStart := Seconds()

       oDlg:SetPos( ScreenHeight() - 80, ScreenWidth( 0 ) - 350 )
       
       DEFINE TIMER oTimer OF oDlg ;
          INTERVAL 10;
          ACTION If( Seconds() - nStart > 5, oDlg:End(),)
       
       ACTIVATE TIMER oTimer
       
    return nil  

    //----------------------------------------------------------------------------//

    #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

    //----------------------------------------------------------------------------//
   

Re: Desktop Alerts

PostPosted: Tue Mar 08, 2016 12:43 pm
by ukoenig
Some month ago,
a created a solution showing a message with popup, animated images, round corners and shadow.
Instead of a dialog, I used TTitle because of more possible visual effects.
I used < SYSWAIT(nWait) > instead of a timer. Selecting < nWait = 0 > the message stays visible on screen.
Calculated text top/left positions, in relation to the possible defined 4 image-positions

Image

best regards
Uwe :D