Project1

标题: 调用窗口问题 [打印本页]

作者: sblkhgm    时间: 2013-1-29 11:16
标题: 调用窗口问题
这脚本在那里改他的窗口 大小 怎么让调用的窗口贴紧游戏窗口的右侧
  1. class String
  2.   
  3.   CP_ACP = 0
  4.   CP_UTF8 = 65001
  5.   
  6.   def u2s
  7.     m2w = Win32API.new("kernel32", "MultiByteToWideChar", "ilpipi", "i")
  8.     w2m = Win32API.new("kernel32", "WideCharToMultiByte", "ilpipipp", "i")
  9.    
  10.     len = m2w.call(CP_UTF8, 0, self, -1, nil, 0)
  11.     buf = "\0" * (len*2)
  12.     m2w.call(CP_UTF8, 0, self, -1, buf, buf.size/2)
  13.    
  14.     len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil)
  15.     ret = "\0" * len
  16.     w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil)
  17.    
  18.     return ret
  19.   end
  20.   
  21.   def s2u
  22.     m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  23.     w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
  24.   
  25.     len = m2w.call(CP_ACP, 0, self, -1, nil, 0);
  26.     buf = "\0" * (len*2)
  27.     m2w.call(CP_ACP, 0, self, -1, buf, buf.size/2);
  28.   
  29.     len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil);
  30.     ret = "\0" * len
  31.     w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil);
  32.      
  33.     return ret
  34.   end

  35.   
  36.   
  37.   def s2u!
  38.     self[0,length] = s2u
  39.   end  
  40.   
  41.   def u2s!
  42.     self[0, length] = u2s
  43.   end
  44.   
  45. end

  46. module Debug
  47.   
  48.   REPLACE       = true
  49.   
  50.   AllocConsole  = Win32API.new("kernel32", "AllocConsole", "v", "i")
  51.   GetStdHandle  = Win32API.new("kernel32", "GetStdHandle", "l", "l")
  52.   ReadConsole   = Win32API.new("kernel32", "ReadConsole","lplpp", "i")
  53.   WriteConsole  = Win32API.new("kernel32", "WriteConsole", "lplpp", "i")
  54.   FreeConsole   = Win32API.new("kernel32", "FreeConsole", "v", "i")

  55.   module_function
  56.   
  57.   def init
  58.     AllocConsole.call
  59.     @h = GetStdHandle.call -11
  60.   end

  61.   def free
  62.     FreeConsole.call
  63.     @h = nil
  64.   end

  65.   def validcheck
  66.     raise "必须先调用Debug.init进行初始化!" if @h.nil?
  67.   end
  68.   
  69.   def print(*args)
  70.     validcheck; str = ""
  71.     args.each{|obj| str += obj.is_a?(String) ? obj : obj.inspect}; str.u2s!
  72.     WriteConsole.call @h, str, str.length, nil, nil
  73.   end
  74.   
  75.   def println
  76.     validcheck; WriteConsole.call @h, "\n", 1, nil, nil
  77.   end
  78.   
  79.   def p(*args)
  80.     validcheck
  81.     str = ""; args.each{|obj| str += obj.inspect + "\n"}; str.u2s!
  82.     WriteConsole.call @h, str, str.length, nil, nil
  83.   end
  84.   
  85.   def gets
  86.     validcheck
  87.     str = "/0"*256
  88.     len = [0].pack("L")
  89.     begin
  90.       ReadConsole.call GetStdHandle.call(-10),str,str.length,len,nil
  91.       nil
  92.     rescue Hangup
  93.       # 10s 的容错
  94.       p $!, str.delete("\0"), len.unpack("L")[0]
  95.     end
  96.     Debug.println

  97.     return str.s2u!.delete("\r\n").delete("/0").delete("\000")
  98.   end  
  99.   
  100.   class << self
  101.    
  102.     private :validcheck
  103.    
  104.     alias puts  print

  105.   end
  106.   
  107.   if REPLACE
  108.     alias origin_print print
  109.     alias origin_p p
  110.     self.init if @h.nil?
  111.   end
  112.   
  113. end
  114. module Kernel
  115.   
  116.     def print(*args)
  117.       Debug.print *args
  118.     end
  119.    
  120.     def p(*args)
  121.       Debug.p *args
  122.     end
  123.    
  124.     def gets
  125.       Debug.gets
  126.     end  
  127.    
  128.     alias ori_exit exit
  129.     def exit(*args)
  130.       Debug.free
  131.       ori_exit(*args)
  132.     end  
  133. end
复制代码

作者: Chen。    时间: 2013-1-29 13:56
说清楚点




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1