(同步个人博客http://sxysxy.org/blogs/72 到csdn)
到这里,没有什么技术含量的东西差不多就说完了,剩下的就是更没有技术含量的体力活了。
修改XYGui_ext.c里面的窗口过程,让窗口能够响应更多的交互事件:
比如支持拖拽文件到窗口:
case WM_DROPFILES: // Drop files into the window
// wParam is HDrop (Win32)
__tmpcptr1__ = (char *)malloc(sizeof(char) * 256);
__tmp2__ = DragQueryFile((HDROP)wParam, 0xffffffff, NULL, 0);
__arg1__ = rb_ary_new();
for(__tmp1__ = 0; __tmp1__ < __tmp2__; __tmp1__++)
{
DragQueryFile((HDROP)wParam, __tmp1__, __tmpcptr1__, 256);
__arg2__ = rb_str_new2(__tmpcptr1__);
rb_funcall(__arg1__, rb_intern("push"), 1, __arg2__);
}
free(__tmpcptr1__);
DragFinish((HDROP)wParam);
__arg2__ = rb_hash_new();
rb_hash_aset(__arg2__, ID2SYM(rb_intern("files")), __arg1__);
XYWidgetCall("ON_DROPFILES", self, __arg2__);
break;
相应菜单,按钮点击等
__tmp1__ = LOWORD(wParam);
if(lParam == 0) // Command caused by menu
{
rb_funcall(self, rb_intern("menuCall"), 1, INT2NUM(__tmp1__));
}else
{ // Command caused by a child control
switch(HIWORD(wParam))
{
case EN_UPDATE:
rb_funcall(self, rb_intern("childCall"), 4, INT2FIX(__tmp1__),
ID2SYM(rb_intern("ON_CHANGED")), self, Qnil);
break;
case EN_CHANGE:
rb_funcall(self, rb_intern("childCall"), 4, INT2FIX(__tmp1__),
ID2SYM(rb_intern("ON_CHANGING")), self, Qnil);
break;
default:
rb_funcall(self, rb_intern("childCall"), 4, INT2FIX(__tmp1__),
ID2SYM(rb_intern("ON_COMMAND")), self, Qnil);
break;
}
}
break;
等
其实你应该发现了,当你封装好XYApp,XYWidget,XYWindow之后,想要其他种类的控件,比如按钮,文本框,大可以复制/粘贴,改一下类名,重写下create方法,就好了…完全就是体力活了,多查查msdn,这些都出来了…
对opengl的支持:
需要api SetPixelFormat一下,使得控件支持opengl绘图,然后用system32下opengl32.dll配置好绘图上下文环境即可,具体见xy_gllabel.rb
def enableGL
#pfd
@dc = WinAPI.call("user32", "GetDC", @handle)
pfd = [40, 1, #size = 40, version = 1
37, #support opengl, double buffers, and draw to window
0, #pixel type :RGBA
24, #color bits
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, #0 * 18 Do not care...
0, #layerMask
0, 0].pack("ssLccccccccccccccccccccLLL")
format = WinAPI.call("gdi32", "ChoosePixelFormat", @dc, pfd)
WinAPI.call("gdi32", "SetPixelFormat", @dc, format, pfd)
@glrc = WinAPI.call("opengl32", "wglCreateContext", @dc)
WinAPI.call("opengl32", "wglMakeCurrent", @dc, @glrc)
WinAPI.call("user32", "ReleaseDC", @handle, @dc)
end
基本绘图以及图片功能的支持
封装gdi/gdi+即可,不用多说…
最后,完结撒花
这一系列以XYGui为例的,讲解开发一个简单的gui库的文章就结束了。我的OI生涯也结束了呢QnQ…