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