-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRS_ExtendMessageBox.rb
81 lines (75 loc) · 2.72 KB
/
RS_ExtendMessageBox.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#================================================================
# The MIT License
# Copyright (c) 2020 biud436
# ---------------------------------------------------------------
# Free for commercial and non commercial use.
#================================================================
#==============================================================================
# ** Extend MessageBox
# Author : biud436
# Date : 2015.12.19.
# Version : 1.0
#==============================================================================
# ** Terms of Use
#==============================================================================
# Free for commercial and non-commercial use
#==============================================================================
# ** Example
#------------------------------------------------------------------------------
# msgbox_yesno "선택하시겠습니까?" do |i|
# if i
# msgbox "확인 버튼을 눌렀습니다"
# else
# msgbox "취소 버튼을 눌렀습니다."
# end
# end
#==============================================================================
$imported = {} if $imported.nil?
$imported["RS_ExtendMessageBox"] = true
module Unicode
MultiByteToWideChar = Win32API.new('Kernel32','MultiByteToWideChar','llpipi','i')
WideCharToMultiByte = Win32API.new('Kernel32','WideCharToMultiByte','llpipipp','i')
UTF_8 = 65001
#--------------------------------------------------------------------------
# * MBCS -> WBCS
#--------------------------------------------------------------------------
def unicode!
buf = "\0" * (self.size * 2 + 1)
MultiByteToWideChar.call(UTF_8, 0, self, -1, buf, buf.size)
buf
end
#--------------------------------------------------------------------------
# * WBCS -> MBCS
#--------------------------------------------------------------------------
def unicode_s
buf = "\0" * (self.size * 2 + 1)
WideCharToMultiByte.call(UTF_8, 0, self, -1, buf, buf.size, nil, nil)
buf.delete("\0")
end
end
class String
include Unicode
end
module Utils
FindWindowW = Win32API.new('User32', 'FindWindowW', 'pp', 'l')
MessageBoxW = Win32API.new('User32', 'MessageBoxW', 'lppl', 'i')
GetWindowTextW = Win32API.new('User32', 'GetWindowTextW', 'lpl', 'i')
HWND = FindWindowW.call("RGSS Player".unicode!, 0)
MB_YESNO = 4
IDYES = 6
def self.window_name
buffer = (0.chr) * 128
GetWindowTextW.call(HWND, buffer, buffer.size)
buffer.delete!(0.chr)
end
end
module Kernel
module_function
def msgbox_yesno(context, &block)
hwnd = Utils::HWND
window_name = Utils.window_name.unicode!
type = Utils::MB_YESNO
result = Utils::MessageBoxW.call(hwnd, context.unicode!, window_name, type) == Utils::IDYES
block.call(result)
end
end