>>>Dear All,
>>>
>>>Is there any way to draw directly to a form surface
>>>with form scrollbars enabled ?
>>>
>>>TIA
>>>Sergio
>>
>>
>>Hi Sergio,
>>
>>That's totally possible, why not ?
>>Are you trying to draw in a topLevel form ?
>>If yes, there's a small trick to obtain the surface HWND:
>>
>>
LOCAL lnHWnd
>>IF Thisform.ShowWindow = 2
>> lnHWnd=SYS(2327, SYS(2325, SYS(2326,Thisform.HWnd)))
>>ELSE
>> lnHWnd = Thisform.HWnd
>>ENDIF
>>
>>Is this what you are looking for ?
>
>
>Hi Cesar,
>
>I am trying to draw on ordinary modeless form.
>ShowWindow is by default 0 (In Screen)
>
>Without scrollbars everything shows just fine
>as soon I enable toolbars - nothing shows :(
>
>Maybe never version of GdiPlusX ?
>This one I am working with I downloaded about month ago
>(Forgot number)
>
>TIA
Hi Sregio,
This has nothing to do with the version of Gdi+X
I've tried here, and you are correct... This is totally strange...
But I made it work. The solution is really tricky, but seems to be reliable:
My conclusion is that when the form has a ScrollBar, a new window is added to it, and this makes a big confusion. The original solution I gave you would not work because it was getting the HWND from the ScrollBars !
For this situation, VFP adds the ScrollBars after the INIT() event is fired, so you can't put the suggestion I will give to you on INIT().
Follow These Steps:
1 - In INIT()
DO LOCFILE("System.prg")
Thisform.AddProperty("RealHWND", 0)
2 - In ACTIVATE() of your form:
IF Thisform.RealHWND <> 0
DODEFAULT()
RETURN
ENDIF
DECLARE INTEGER GetWindowRect IN user32 INTEGER hwnd, STRING @lpRect
DECLARE INTEGER WindowFromPoint IN WIN32API INTEGER x, INTEGER y
#DEFINE EMPTY_RECT REPLICATE(CHR(0),16)
LOCAL lcRect, lnLeft, lnTop
lcRect = EMPTY_RECT
= GetWindowRect(Thisform.hWnd, @lcRect)
lnLeft = CTOBIN(SUBSTR(lcRect, 1,4),"4RS")
lnTop = CTOBIN(SUBSTR(lcRect, 5,4),"4RS")
LOCAL lnTitleHeight, lnLeftBorder, lnTopBorder, x1, y1
lnTitleHeight = SYSMETRIC(9)
lnLeftBorder = SYSMETRIC(3)
lnTopBorder = SYSMETRIC(4)
x1 = lnLeftBorder
y1 = lnTitleHeight + lnTopBorder
Thisform.RealHWND = WindowFromPoint(lnLeft + x1, lnTop + y1)
DODEFAULT()
RETURN
3 - Create any commandButton, and add the following code:
WITH _Screen.System.Drawing
loGfx = .Graphics.FromHwnd(Thisform.RealHWND)
loGfx.FillRectangle(.Brushes.Red, 0,0,100,100)
ENDWITH
Hope this helps you to get started.
I'm sure I'll find a better way to do that, but for the moment, this was the simplest solution that came to my mind.
Hope this helps
Cesar