Win_Msg - A kind of Notification message so easy and friendly Demo

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Win_Msg - A kind of Notification message so easy and friendly Demo

Post by Pablo César »

The only problem in transparency when you click on other window the Notifier lose its transparency...

I added to:

Code: Select all

If ValType(ERROR) = "U"
   aBcolor := If(nTransparency=255,{0,153,0},{0,51,0})
Else
   aBcolor := If(nTransparency=255,{204,0,0},{153,0,0})
Endif
and...

FONTBOLD If(nTransparency=255,.F.,.T.)

When Transparent, leaving bold and bold colors to better visualize ...
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Win_Msg - A kind of Notification message so easy and friendly Demo

Post by Pablo César »

Impossible to use hb_ThreadStart, doesn't it Rathi ?
 
Screen91.png
Screen91.png (4.84 KiB) Viewed 4523 times
 
I read at PCToledo forum where an experimental test THREAD with HMG and he said is not possible in HMG...

Or am I doing something wrong ? :?

SOCORRO Claudio... :o
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Win_Msg - A kind of Notification message so easy and friendly Demo

Post by Rathinagiri »

East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: Win_Msg - A kind of Notification message so easy and friendly Demo

Post by Pablo César »

Yes Rathi. Very useful. Krzysztof make a very good sample.

I think this is the way on..
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: Win_Msg - A kind of Notification message so easy and friendly Demo

Post by KDJ »

Pablo

Very nice job. I like it!

Example how to do this in multi threading:

Code: Select all

/*  
  Win_Msg - A kind of Notification message so easy and friendly Demo
  
  Version.........: 1.1
  Created by......: Pablo César on February 9th, 2017
 */

#include <hmg.ch>

#define HB_THREAD_INHERIT_PUBLIC 1

Function Main()
  LOCAL pThread1
  LOCAL pThread2
  SET WINDOW MAIN OFF
  pThread1 := HB_ThreadStart(HB_THREAD_INHERIT_PUBLIC, @Notifier1(), "Printing file xxxxx.xxx sent to EPSON LX-300" , , 3)
  hb_IdleSleep(4)
  pThread2 := HB_ThreadStart(HB_THREAD_INHERIT_PUBLIC, @Notifier2(), CRLF+"File not found!", 1)
  HB_ThreadJoin(pThread1)
  HB_ThreadJoin(pThread2)
  SET WINDOW MAIN ON
Return Nil

Function Notifier1(cMsg,ERROR,nSeconds)
  LOCAL nHeight := 82, nWidth := 204
  LOCAL nLeft := (GetDesktopWidth() - 5) - nWidth
  LOCAL nTop := (GetDesktopHeight() - 50) - nHeight
  LOCAL hWnd, aBcolor, nWinRow := nTop, nWinCol := nLeft

  DEFAULT nSeconds := 2
  If ValType(ERROR) = "U"
     aBcolor := {0,153,0}
  Else
     aBcolor := {204,0,0}
  Endif

  DEFINE WINDOW Win_Msg1 AT nTop, nLeft WIDTH nWidth HEIGHT nHeight TOPMOST ;
      NOMAXIMIZE NOMINIMIZE NOSIZE NOSYSMENU NOCAPTION BACKCOLOR aBcolor
	
    DEFINE LABEL Label_1
        ROW         10
        COL         10
        WIDTH       nWidth - 20
        HEIGHT      nHeight - 20
        VALUE       cMsg
        FONTNAME    "MS Shell Dlg"
        FONTSIZE    10
        FONTBOLD    .F.
        BACKCOLOR   aBcolor
        FONTCOLOR   WHITE
        CENTERALIGN .T. 
    END LABEL
  END WINDOW

  hWnd := GetFormHandle("Win_Msg1")
  HMG_ChangeWindowStyle(hWnd, WS_EX_CLIENTEDGE, NIL, .T.)

  AnimateWindow(hWnd, (nSeconds*300), AW_VER_NEGATIVE)
  hb_IdleSleep(nSeconds)
  AnimateWindow(hWnd, (nSeconds*1500), (AW_BLEND + AW_HIDE))
  SendMessage( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0 )
Return Nil

Function Notifier2(cMsg,ERROR,nSeconds)
  LOCAL nHeight := 82, nWidth := 204
  LOCAL nLeft := 0
  LOCAL nTop := 0
  LOCAL hWnd, aBcolor, nWinRow := nTop, nWinCol := nLeft

  DEFAULT nSeconds := 2
  If ValType(ERROR) = "U"
     aBcolor := {0,153,0}
  Else
     aBcolor := {204,0,0}
  Endif

  DEFINE WINDOW Win_Msg2 AT nTop, nLeft WIDTH nWidth HEIGHT nHeight TOPMOST ;
      NOMAXIMIZE NOMINIMIZE NOSIZE NOSYSMENU NOCAPTION BACKCOLOR aBcolor
	
    DEFINE LABEL Label_1
        ROW         10
        COL         10
        WIDTH       nWidth - 20
        HEIGHT      nHeight - 20
        VALUE       cMsg
        FONTNAME    "MS Shell Dlg"
        FONTSIZE    10
        FONTBOLD    .F.
        BACKCOLOR   aBcolor
        FONTCOLOR   WHITE
        CENTERALIGN .T. 
    END LABEL
  END WINDOW

  hWnd := GetFormHandle("Win_Msg2")
  HMG_ChangeWindowStyle(hWnd, WS_EX_CLIENTEDGE, NIL, .T.)

  AnimateWindow(hWnd, (nSeconds*300), AW_VER_NEGATIVE)
  hb_IdleSleep(nSeconds)
  AnimateWindow(hWnd, (nSeconds*1500), (AW_BLEND + AW_HIDE))
  SendMessage( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0 )
Return Nil
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Win_Msg - A kind of Notification message so easy and friendly Demo

Post by Rathinagiri »

That is so cool!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Win_Msg - A kind of Notification message so easy and friendly Demo

Post by serge_girard »

Thx Pablo !
Serge
There's nothing you can do that can't be done...
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Win_Msg - A kind of Notification message so easy and friendly Demo

Post by Pablo César »

Hi Krzysztof thank you very much for teaching us a little more about Threads, for your contribution and your compliment and from others.

I'm trying another way with Not_HMG window (registered but not with _HMG_SYSDATA structure) but I'm not finished yet.

Based on your example, I added: hb_ThreadWait, hb_threadQuitRequest

Code: Select all

/*  
  Win_Msg - A kind of Notification message so easy and friendly Demo
  
  Version.........: 1.2
  Created by......: Pablo César on February 11th, 2017
 */

#include "hmg.ch"
#include "MyWindow.ch"

#define HB_THREAD_INHERIT_PUBLIC 1

Function Main()
Load Window Demo2
Demo2.Center
Demo2.Activate
Return Nil

Function Send_Msgs()
LOCAL pThID

StopWindowEventProcedure("Demo2",.T.)

pThID := hb_ThreadStart(HB_THREAD_INHERIT_PUBLIC, @Notifier(), "Printing file xxxxx.xxx sent to EPSON LX-300", , 1)

If hb_ThreadWait( pThID ) = 1
   hb_threadQuitRequest( pThID )
   hb_ThreadStart(HB_THREAD_INHERIT_PUBLIC, @Notifier(), CRLF+"File not found!", 1, 1)
Endif

DoMethod("Demo2","SETFOCUS")
Return 1

Function Notifier(cMsg, ERROR, nSeconds)
LOCAL nHeight := 82, nWidth := 204
LOCAL nLeft := (GetDesktopWidth() - 5) - nWidth
LOCAL nTop := (GetDesktopHeight() - 50) - nHeight
LOCAL hWnd, aBcolor, nWinRow := nTop, nWinCol := nLeft
LOCAL cLastForm := GetFormNameByIndex(GetLastActiveFormIndex())

DEFAULT cMsg := ""
DEFAULT nSeconds := 2

If Empty(cMsg)
   Return Nil
Endif

If ValType(ERROR) = "U"
   aBcolor := {0,153,0}
Else
   aBcolor := {204,0,0}
Endif

// SET WINDOW MAIN OFF // Note need any more for not being HMG window

DEFINE MYWINDOW Win_Msg AT nTop, nLeft WIDTH nWidth HEIGHT nHeight TOPMOST ;
    NOMAXIMIZE NOMINIMIZE NOSIZE NOSYSMENU NOCAPTION BACKCOLOR aBcolor

// hWnd := My_DefineWindow ( "Win_Msg",, nLeft, nTop, nWidth, nHeight, .F., .F., .F., .F., .T.,.F., "",, ,, , ,, aBcolor, , .F. , .T. , .F. , , .T. , ,, , , ,, , , , , , , , , , .F. , , , , .F. , , , , , , , , , , .F. )    
/*
    DEFINE LABEL Label_1
        ROW         10
        COL         10
        WIDTH       nWidth - 20
        HEIGHT      nHeight - 20
        VALUE       cMsg
        FONTNAME    "MS Shell Dlg"
        FONTSIZE    10
        FONTBOLD    .F.
        BACKCOLOR   aBcolor
        FONTCOLOR   WHITE
        CENTERALIGN .T. 
    END LABEL
*/
// END WINDOW
// hWnd := GetFormHandle("Win_Msg")

HMG_ChangeWindowStyle(hWnd, WS_EX_CLIENTEDGE, NIL, .T.)

EnableWindow( hWnd, .T. )
AnimateWindow(hWnd, (nSeconds*300), AW_VER_NEGATIVE)
hb_IdleSleep(nSeconds)
AnimateWindow(hWnd, (nSeconds*1500), (AW_BLEND + AW_HIDE))

// UnRegisterWindow("Win_Msg")

SendMessage( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0 )

StopWindowEventProcedure(cLastForm,.F.)

// SET WINDOW MAIN ON
Return Nil

Function My_DefineWindow( FormName,  ;                  /* 01   "Form_1",*/
                          Caption,  ;                   /* 02           ,*/
                          x,  ;                         /* 03      nLeft,*/
                          y,  ;                         /* 04       nTop,*/
                          w,  ;                         /* 05     nWidth,*/
                          h,  ;                         /* 06    nHeight,*/
                          nominimize,  ;                /* 07        .F.,*/
                          nomaximize,  ;                /* 08        .F.,*/
                          nosize,  ;                    /* 09        .F.,*/
                          nosysmenu, ;                  /* 10        .F.,*/
                          nocaption, ;                  /* 11        .T.,*/
                          StatusBar, ;                  /* 12        .F.,*/
                          StatusText, ;                 /* 13         "",*/
                          initprocedure, ;              /* 14           ,*/
                          ReleaseProcedure, ;           /* 15           ,*/
                          MouseDragProcedure, ;         /* 16           ,*/
                          SizeProcedure, ;              /* 17           ,*/
                          ClickProcedure, ;             /* 18           ,*/
                          MouseMoveProcedure, ;         /* 19           ,*/
                          aRGB, ;                       /* 20    aBcolor,*/
                          PaintProcedure, ;             /* 21           ,*/
                          noshow, ;                     /* 22        .F.,*/
                          topmost, ;                    /* 23        .T.,*/
                          main, ;                       /* 24        .F.,*/
                          icon, ;                       /* 25           ,*/
                          child, ;                      /* 26        .T.,*/
                          fontname, ;                   /* 27           ,*/
                          fontsize, ;                   /* 28           ,*/
                          NotifyIconName, ;             /* 29           ,*/
                          NotifyIconTooltip, ;          /* 30           ,*/
                          NotifyIconLeftClick, ;        /* 31           ,*/
                          GotFocus, ;                   /* 32           ,*/
                          LostFocus, ;                  /* 33           ,*/
                          virtualheight, ;              /* 34           ,*/
                          VirtualWidth, ;               /* 35           ,*/
                          scrollleft, ;                 /* 36           ,*/
                          scrollright, ;                /* 37           ,*/
                          scrollup, ;                   /* 38           ,*/
                          scrolldown, ;                 /* 39           ,*/
                          hscrollbox, ;                 /* 40           ,*/
                          vscrollbox, ;                 /* 41           ,*/
                          helpbutton, ;                 /* 42        .F.,*/
                          maximizeprocedure, ;          /* 43           ,*/
                          minimizeprocedure, ;          /* 44           ,*/
                          cursor, ;                     /* 45           ,*/
                          NoAutoRelease, ;              /* 46        .F.,*/
                          InteractiveCloseProcedure, ;  /* 47           ,*/
                          visible, ;                    /* 48           ,*/
                          autorelease, ;                /* 49           ,*/
                          minbutton, ;                  /* 50           ,*/
                          maxbutton, ;                  /* 51           ,*/
                          sizable, ;                    /* 52           ,*/
                          sysmenu, ;                    /* 53           ,*/
                          titlebar, ;                   /* 54           ,*/
                          cPanelParent, ;               /* 55           ,*/
                          panel ;                       /* 56        .F. */
                        )

LOCAL vscroll , hscroll , BrushHandle , FormHandle, ParentHandle

/* Unused Parameters */
StatusBar := Nil
StatusText := Nil

DEFAULT x := GetDesktopRealLeft()
DEFAULT y := GetDesktopRealTop()
DEFAULT w := GetDeskTopRealWidth()
DEFAULT h := GetDeskTopRealHeight()

DEFAULT nosize        := .Not. sizable
DEFAULT nosysmenu     := .Not. sysmenu
DEFAULT nocaption     := .Not. titlebar
DEFAULT nominimize    := .Not. minbutton
DEFAULT nomaximize    := .Not. maxbutton
DEFAULT NoAutoRelease := .Not. AutoRelease
DEFAULT NoShow        := .Not. Visible

FormName := AllTrim(FormName)

DEFAULT Caption            := ""
DEFAULT scrollup           := ""
DEFAULT scrolldown         := ""
DEFAULT scrollleft         := ""
DEFAULT scrollright        := ""
DEFAULT hscrollbox         := ""
DEFAULT vscrollbox         := ""
DEFAULT InitProcedure      := ""
DEFAULT ReleaseProcedure   := ""
DEFAULT MouseDragProcedure := ""
DEFAULT SizeProcedure      := ""
DEFAULT ClickProcedure     := ""
DEFAULT MouseMoveProcedure := ""
DEFAULT PaintProcedure     := ""
DEFAULT GotFocus           := ""
DEFAULT LostFocus          := ""
DEFAULT VirtualHeight      := 0
DEFAULT VirtualWidth       := 0
DEFAULT aRGB               := { -1, -1, -1 }

If VirtualHeight = 0
   vscroll := .f.
Else
    vscroll := .t.
Endif
If VirtualWidth = 0
   hscroll := .f.
Else
   hscroll := .t.
Endif

UnRegisterWindow(FormName) 
   
If ValType( icon ) == 'U' .and. ValType( _HMG_DefaultIconName ) != 'U'
   icon := _HMG_DefaultIconName
Endif
 
BrushHandle := RegisterWindow( icon, FormName, aRGB ) 

Formhandle = InitWindow( Caption , x, y, w, h, nominimize, nomaximize, nosize, nosysmenu, nocaption, topmost, FormName, ParentHandle, vscroll, hscroll, helpbutton, panel )

If Valtype ( cursor ) != "U"
   SetWindowCursor( Formhandle , cursor )
EndIf

If valtype(NotifyIconName) == "U"
   NotifyIconName := ""
Else
   ShowNotifyIcon( FormHandle , .T., LoadTrayIcon(GETINSTANCE(), NotifyIconName ), NotifyIconTooltip )
Endif

InitDummy(FormHandle)

If VirtualHeight > 0
    SetScrollRange ( Formhandle, SB_VERT, 0, VirtualHeight - h, .T. )
EndIf
If VirtualWidth > 0
    SetScrollRange ( Formhandle, SB_HORZ, 0, VirtualWidth - w, .T. )
EndIf
_HMG_SYSDATA [ 264 ] := .F.
Return (FormHandle)
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Win_Msg - A kind of Notification message so easy and friendly Demo

Post by srvet_claudio »

Rathinagiri wrote: Fri Feb 10, 2017 5:44 am Looks very nice and decent! My small addition to center window and transparency.

Now, until the notifier is removed, does the application stop processing? If yes, can this process be moved to a multi-threading enabled thread?

Code: Select all

/*  
  Win_Msg - A kind of Notification message so easy and friendly Demo
  
  Version.........: 1.1
  Created by......: Pablo César on February 9th, 2017
 */

#include <hmg.ch>

Function Main()
SET WINDOW MAIN OFF
Notifier("Printing file xxxxx.xxx sent to EPSON LX-300",,3)
Notifier(CRLF+"File not found!",1)
Notifier("Printing file xxxxx.xxx sent to EPSON LX-300",,3, .t., 128 )
Notifier(CRLF+"File not found!",1,, .t., 100 )
SET WINDOW MAIN ON
Return Nil

Function Notifier(cMsg,ERROR,nSeconds, lCenter, nTransparency)
LOCAL nHeight := 82, nWidth := 204
LOCAL nLeft := (GetDesktopWidth() - 5) - nWidth
LOCAL nTop := (GetDesktopHeight() - 50) - nHeight
LOCAL hWnd, aBcolor, nWinRow := nTop, nWinCol := nLeft
DEFAULT lCenter := .f.
DEFAULT nTransparency := 255


DEFAULT nSeconds := 2
If ValType(ERROR) = "U"
   aBcolor := {0,153,0}
Else
   aBcolor := {204,0,0}
Endif

DEFINE WINDOW Win_Msg AT nTop, nLeft WIDTH nWidth HEIGHT nHeight TOPMOST ;
    NOMAXIMIZE NOMINIMIZE NOSIZE NOSYSMENU NOCAPTION BACKCOLOR aBcolor
	
    DEFINE LABEL Label_1
        ROW         10
        COL         10
        WIDTH       nWidth - 20
        HEIGHT      nHeight - 20
        VALUE       cMsg
        FONTNAME    "MS Shell Dlg"
        FONTSIZE    10
        FONTBOLD    .F.
        BACKCOLOR   aBcolor
        FONTCOLOR   WHITE
        CENTERALIGN .T. 
    END LABEL

END WINDOW
if lCenter
   center window win_msg
endif
SET WINDOW win_msg TRANSPARENT TO nTransparency
hWnd := GetFormHandle("Win_Msg")
HMG_ChangeWindowStyle(hWnd, WS_EX_CLIENTEDGE, NIL, .T.)

AnimateWindow(hWnd, (nSeconds*300), AW_VER_NEGATIVE)
hb_IdleSleep(nSeconds)
AnimateWindow(hWnd, (nSeconds*1500), (AW_BLEND + AW_HIDE))
SendMessage( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0 )
Return Nil
Change in Notifier function:

hb_IdleSleep(nSeconds)

for this:

nTimeIni := hb_MilliSeconds()
WHILE( ( hb_MilliSeconds() - nTimeIni ) < nSeconds * 1000 )
DO EVENTS
hb_releaseCPU()
ENDDO
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
Post Reply