# 按钮常量
BUTTONS_OK = 0 #只有确定
BUTTONS_OKCANCEL = 1 #确定/取消
BUTTONS_ABORTRETRYIGNORE = 2 #终止/重试/跳过
BUTTONS_YESNO = 4 #是/否
# 返回码常量
CLICKED_OK = 1 #按下确定
CLICKED_CANCEL = 2 #按下取消
CLICKED_ABORT = 3 #按下终止
CLICKED_RETRY = 4 #按下重试
CLICKED_IGNORE = 5 #按下无视
CLICKED_YES = 6 #按下是
CLICKED_NO = 7 #按下否
#系统函数导入
MSGBOX = Win32API.new('user32','MessageBoxW','LPPL','L')
MBWC = Win32API.new("kernel32","MultiByteToWideChar",'LLPLPL','L')
#获取游戏窗口的"把柄"
HWND = Win32API.new('user32', 'FindWindow', 'PP','L').call('RGSS Player',nil)
#修正UTF-8字符的问题
def multi_to_wide(txt)
int = MBWC.call(65001, 0, txt, -1, nil, 0)
return "" if int <= 0
buf = ' ' * int * 2
MBWC.call(65001, 0, txt, -1, buf, int)
return buf + "\0\0"
end
#显示讯息窗
#递入参数:内容,标题,按钮设定
#返回内容:按下的按钮
def message_box(txt, title = "", buttons = BUTTONS_OK)
return MSGBOX.call(HWND, multi_to_wide(txt), multi_to_wide(title), buttons)
end
#范例:显示讯息窗
message_box("讯息内容", "讯息标题")
#范例:显示讯息窗,按钮设置为:是/否
response = message_box("内容", "标题", BUTTONS_YESNO)
if response == CLICKED_YES
p "用户选择了是"
else
p "用户选择了否"
end
# 按钮常量
BUTTONS_OK = 0 #只有确定
BUTTONS_OKCANCEL = 1 #确定/取消
BUTTONS_ABORTRETRYIGNORE = 2 #终止/重试/跳过
BUTTONS_YESNO = 4 #是/否
# 返回码常量
CLICKED_OK = 1 #按下确定
CLICKED_CANCEL = 2 #按下取消
CLICKED_ABORT = 3 #按下终止
CLICKED_RETRY = 4 #按下重试
CLICKED_IGNORE = 5 #按下无视
CLICKED_YES = 6 #按下是
CLICKED_NO = 7 #按下否
#系统函数导入
MSGBOX = Win32API.new('user32','MessageBoxW','LPPL','L')
MBWC = Win32API.new("kernel32","MultiByteToWideChar",'LLPLPL','L')
#获取游戏窗口的"把柄"
HWND = Win32API.new('user32', 'FindWindow', 'PP','L').call('RGSS Player',nil)
#修正UTF-8字符的问题
def multi_to_wide(txt)
int = MBWC.call(65001, 0, txt, -1, nil, 0)
return "" if int <= 0
buf = ' ' * int * 2
MBWC.call(65001, 0, txt, -1, buf, int)
return buf + "\0\0"
end
#显示讯息窗
#递入参数:内容,标题,按钮设定
#返回内容:按下的按钮
def message_box(txt, title = "", buttons = BUTTONS_OK)
return MSGBOX.call(HWND, multi_to_wide(txt), multi_to_wide(title), buttons)
end
#范例:显示讯息窗
message_box("讯息内容", "讯息标题")
#范例:显示讯息窗,按钮设置为:是/否
response = message_box("内容", "标题", BUTTONS_YESNO)
if response == CLICKED_YES
p "用户选择了是"
else
p "用户选择了否"
end