| 赞 | 95 |
| VIP | |
| 好人卡 | |
| 积分 | 69 |
| 经验 | |
| 最后登录 | 2025-2-12 |
| 在线时间 | 7027 小时 |
- 梦石
- 0
- 星屑
- 6891
- 在线时间
- 7027 小时
- 注册时间
- 2013-11-2
- 回帖
- 1263
 
|
发表于 2017-3-12 14:46:22
|
显示全部楼层
本帖最后由 RaidenInfinity 于 2017-3-12 15:56 编辑
[pre lang="ruby"]
# 按钮常量
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
[/pre]
RGSS3自带的msgbox的确是不够用的。因此得另外开Win32API呼叫系统方法来执行显示。
基本上是用了user32.dll里面的MessageBoxW系统API函数,然后需要kernel32的MultiByteToWideChar来修正UTF-8字符。
(这是因为MessageBoxW需要UTF-16编码的字符串作为参数,而RGSS3用的是UTF-8) |
评分
-
查看全部评分
|