I am trying to port over some code I wrote for the DDT Graphic Control for use in FF3 and it's Graphic Control, sadly I am getting lost on even the basics.
I put the control on the form, enabled GDIPlusAware and created a 250ms timer to do the following that I pulled out of other examples...
Function DLGLOGON_TMCTIMER1_WM_TIMER ( _
hWndForm As Dword, _ ' handle of Form
wTimerID As Dword _ ' the timer identifier
) As Long
Dim hStatus As Local Long
Dim pGraphics As Local Dword
Dim pPen As Local Dword
hStatus = GdipCreateFromHDC( GraphCtx_GetDc( HWND_DLGLOGON_GRPHCONTROL1 ), pGraphics )
hStatus = GdipCreatePen1( GDIP_ARGB( 255, 255, 0, 0 ), 1, %UnitPixel, pPen )
GdipDrawLineI pGraphics, pPen, 0, 0, 200, 100
If pPen Then GdipDeletePen( pPen )
If pGraphics Then GdipDeleteGraphics( pGraphics )
End Function
I expect it to draw the diagonal line like it does in all other examples but it does nothing. I've even added ZTRACE code... I get an hDC, hStatus is 0 on both, and I am getting pPen and pGraphics values, but no line. I know I am missing SOMETHING plainly obvious but can't see what.
P.S. I know it seems silly to put THAT code in a 1/4sec loop but I am just trying to get it to draw a line at the moment. It will be updated to perform more complex line drawings that need to be updated on frequency once I get the basics of working with the control in place.
Nevermind, 3 hours of on and off testing and I find the answer 30 seconds after I post... figures.
It seems I needed a FF_Control_Redraw( HWND_DLGLOGON_GRPHCONTROL1 )
So the end result of what I was looking to do is this...
%JumpAmount = 16
Sub AnimateBox(ByVal hCtrl As Dword)
Dim hDC As Static Dword
Dim lngWidth As Static Long
Dim lngHeight As Static Long
Dim lngLineLen() As Static Long
Dim lngLineColor() As Static Long
Dim lngXPos As Local Long
Dim lngYPos As Local Long
Dim lngTemp As Local Long
If lngWidth=0 Then
Randomize timer
FF_Control_GetSize( hCtrl, lngWidth, lngHeight)
Dim lngLineLen(lngWidth-1)
Dim lngLineColor(lngWidth-1)
hDC = GraphCtx_GetDc( hCtrl )
For lngTemp = 0 To lngHeight
GoSub DrawIt
Next lngTemp
GoTo UpdateControl
End If
GoSub DrawIt
GoTo UpdateControl
DrawIt:
For lngYPos = %JumpAmount-1 To 0 Step -1
BitBlt hDC,0,1,lngWidth-1, lngHeight-1, hDC, 0, 0, %srccopy
For lngXPos = 0 To lngWidth -1 Step 2
SetPixel hDC, lngXPos, 0, lngLineColor(lngXPos)
SetPixel hDC, lngXPos+1, 0, lngLineColor(lngXPos)
If lngLineLen(lngXPos)=0 Then
lngLineLen(lngXPos)=Rnd(10, 20)
lngLineColor(lngXPos) = Rgb(0, Rnd(0,255),0)
Else
Decr lngLineLen(lngXPos)
End If
Next lngXPos
Next lngYPos
Return
UpdateControl:
FF_Control_Redraw( hCtrl )
End Sub
Throw this into a module then call AnimateBox(hYourGraphicControl) from a WM_TIMER event every so often. Adds a little fun animation to a dull static form.
instead of WM_TIMER use TimeSetEvent much smoother.
Cool! I don't use the graphic control so it was fun to try your example in a test project of mine.
Alternate cool effect
%JumpAmount = 1
Function AniCallback( ByVal uID As Long, ByVal uMsg As Long, _
ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long) As Long
AnimateBox {Handle to your graphic control goes here}
End Function
Sub AnimateBox(ByVal hCtrl As Dword)
Dim hDC As Static Dword
Dim lngWidth As Static Long
Dim lngHeight As Static Long
Dim lngLineLen() As Static Long
Dim lngLineColor() As Static Long
Dim lngXPos As Local Long
Dim lngYPos As Local Long
Dim lngTemp As Local Long
Dim bytRed As Local Byte
If lngWidth=0 Then
Randomize timer
FF_Control_GetSize( hCtrl, lngWidth, lngHeight)
Dim lngLineLen(lngWidth-1)
Dim lngLineColor(lngWidth-1)
hDC = GraphCtx_GetDc( hCtrl )
For lngTemp = 0 To lngHeight
GoSub DrawIt
Next lngTemp
GoTo UpdateControl
End If
GoSub DrawIt
GoTo UpdateControl
DrawIt:
For lngYPos = %JumpAmount-1 To 0 Step -1
BitBlt hDC,0,1,lngWidth-1, lngHeight-1, hDC, 0, 0, %srccopy
For lngXPos = 0 To lngWidth -1 Step 2
SetPixel hDC, lngXPos, 0, Rgb(lngLineColor(lngXPos), lngLineColor(lngXPos)-&H20, lngLineColor(lngXPos)-&H20)
SetPixel hDC, lngXPos+1, 0, Rgb(lngLineColor(lngXPos), lngLineColor(lngXPos)-&H20, lngLineColor(lngXPos)-&H20)
If lngLineColor(lngXPos)=0 Then
bytRed = Rnd(&H98, &HF8)
lngLineColor(lngXPos) = bytRed
lngLineLen(lngXPos) = (Rnd(0,1)*2)-1
Else
lngLineColor(lngXPos) += lngLineLen(lngXPos)
If lngLineColor(lngXPos)=&HF9 Or lngLineColor(lngXPos)=&H97 Then
lngLineLen(lngXPos) = -lngLineLen(lngXPos)
lngLineColor(lngXPos) += (lngLineLen(lngXPos) * 2)
End If
End If
Next lngXPos
Next lngYPos
Return
UpdateControl:
FF_Control_Redraw( hCtrl )
End Sub
and in your WM_CREATE dump this...
TimeSetEvent ByVal 20, ByVal 0, ByVal CodePtr(AniCallback), ByVal 0&, ByVal %TIME_PERIODIC