赞 | 5 |
VIP | 359 |
好人卡 | 195 |
积分 | 3 |
经验 | 560179 |
最后登录 | 2024-5-17 |
在线时间 | 1373 小时 |
Lv2.观梦者
- 梦石
- 0
- 星屑
- 275
- 在线时间
- 1373 小时
- 注册时间
- 2005-10-16
- 帖子
- 5113
|
- #==============================================================================
- # ■ EasyConv
- #------------------------------------------------------------------------------
- # 转码模块。
- #==============================================================================
- module EasyConv
- #--------------------------------------------------------------------------
- # ● 常量定义
- #--------------------------------------------------------------------------
- CP_ACP = 0
- CP_UTF8 = 65001
- #--------------------------------------------------------------------------
- # ● 模块函数
- #--------------------------------------------------------------------------
- module_function
- #--------------------------------------------------------------------------
- # ● 转码
- #--------------------------------------------------------------------------
- def s2u(text)
- m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
- w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
- len = m2w.call(CP_ACP, 0, text, -1, nil, 0)
- buf = "\0" * (len*2)
- m2w.call(CP_ACP, 0, text, -1, buf, buf.size/2)
- len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil)
- ret = "\0" * len
- w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil)
- ret[-1] = ""
- return ret
- end
- #--------------------------------------------------------------------------
- # ● 转码
- #--------------------------------------------------------------------------
- def u2s(text)
- m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
- w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
- len = m2w.call(CP_UTF8, 0, text, -1, nil, 0)
- buf = "\0" * (len*2)
- m2w.call(CP_UTF8, 0, text, -1, buf, buf.size/2)
- len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil)
- ret = "\0" * len
- w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil)
- return ret
- end
- end
- HWND = Win32API.new("user32", "GetActiveWindow", nil, 'l')
- module Kernel
- unless defined?(old_exit)
- MessageBox = Win32API.new('user32', 'MessageBox', "p p p i", 'i')
- alias old_exit exit
- def exit(*arg)
- begin
- old_exit(*arg) if arg[0] == true
- text1 = "确定要退出游戏么?"
- text2 = "退出游戏"
- msg = MessageBox.call(HWND.call, EasyConv.u2s(text1), EasyConv.u2s(text2), 1)
- if msg == 1
- old_exit(*arg)
- end
- rescue
- old_exit(*arg)
- end
- end
- end
- end
复制代码 以前写过这样的东西,其实还蛮好使的~ |
|