赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 2 |
经验 | 0 |
最后登录 | 2017-2-1 |
在线时间 | 16 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 1788
- 在线时间
- 16 小时
- 注册时间
- 2014-12-7
- 帖子
- 4
|
多谢楼主,看了你的程序真的让我大开眼见,没想到winapi还可以这样用,让程序减少了不少。其实今天中午我的程序也写完了,但是有300行之多,主要是定义了半天cstruct。刚才看了你的程序,下载后在我这里运行不了,所以就想到用你的程序来简化我的程序。本来想另外开帖,又觉得是在这个帖里面长大的所以就放在这里了。
示例工程如下
RGSS纯ruby启动器.zip
(1.13 MB, 下载次数: 120)
程序代码如下- # -*- coding:utf-8 -*-
- =begin
- 参考资料
- https://rpg.blue/thread-377723-1-1.html 想法来源(后来还用楼主的脚本重新改写)
- http://skandhas.iteye.com/blog/809806 解决了创建windows窗口的问题
- 有些windows的常量没有定义需要查看MSDN
- http://rpg.blue/thread-282803-1-1.html 解决了最后读不了脚本文件的问题
- 解决不了的问题
- 1.RTP无法加载(也不知道加载是什么原理)
- 2.想知道RGSS.dll是如何实现的
- 3.RGSSGameMain 究竟干了什么,为什么之前的RGSSEval不能使用Sprite
- =end
- require 'Win32API'
- require 'pathname'
- require 'iniparse' #读取ini文件
- RGSSversion=3 # 1 or 3
- Gameini="Game_debug.ini" #"Game.ini"
- WndClassName = "Pure Ruby Window For RGSS"
- @title=WndClassName
- #--------
- szAppPath=Pathname.new(File.dirname(__FILE__)).realpath
- #puts Dir.getwd 获得当前的执行目录 ***
- Dir.chdir(szAppPath) #改变当前目录
- #-------------
- #隐藏掉控制台
- #Win32API.new('user32', 'ShowWindow', 'li', 'i').call(
- # Win32API.new('kernel32', 'GetConsoleWindow', 'v', 'l').call, 0)
- #-------------
- @hInstance = Win32API.new('kernel32', 'GetModuleHandle', 'l', 'l').call(0)
- @wndclass = [
- 43, # style
- Win32API.new('kernel32', 'GetProcAddress', 'lp', 'l').call(
- Win32API.new('kernel32', 'LoadLibrary', 'p', 'l').call('User32.dll'),
- 'DefWindowProcW'), # wndproc
- 0, # class extra
- 0, # wnd extra
- @hInstance,
- Win32API.new('user32', 'LoadIcon', 'll', 'l').call(0, 32512), # icon
- Win32API.new('user32', 'LoadCursor', 'll', 'l').call(0, 32512), # cursor
- Win32API.new('gdi32', 'GetStockObject', 'i', 'l').call(4), # brush
- 0, # menu name
- WndClassName # class name
- ].pack('ILiiLLLLLp')
- atom = Win32API.new('user32', 'RegisterClass', 'p', 'l').call(@wndclass)
- atom &=0x0000ffff
- return if atom==0
- #在第一个实现的脚本中atom本来是要用在WndClassName位置的
- x=200; y=100; width=640 ; height=480
- @hWnd = Win32API.new('user32','CreateWindowExA','lpplllllllll','l').call(
- 0x100, WndClassName, @title, 0x90CA0000, x, y, width, height, 0, 0, @hInstance, 0)
- #-------------
- hd_gameini=IniParse.parse( File.read "#{Gameini}" )
- szLibrary=hd_gameini["Game"]["Library"]
- szTitle =hd_gameini["Game"]["Title"]
- szScripts=hd_gameini["Game"]["Scripts"]
- szRtpName=hd_gameini["Game"]["RTP"]
- @title=szTitle
- #通过核心库加载程序
- @hRgssCore = Win32API.new('kernel32', 'LoadLibrary', 'p', 'l').call(szLibrary)
- pRGSSEval=Win32API.new(szLibrary, "RGSSEval", ['P'], 'I')
- pRGSSSetupRTP=Win32API.new(szLibrary, "RGSSSetupRTP", ['P','P','I'], 'B')
- pRGSSInitialize=if RGSSversion==3
- Win32API.new(szLibrary, "RGSSInitialize3", 'L', 'L')
- elsif RGSSversion==1
- Win32API.new(szLibrary, "RGSSInitialize", 'L', 'L')
- end
- pRGSSGameMain=Win32API.new(szLibrary, "RGSSGameMain", ['L','P','P'], 'V')
- #puts Win32API::COLOR_WINDOWFRAME
- def stop
- Win32API.new('kernel32', 'FreeLibrary', 'l', 'i').call(@hRGSSCore) if @hRGSSCore and @hRGSSCore != 0
- Win32API.new('user32', 'DestroyWindow', 'l', 'i').call(@hWnd) if @hWnd and @hWnd != 0
- Win32API.new('user32', 'UnregisterClass', 'pl', 'i').call(WndClassName, @hInstance)
- exit
- end
- #RTP就是不行
- szRtpName= [0].pack('C') * 1024
- p pRGSSSetupRTP.Call("#{Gameini}", szRtpName, 1024)
- pRGSSInitialize.Call(@hRgssCore) # 没有这个就不行,说明还是有关系的
- szScripts="Scripts.rvdata2"
- class String
- MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
- WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
- def to_uni
- len = MultiByteToWideChar.call 65001, 0, self, -1, nil, 0
- buf = "\0" * (len * 2 + 2)
- MultiByteToWideChar.call 65001, 0, self, -1, buf, buf.size / 2
-
- buf
- end
-
- def from_uni
- len = WideCharToMultiByte.call 65001, 0, (self.respond_to?(:force_encoding) ? self.force_encoding("ASCII-8BIT") : self) + "\000\000", -1, nil, 0, nil, nil
- ret = "\0" * len
- WideCharToMultiByte.call 65001, 0, self, -1, ret, ret.size, nil, nil
-
- self.respond_to?(:force_encoding) ?
- ret.force_encoding("ASCII-8BIT").delete("\000") :
- ret.delete("\000")
- end
- end
- pRGSSGameMain.call(@hWnd,szScripts.to_uni,"") #必须这样才行
- stop
复制代码 |
|