Post by muXed on Aug 16, 2020 13:39:40 GMT -5
Evening all!
On a recent project i've had to use toast notifications (A.K.A win10 notification messages)
Thought i'd share the code. Although actual true libertybasic code is minimal in this example... I'm sure there are better ways of utilising toaster notifications and using liberty herself instead of cmd
However my requirements were simple and i'm lacking in knowledg so here is my easy example:-
Please see below...
On a recent project i've had to use toast notifications (A.K.A win10 notification messages)
Thought i'd share the code. Although actual true libertybasic code is minimal in this example... I'm sure there are better ways of utilising toaster notifications and using liberty herself instead of cmd
However my requirements were simple and i'm lacking in knowledg so here is my easy example:-
Please see below...
' Window 10+ Only....
nomainwin
REM Enter message below
toastmsg$ = "Test"
open "test.bat" for output as #f
print #f, "@if (@x)==(@y) @end /* JScript comment"
print #f, "@echo off"
print #f, "setlocal"
print #f, "del /q /f %~n0.exe >nul 2>&1"
print #f,"for /f ";chr$(34);"tokens=* delims=";chr$(34); " %%v in ('dir /b /s /a:-d /o:-n ";chr$(34); "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe";chr$(34);"') do ("
print #f, "set ";chr$(34);"jsc=%%v";chr$(34)
print #f,")"
print #f, "if not exist ";chr$(34); "%~n0.exe";chr$(34);" ("
print #f, chr$(34); "%jsc%";chr$(34);" /nologo /out:";chr$(34);"%~n0.exe";chr$(34); " ";chr$(34);"%~dpsfnx0";chr$(34)
print #f, ")"
print #f, "if exist ";chr$(34);"%~n0.exe";chr$(34);" ( "
print #f, " ";chr$(34);"%~n0.exe";chr$(34);" %* "
print #f, ")"
print #f, "endlocal & exit /b %errorlevel%"
print #f, "end of jscript comment*/"
print #f, "import System;"
print #f, "import System.Windows;"
print #f, "import System.Windows.Forms;"
print #f, "import System.Drawing;"
print #f, "import System.Drawing.SystemIcons;"
print #f, "var notification;"
print #f, "try {"
print #f, " notification = new System.Windows.Forms.NotifyIcon();"
print #f, "} catch (Application){"
print #f, "}"
print #f,"notification.Icon = System.Drawing.SystemIcons.Information; // Could be Application,Asterisk,Error,Exclamation,Hand,Information,Question,Shield,Warning,WinLogo"
print #f, "notification.BalloonTipText = ";chr$(34);toastmsg$;chr$(34)
print #f, "notification.Visible = true;"
print #f, "// optional - BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;"
print #f, "// optional - BalloonTipTitle = ";chr$(34);toastmsg$;chr$(34);
print #f, "// Display for 2 seconds."
print #f, "notification.ShowBalloonTip(5000);"
print #f, "System.Threading.Thread.Sleep(5100);"
print #f, "notification.Dispose();"
close #f
run "test.bat /c", HIDE
end
nomainwin
REM Enter message below
toastmsg$ = "Test"
open "test.bat" for output as #f
print #f, "@if (@x)==(@y) @end /* JScript comment"
print #f, "@echo off"
print #f, "setlocal"
print #f, "del /q /f %~n0.exe >nul 2>&1"
print #f,"for /f ";chr$(34);"tokens=* delims=";chr$(34); " %%v in ('dir /b /s /a:-d /o:-n ";chr$(34); "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe";chr$(34);"') do ("
print #f, "set ";chr$(34);"jsc=%%v";chr$(34)
print #f,")"
print #f, "if not exist ";chr$(34); "%~n0.exe";chr$(34);" ("
print #f, chr$(34); "%jsc%";chr$(34);" /nologo /out:";chr$(34);"%~n0.exe";chr$(34); " ";chr$(34);"%~dpsfnx0";chr$(34)
print #f, ")"
print #f, "if exist ";chr$(34);"%~n0.exe";chr$(34);" ( "
print #f, " ";chr$(34);"%~n0.exe";chr$(34);" %* "
print #f, ")"
print #f, "endlocal & exit /b %errorlevel%"
print #f, "end of jscript comment*/"
print #f, "import System;"
print #f, "import System.Windows;"
print #f, "import System.Windows.Forms;"
print #f, "import System.Drawing;"
print #f, "import System.Drawing.SystemIcons;"
print #f, "var notification;"
print #f, "try {"
print #f, " notification = new System.Windows.Forms.NotifyIcon();"
print #f, "} catch (Application){"
print #f, "}"
print #f,"notification.Icon = System.Drawing.SystemIcons.Information; // Could be Application,Asterisk,Error,Exclamation,Hand,Information,Question,Shield,Warning,WinLogo"
print #f, "notification.BalloonTipText = ";chr$(34);toastmsg$;chr$(34)
print #f, "notification.Visible = true;"
print #f, "// optional - BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;"
print #f, "// optional - BalloonTipTitle = ";chr$(34);toastmsg$;chr$(34);
print #f, "// Display for 2 seconds."
print #f, "notification.ShowBalloonTip(5000);"
print #f, "System.Threading.Thread.Sleep(5100);"
print #f, "notification.Dispose();"
close #f
run "test.bat /c", HIDE
end