Skip to content

Instantly share code, notes, and snippets.

@letsgoawaydev
Created December 10, 2022 13:29
Show Gist options
  • Save letsgoawaydev/5ebb2437bf47bea4f491af17ceedb5fa to your computer and use it in GitHub Desktop.
Save letsgoawaydev/5ebb2437bf47bea4f491af17ceedb5fa to your computer and use it in GitHub Desktop.
Haxe Native Windows Errors (requires lime for other platform fall back, other wise remove whats not needed)
/**
* Native Windows Alert
*
* using Vbscript Message Box
*
* alert types:
*
* `error`
*
* `question`
*
* `warning`
*
* `info`
*/
import js.Browser;
import openfl.Lib;
function winAlert(message:Null<String>, ?title:Null<String>, ?type:Null<String>)
{
#if windows
if (type == null)
{
t = 64;
}
if (title == null)
{
title = "";
}
else
{
type = type.toLowerCase();
if (type == "error")
{
t = 16;
}
else if (type == "question")
{
t = 32;
}
else if (type == "warning")
{
t = 48;
}
else if (type == "info")
{
t = 64;
}
}
var array:Array<String> = ['vbscript:msgbox("' + message + '",' + t + ',"' + title + '")\\close()'];
var p = new sys.io.Process('"C:/Windows/System32/mshta.exe" ' + array[0]);
p.close();
#else
alert(message, title);
#end
}
function alert(message:Null<String>, ?title:Null<String>):Void
{
if (title == null)
{
title = "";
}
#if !html5
Lib.application.window.alert(message, title);
#else
if (!(title == ""))
{
Browser.alert(title + "\n-------------\n" + message);
}
else
{
Browser.alert(message);
}
#end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment