First of all, please understand that English is not my mother tongue, so I use a translator
It's a script that worked well on VX Ace. This is a script that lets you pop up a Windows message box and include icons, titles, and content that you want. As I moved on to RMMV, I used Opal, Online Ruby to js coverter.
I have no programming knowledge, so I've seen a lot of errors, but I haven't solved them.
So I'm going to post the code here
Things I've tried : NW.js update, jquery ui(but it's not what I wanted, so I throw away), delete all plugins and just use this one, code grammar check
Somebody please help me
It's a script that worked well on VX Ace. This is a script that lets you pop up a Windows message box and include icons, titles, and content that you want. As I moved on to RMMV, I used Opal, Online Ruby to js coverter.
I have no programming knowledge, so I've seen a lot of errors, but I haven't solved them.
So I'm going to post the code here
Things I've tried : NW.js update, jquery ui(but it's not what I wanted, so I throw away), delete all plugins and just use this one, code grammar check
Somebody please help me
Ruby:
#────────────────────────────────────────────────────────────────────────────
# * msgbox, @cheapmunk.naver, 2014. 12. 27
#────────────────────────────────────────────────────────────────────────────
MessageBox = Win32API.new('user32', 'MessageBoxW', 'lppl', 'l')
GetActiveWindow = Win32API.new('user32', 'GetActiveWindow', 'v', 'l')
MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'llplpl', 'l')
WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'llplplpp', 'l')
GetWindowText = Win32API.new('user32', 'GetWindowText', 'lpl', 'l')
GetWindowTextLength = Win32API.new('user32', 'GetWindowTextLength', 'l', 'l')
GetPrivateProfileString = Win32API.new('kernel32', 'GetPrivateProfileStringA', 'pppplp', 'l')
FindWindow = Win32API.new('user32', 'FindWindow', 'pp', 'l')
module MB
OK = 0
OKCANCEL = 1
ABORTRETRYIGNORE = 2
YESNOCANCEL = 3
YESNO = 4
RETRYCANCEL = 5
CANCELTRYCONTINUE = 6
HELP = 0x00004000
ICONSTOP = 16
ICONQUESTION = 32
ICONEXCLAMATION = 48
ICONINFORMATION = 64
DEFBUTTON1 = 0x00000000
DEFBUTTON2 = 0x00000100
DEFBUTTON3 = 0x00000200
DEFBUTTON4 = 0x00000300
RIGHT = 0x00080000
RTLREADING = 0x00100000
TOPMOST = 0x00040000
IDOK = 1
IDCANCEL = 2
IDABORT = 3
IDRETRY = 4
IDIGNORE = 5
IDYES = 6
IDNO = 7
IDTRYAGAIN = 10
IDCONTINUE = 11
module_function
def hwnd
GetPrivateProfileString.call('Game', 'Title', '', buf='\0'*256, 255, './Game.ini')
handle = FindWindow.call('RGSS Player', buf)
return (handle == 0 ? GetActiveWindow.call : handle)
end;HWND = hwnd
def s2u(text)
len = MultiByteToWideChar.call(0, 0, text, -1, nil, 0)
buf = '\0' * (len*2)
MultiByteToWideChar.call(0, 0, text, -1, buf, buf.size/2)
len = WideCharToMultiByte.call(65001, 0, buf, -1, nil, 0, nil, nil)
ret = '\0' * len
WideCharToMultiByte.call(65001, 0, buf, -1, ret, ret.size, nil, nil)
return ret.delete('\000')
end
def caption
length = GetWindowTextLength.call(HWND)
str = '\0' * (length + 1)
GetWindowText.call(HWND, str, length + 1)
return s2u(str)
end
end
class String
def to_unicode
len = MultiByteToWideChar.call(65001, 0, self, -1, 0, 0)
MultiByteToWideChar.call(65001, 0, self, -1, buf = '\0' * len, len)
return buf
end
end
module Kernel
def msgbox(lpText = String.new, wType = 0, lpCaption = MB.caption)
MessageBox.call(MB::HWND, lpText.to_s.to_unicode, lpCaption.to_s.to_unicode, wType)
end
end
JavaScript:
//=============================================================================
//메세지박스
//=============================================================================
/*:
* 메세지박스
*/
Opal.queue(function(Opal) {/* Generated by Opal 1.7.4 */
var $const_set = Opal.const_set, $module = Opal.module, $rb_times = Opal.rb_times, $eqeq = Opal.eqeq, $def = Opal.def, $rb_divide = Opal.rb_divide, $rb_plus = Opal.rb_plus, $klass = Opal.klass, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil, $$$ = Opal.$$$;
Opal.add_stubs('new,module_function,call,*,==,hwnd,/,size,delete,+,s2u,caption,to_unicode,to_s');
$const_set($nesting[0], 'MessageBox', $$('Win32API').$new("user32", "MessageBoxW", "lppl", "l"));
$const_set($nesting[0], 'GetActiveWindow', $$('Win32API').$new("user32", "GetActiveWindow", "v", "l"));
$const_set($nesting[0], 'MultiByteToWideChar', $$('Win32API').$new("kernel32", "MultiByteToWideChar", "llplpl", "l"));
$const_set($nesting[0], 'WideCharToMultiByte', $$('Win32API').$new("kernel32", "WideCharToMultiByte", "llplplpp", "l"));
$const_set($nesting[0], 'GetWindowText', $$('Win32API').$new("user32", "GetWindowText", "lpl", "l"));
$const_set($nesting[0], 'GetWindowTextLength', $$('Win32API').$new("user32", "GetWindowTextLength", "l", "l"));
$const_set($nesting[0], 'GetPrivateProfileString', $$('Win32API').$new("kernel32", "GetPrivateProfileStringA", "pppplp", "l"));
$const_set($nesting[0], 'FindWindow', $$('Win32API').$new("user32", "FindWindow", "pp", "l"));
(function($base, $parent_nesting) {
var self = $module($base, 'MB');
var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
$const_set($nesting[0], 'OK', 0);
$const_set($nesting[0], 'OKCANCEL', 1);
$const_set($nesting[0], 'ABORTRETRYIGNORE', 2);
$const_set($nesting[0], 'YESNOCANCEL', 3);
$const_set($nesting[0], 'YESNO', 4);
$const_set($nesting[0], 'RETRYCANCEL', 5);
$const_set($nesting[0], 'CANCELTRYCONTINUE', 6);
$const_set($nesting[0], 'HELP', 16384);
$const_set($nesting[0], 'ICONSTOP', 16);
$const_set($nesting[0], 'ICONQUESTION', 32);
$const_set($nesting[0], 'ICONEXCLAMATION', 48);
$const_set($nesting[0], 'ICONINFORMATION', 64);
$const_set($nesting[0], 'DEFBUTTON1', 0);
$const_set($nesting[0], 'DEFBUTTON2', 256);
$const_set($nesting[0], 'DEFBUTTON3', 512);
$const_set($nesting[0], 'DEFBUTTON4', 768);
$const_set($nesting[0], 'RIGHT', 524288);
$const_set($nesting[0], 'RTLREADING', 1048576);
$const_set($nesting[0], 'TOPMOST', 262144);
$const_set($nesting[0], 'IDOK', 1);
$const_set($nesting[0], 'IDCANCEL', 2);
$const_set($nesting[0], 'IDABORT', 3);
$const_set($nesting[0], 'IDRETRY', 4);
$const_set($nesting[0], 'IDIGNORE', 5);
$const_set($nesting[0], 'IDYES', 6);
$const_set($nesting[0], 'IDNO', 7);
$const_set($nesting[0], 'IDTRYAGAIN', 10);
$const_set($nesting[0], 'IDCONTINUE', 11);
self.$module_function();
$def(self, '$hwnd', function $$hwnd() {
var buf = nil, handle = nil;
$$('GetPrivateProfileString').$call("Game", "Title", "", (buf = $rb_times("\\0", 256)), 255, "./Game.ini");
handle = $$('FindWindow').$call("RGSS Player", buf);
return ($eqeq(handle, 0) ? ($$('GetActiveWindow').$call()) : (handle));
});
$const_set($nesting[0], 'HWND', self.$hwnd());
$def(self, '$s2u', function $$s2u(text) {
var len = nil, buf = nil, ret = nil;
len = $$('MultiByteToWideChar').$call(0, 0, text, -1, nil, 0);
buf = $rb_times("\\0", $rb_times(len, 2));
$$('MultiByteToWideChar').$call(0, 0, text, -1, buf, $rb_divide(buf.$size(), 2));
len = $$('WideCharToMultiByte').$call(65001, 0, buf, -1, nil, 0, nil, nil);
ret = $rb_times("\\0", len);
$$('WideCharToMultiByte').$call(65001, 0, buf, -1, ret, ret.$size(), nil, nil);
return ret.$delete("\\000");
});
return $def(self, '$caption', function $$caption() {
var self = this, length = nil, str = nil;
length = $$('GetWindowTextLength').$call($$('HWND'));
str = $rb_times("\\0", $rb_plus(length, 1));
$$('GetWindowText').$call($$('HWND'), str, $rb_plus(length, 1));
return self.$s2u(str);
});
})($nesting[0], $nesting);
(function($base, $super, $parent_nesting) {
var self = $klass($base, $super, 'String');
var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
return $def(self, '$to_unicode', function $$to_unicode() {
var self = this, len = nil, buf = nil;
len = $$('MultiByteToWideChar').$call(65001, 0, self, -1, 0, 0);
$$('MultiByteToWideChar').$call(65001, 0, self, -1, (buf = $rb_times("\\0", len)), len);
return buf;
});
})($nesting[0], null, $nesting);
return (function($base, $parent_nesting) {
var self = $module($base, 'Kernel');
var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
return $def(self, '$msgbox', function $$msgbox(lpText, wType, lpCaption) {
if (lpText === null) lpText = $$('String').$new();
if (wType === null) wType = 0;
if (lpCaption === null) lpCaption = $$('MB').$caption();
return $$('MessageBox').$call($$$($$('MB'), 'HWND'), lpText.$to_s().$to_unicode(), lpCaption.$to_s().$to_unicode(), wType);
}, -1);
})($nesting[0], $nesting);
});
JavaScript:
const MessageBox = new Win32API("user32", "MessageBoxW", "lppl", "l");
const GetActiveWindow = new Win32API("user32", "GetActiveWindow", "v", "l");
const MultiByteToWideChar = new Win32API("kernel32", "MultiByteToWideChar", "llplpl", "l");
const WideCharToMultiByte = new Win32API("kernel32", "WideCharToMultiByte", "llplplpp", "l");
const GetWindowText = new Win32API("user32", "GetWindowText", "lpl", "l");
const GetWindowTextLength = new Win32API("user32", "GetWindowTextLength", "l", "l");
const GetPrivateProfileString = new Win32API("kernel32", "GetPrivateProfileStringA", "pppplp", "l");
const FindWindow = new Win32API("user32", "FindWindow", "pp", "l");
MB = (() => {
const OK = 0;
const OKCANCEL = 1;
const ABORTRETRYIGNORE = 2;
const YESNOCANCEL = 3;
const YESNO = 4;
const RETRYCANCEL = 5;
const CANCELTRYCONTINUE = 6;
const HELP = 16384;
const ICONSTOP = 16;
const ICONQUESTION = 32;
const ICONEXCLAMATION = 48;
const ICONINFORMATION = 64;
const DEFBUTTON1 = 0;
const DEFBUTTON2 = 256;
const DEFBUTTON3 = 512;
const DEFBUTTON4 = 768;
const RIGHT = 524288;
const RTLREADING = 1048576;
const TOPMOST = 262144;
const IDOK = 1;
const IDCANCEL = 2;
const IDABORT = 3;
const IDRETRY = 4;
const IDIGNORE = 5;
const IDYES = 6;
const IDNO = 7;
const IDTRYAGAIN = 10;
const IDCONTINUE = 11;
let module_function;
function hwnd() {
GetPrivateProfileString.call(
"Game",
"Title",
"",
buf = "\\0".repeat(256),
255,
"./Game.ini"
);
let handle = FindWindow.call("RGSS Player", buf);
return handle === 0 ? GetActiveWindow.call : handle
};
const HWND = hwnd;
function s2u(text) {
let len = MultiByteToWideChar.call(0, 0, text, -1, null, 0);
let buf = "\\0".repeat(len * 2);
MultiByteToWideChar.call(0, 0, text, -1, buf, buf.size / 2);
len = WideCharToMultiByte.call(
65001,
0,
buf,
-1,
null,
0,
null,
null
);
let ret = "\\0".repeat(len);
WideCharToMultiByte.call(
65001,
0,
buf,
-1,
ret,
ret.size,
null,
null
);
return delete ret.\000
};
function caption() {
let length = GetWindowTextLength.call(HWND);
let str = "\\0".repeat(length + 1);
GetWindowText.call(HWND, str, length + 1);
return s2u(str)
};
return {
OK,
OKCANCEL,
ABORTRETRYIGNORE,
YESNOCANCEL,
YESNO,
RETRYCANCEL,
CANCELTRYCONTINUE,
HELP,
ICONSTOP,
ICONQUESTION,
ICONEXCLAMATION,
ICONINFORMATION,
DEFBUTTON1,
DEFBUTTON2,
DEFBUTTON3,
DEFBUTTON4,
RIGHT,
RTLREADING,
TOPMOST,
IDOK,
IDCANCEL,
IDABORT,
IDRETRY,
IDIGNORE,
IDYES,
IDNO,
IDTRYAGAIN,
IDCONTINUE,
hwnd,
HWND,
s2u,
caption
}
})();
class String {
get to_unicode() {
let len = MultiByteToWideChar.call(65001, 0, this, -1, 0, 0);
MultiByteToWideChar.call(
65001,
0,
this,
-1,
buf = "\\0".repeat(len),
len
);
return buf
}
};
const Kernel = {msgbox(lpText=new String, wType=0, lpCaption=MB.caption) {
return MessageBox.call(
MB.HWND,
lpText.toString().to_unicode,
lpCaption.toString().to_unicode,
wType
)
}}