设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
Project1 查看内容

免DLL的输入法

2008-8-6 21:26| 发布者: 秀秀| 查看: 1763| 评论: 0|原作者: 神思|来自: 点此进入发布帖

摘要: #------------------------------------------------------------------------------# Moonlight INN# http://cgi.members.interq.or.jp/aquarius/rasetsu/# RaTTiE# [email protected]#------------------------------------------------------------# EasyCon

#------------------------------------------------------------------------------
# Moonlight INN
# http://cgi.members.interq.or.jp/aquarius/rasetsu/
# RaTTiE
# [email protected]
#------------------------------------------------------------
# EasyConv::s2u(text) : S-JIS -> UTF-8
# EasyConv::u2s(text) : UTF-8 -> S-JIS
#==============================================
module EasyConv
# API梡掕悢掕媊
   CP_ACP = 0
   CP_UTF8 = 65001

#--------------------------------------------------------------------------
# 仠 S-JIS -> UTF-8
#--------------------------------------------------------------------------
def s2u(text)
# API掕媊
   m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
   w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')

# S-JIS -> Unicode
   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);

# Unicode -> UTF-8
   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);
  
   return ret
end
# module_function偲偟偰岞奐
module_function :s2u
#--------------------------------------------------------------------------
# 仠 UTF-8 -> S-JIS
#--------------------------------------------------------------------------
def u2s(text)
# API掕媊
   m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
   w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')

# UTF-8 -> Unicode
   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);

# Unicode -> S-JIS
   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
# module_function偲偟偰岞奐
module_function :u2s
end

#========================================
# 本脚本来自www.66rpg.com
#========================================

 

 

#==============================================================================
# ■ TextBox
#------------------------------------------------------------------------------
#  设置输入窗口
#==============================================================================
class TextBox
# 获取程序模块
GetModuleHandle = Win32API.new("kernel32", "GetModuleHandle", "p", "l")
# 创建窗口
CreateWindowEx = Win32API.new("user32", "CreateWindowExA", "lppllllllllp", "l")
# 销毁窗口
DestroyWindow = Win32API.new("user32", "DestroyWindow", "l", "l")
# 控制窗口显示
ShowWindow = Win32API.new("user32", "ShowWindow", "ll", "l")
# 设置输入焦点
SetFocus = Win32API.new("user32", "SetFocus", "l", "l")
# 获取活动的窗口
GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, "l")
# 获取控件文字
GetWindowText = Win32API.new("user32", "GetWindowTextA", "lpl", "l")
# 获取控件文字长度
GetWindowTextLength = Win32API.new("user32", "GetWindowTextLength", "l", "l")
# 设置控件文字
SetWindowTextA = Win32API.new("user32", "SetWindowTextA", "lp", "l")
# 刷新窗口
UpdateWindow = Win32API.new("user32", "UpdateWindow", "l", "l")
# 常数
WS_CHILD = 0x40000000
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
def initialize(w, h)
    @wnd = CreateWindowEx.call(1, "Edit", "", WS_CHILD, 0,0,w,h,GetActiveWindow.call,1,GetModuleHandle.call(nil),1)
    SetFocus.call(@wnd)
    ShowWindow.call(@wnd,0)
end
#--------------------------------------------------------------------------
# ● 释放窗口
#--------------------------------------------------------------------------
def dispose
    DestroyWindow.call(@wnd)
end
#--------------------------------------------------------------------------
# ● 获取txt
#--------------------------------------------------------------------------
def txt
    length = GetWindowTextLength.call(@wnd)
    lpstring = Array.new(length+1).pack("C*")
    GetWindowText.call(@wnd, lpstring, length)
    lpstring.delete!("\0")
    t = EasyConv::s2u(lpstring)
    return t
end
#--------------------------------------------------------------------------
# ● 设置txt
#--------------------------------------------------------------------------
def set_txt(txt)
    str = EasyConv::u2s(txt)
    SetWindowTextA.call(@wnd, str)
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def update
    UpdateWindow.call(@wnd)
    SetFocus.call(@wnd)
end
end

t = TextBox.new(320, 24)
v = Viewport.new(160, 228, 320 , 24)
sprite = Sprite.new(v)
sprite.bitmap = Bitmap.new(320,24)
sprite.bitmap.fill_rect(0,0,320,24,Color.new(0,0,0))
sprite.bitmap.fill_rect(1,1,318,22,Color.new(255,255,255))
cou = Sprite.new(v)
cou.bitmap = Bitmap.new(1, 22)
cou.bitmap.fill_rect(0, 0, 1, 22, Color.new(0,255,255))
cou.y = 1
s = t.txt
loop {
Graphics.update
Input.update
t.update
cou.visible = Time.now.sec % 2 == 0
if s != t.txt
cou.visible = true
s = t.txt
sprite.bitmap.clear
sprite.bitmap.font.size = 18
sprite.bitmap.font.color.set(0,0,0)
sprite.bitmap.fill_rect(0,0,320,24,Color.new(0,0,0))
sprite.bitmap.fill_rect(1,1,318,22,Color.new(255,255,255))
sprite.bitmap.draw_text(0,0,320,24,s)
cou.x = 1 + sprite.bitmap.text_size(s).width
end
}

1

鲜花

刚表态过的朋友 (1 人)

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2025-1-11 12:57

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

返回顶部