A.R.
2006-Sep-29 03:25 UTC
[fxruby-users] Dirty (but working) solution for handle win32 message with Fox and Swin
After few searchs, i''ve find some solution to my problem. I''ll work on it next week for understand the loop procedure under both fox and swin. So this is the code for an FXRuby auto-copy application (keep on top-most windows) with handling win32 event with Swin library (there no much documentation about it :( ) If you have over ideas for doing same thing less dirty, drop me a line ! require ''fox16'' include Fox require ''Win32API'' require ''swin'' HWND_TOPMOST = -1 HWND_NOTOPMOST = -2 SWP_NOSIZE = 1 SWP_NOMOVE = 2 SWP_SHOWWINDOW = 64 CF_TEXT = 1 WM_DESTROY = 0x00000002 WM_QUIT = 0x00000018 WM_CHANGECBCHAIN = 781 WM_DRAWCLIPBOARD = 776 class ClipW < FXMainWindow attr_accessor :txt def initialize(app) super(app,"test clip",nil,nil,DECOR_ALL|LAYOUT_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y,10,30,200,200) @txt = FXText.new(self,nil,0,LAYOUT_FILL_X|LAYOUT_FILL_Y) end def create super show(PLACEMENT_SCREEN) end def setOnTop setWindowPos = Win32API.new(''user32'', ''SetWindowPos'', ["P", "P","I", "I", "I", "I", "I"], "I") setWindowPos.call(xid, HWND_TOPMOST, 0, 0, 0, 0,SWP_NOSIZE|SWP_NOMOVE) end end #win32 API Bee = Win32API.new(''kernel32'', ''Beep'', ''II'', ''I'') SetClipboardViewer = Win32API.new(''user32'',''SetClipboardViewer'',''L'',''L'') ChangeClipboardChain = Win32API.new(''user32'',''ChangeClipboardChain'',''LL'',''I'') SendMessage = Win32API.new("user32", "SendMessage", [''L''] * 4, ''L'') #Fox application = FXApp.new("Clip","copie") Clip = ClipW.new(application) application.create #SWin S = SWin::LWFactory.new(SWin::Application.hInstance) mw = S.newwindow(nil) mw.create @@hwndNextViewer = SetClipboardViewer.call(mw.hWnd) mw.addEvent WM_DRAWCLIPBOARD mw.addEvent WM_CHANGECBCHAIN mw.addEvent WM_DESTROY def mw.msghandler(msg) #msg has attrs of hWnd,msg,wParam,lParam Bee.call(3000,50) #add this for debugging facility :) case msg.msg when WM_CHANGECBCHAIN @@hwndNextViewer = msg.lParam if msg.wParam == @@hwndNextViewer SendMessage.call(@@hwndNextViewer, msg.msg, msg.wParam, msg.lParam) when WM_DESTROY ChangeClipboardChain.call(msg.hWnd,@@hwndNextViewer) when WM_DRAWCLIPBOARD Bee.call(4000,50) SendMessage.call(@@hwndNextViewer, msg.msg, msg.wParam, msg.lParam) if @@hwndNextViewer!=0 Clip.txt.text = Clip.getDNDData(FROM_CLIPBOARD, FXWindow.stringType) end end Clip.show(PLACEMENT_SCREEN) Clip.setOnTop #mw.show application.run SWin::Application.messageloop