This code needs to be compiled in a dll in order to work:
Code: Select all
; Compile this code as shared dll = "Draw.DLL"
ProcedureDLL AttachProcess(instance)
Global drawmessage = RegisterWindowMessage_("CustomDraw")
Global window = FindWindow_(#Null, "CustomDrawTest")
Global hook = GetWindowLong_(window, #GWL_USERDATA)
EndProcedure
ProcedureDLL CallWndProcRet(nCode, wParam, lParam)
*msg.CWPRETSTRUCT = lparam
Select *msg\message
Case #WM_PAINT,#WM_NCPAINT
PostMessage_(window, drawmessage, 0, 0)
EndSelect
ProcedureReturn CallNextHookEx_(hook, nCode, wParam, lParam)
EndProcedureCode: Select all
; When you've made "Draw.dll", make it available and run this code:
Global drawmessage = RegisterWindowMessage_("CustomDraw")
Declare Draw(hwnd)
OpenWindow(0,0,0,1,1,"CustomDrawTest",#PB_Window_BorderLess|#PB_Window_Invisible)
RunProgram("calc.exe")
Delay(1000)
hwnd = FindWindow_(0,"Calculator")
draw(hwnd)
hDLL = OpenLibrary(0, "draw.dll")
ThreadID = GetWindowThreadProcessId_(hwnd, @ProcessID)
proc = GetFunction(0, "CallWndProcRet")
hook = SetWindowsHookEx_(#WH_CALLWNDPROCRET, proc, hDll, ThreadID )
SetWindowLong_(WindowID(0),#GWL_USERDATA, hook)
Repeat
msg = WaitWindowEvent(1)
If msg = drawmessage
Draw(hwnd)
EndIf
Until IsWindow_(hwnd) = #False
CloseWindow(0)
Procedure Draw(hwnd)
GetClientRect_(hwnd, @cr.RECT)
w = cr\right-cr\left
tmp = CreateImage(#PB_Any,w,1,#PB_Image_DisplayFormat)
hdc = GetDC_(hwnd)
dcimg = StartDrawing(ImageOutput(tmp))
;here the 2ddrawing commands..
Line(0,0,w,0,#Red)
BitBlt_(hdc, 0,0,ImageWidth(tmp),ImageHeight(tmp),dcimg,0,0,#SRCCOPY)
StopDrawing()
ReleaseDC_(hwnd, hdc)
FreeImage(tmp)
EndProcedure

