Code:
--Global User32Library = Library.Load("user32.dll"); Gdi32Library = Library.Load("Gdi32.dll"); BOOL = INT HDC = INT RECT = MemoryEx.DefineStruct{ LONG "left"; LONG "top"; LONG "right"; LONG "bottom"; }; PAINTSTRUCT = MemoryEx.DefineStruct{ HDC "hdc"; BOOL "fErase"; RECT "rcPaint"; BOOL "fRestore"; BOOL "fIncUpdate"; BYTE "rgbReserved"; } HostWindow = {} HostWindow.CreateHost = function(x,y,w,h) local WS_EX_CLIENTEDGE = 0x00000200; local hWnd = Application.GetWndHandle(); local WS_CHILD = 0x40000000; local WS_VISIBLE = 0x10000000; local nstyle = WS_CHILD + WS_VISIBLE; local bhdl = User32Library.CreateWindowExA(WS_EX_CLIENTEDGE,32770,"",nstyle,x,y,w,h,hWnd,0,0,0) if bhdl and (type(bhdl) ~= "number") then return false, "Can't create container" end HostWindow.HostHandle = bhdl local s = Subclass.Create(HostWindow.HostHandle, function(hWnd, uMsg, wParam, lParam) if(uMsg == 0x0014)then--WM_ERASEBKGND local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(PAINTSTRUCT) + 100); if not lpBuff then return 0 end local hStruct = MemoryEx.AssignStruct(lpBuff + 50, PAINTSTRUCT); if not hStruct then return 0 end local x = User32Library.BeginPaint(hWnd,hStruct:GetPointer()) if (x ~= nil and x > 0) then local x = User32Library.FillRect(wParam,hStruct.rcPaint:GetPointer(),HostWindow.BrushHandle) User32Library.EndPaint(hWnd,hStruct:GetPointer()) hStruct:Close(); MemoryEx.Free(lpBuff); return 0 else hStruct:Close(); MemoryEx.Free(lpBuff); return 0 end end return Subclass.OldWinProc(hWnd, uMsg, wParam, lParam); end) local x,y = HostWindow.CreateBrush() if not x then return false, "Can't create brush" else HostWindow.BrushHandle = y end HostWindow.BringToTop(HostWindow.HostHandle) return true, "OK" end; HostWindow.BringToTop = function(SWnd) if tonumber(User32Library.BringWindowToTop(SWnd)) == 0 then return false, "Can't bring to top" else return true, "OK" end end; HostWindow.CreateBrush = function() local hBrush = Gdi32Library.CreateSolidBrush(16777215) if hBrush and (type(hBrush) ~= "number") then return false, "Can't create brush" else return true, hBrush end end; --Button / On Show HostWindow.CreateHost(10,10,400,300) --Maximize then window shows window mirror, minimize then restore and background works
Comment