PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Marc van Cauwenberghe on October 05, 2012, 10:48:03 AM

Title: New graphics control (part 2)
Post by: Marc van Cauwenberghe on October 05, 2012, 10:48:03 AM
Hi,
I would like to understand graphics and the graphics control in FF. How must I see the control. Is it a normal DC created like:
hdcScreen = CreateDC("DISPLAY", BYVAL %NULL, BYVAL %NULL, BYVAL %NULL)
I would like to get started exploring Jose's many examples. I can run them in PB10 but have no luck running them in FF with the graphics control.
Can anyone make me a small skeleton so that I can run Jose's GDI and GID+ examples.

Many thanks for any help.

Marc
Title: Re: New graphics control (part 2)
Post by: José Roca on October 05, 2012, 10:55:51 AM
You get the device context of the control calling hDc = GraphCtx_GetDc(<handle of the control>).
Title: Re: New graphics control (part 2)
Post by: José Roca on October 05, 2012, 11:07:10 AM
Jean-Pierre dis post an example:

http://www.planetsquires.com/protect/forum/index.php?topic=3184.0
Title: Re: New graphics control (part 2)
Post by: Marc van Cauwenberghe on October 05, 2012, 11:23:23 AM
Hi Jose,
I have looked at that code.

I have added a button and the following code:
'--------------------------------------------------------------------------------
Function FORM1_COMMAND1_BN_CLICKED ( _
                                   ControlIndex     As Long,  _  ' index in Control Array
                                   hWndForm         As Dword, _  ' handle of Form
                                   hWndControl      As Dword, _  ' handle of Control
                                   idButtonControl  As Long   _  ' identifier of button
                                   ) As Long
   GDIP_DrawImage(GraphCtx_GetDc(HWND_FORM1_GRAPHICCONTROL1))
End Function
'--------------------------------------------------------------------------------
Sub GDIP_DrawImage (ByVal hdc As Dword)

   Local hStatus As Long
   Local pGraphics As Dword
   Local pImage As Dword
   Local strFileName As String

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create the Image object
   strFileName = UCode$("climber.jpg")
   hStatus = GdipLoadImageFromFile(StrPtr(strFileName), pImage)

   ' // Draw the image
   hStatus = GdipDrawImage(pGraphics, pImage, 10, 10)

   ' // Cleanup
   If pImage Then GdipDisposeImage(pImage)
   If pGraphics Then GdipDeleteGraphics(pGraphics)

End Sub


When compiling I get 'error 421: STRING OPERAND EXPECTED' and the cursor is pointing just befor the StrPtr command.

Marc
Title: Re: New graphics control (part 2)
Post by: José Roca on October 05, 2012, 12:17:18 PM
You're using code from examples for PB 9. PB 10 and my latest headers are unicode aware.

Use:


Local wszFileName As WSTRINGZ * 260
wszFileName = "climber.jpg"
hStatus = GdipLoadImageFromFile(wszFilename), pImage)


Title: Re: New graphics control (part 2)
Post by: Marc van Cauwenberghe on October 05, 2012, 01:07:09 PM
Aha, that worked. Thank you.
I did need to redraw the graphic control.

Up to the next function.
In an other sample that worked I used
AfxDrawBitmap GraphCtx_GetDc(HWND_FORM1_GRAPHICCONTROL1), 10, 10, hBitmap
Is there a difference with the following?:
GdipDrawImage(pGraphics, pImage, 10, 10)

Marc

Title: Re: New graphics control (part 2)
Post by: José Roca on October 05, 2012, 01:27:26 PM
A world of difference. AfxDrawBitmap is to draw a GDI bitmap. GdipDrawImage is to draw a GDI+ image.

Your problem is not how to use my graphic control with FF, but to learn GDI and GDI+ programming first.

GDi examples: http://www.jose.it-berater.org/smfforum/index.php?board=416.0
GDI+ Flat API examples: http://www.powerbasic.com/support/pbforums/forumdisplay.php?f=53&order=desc&page=2
Title: Re: New graphics control (part 2)
Post by: Marc van Cauwenberghe on October 05, 2012, 01:52:08 PM
That is so true Jose, I know.
But I would like to know what the relation of the graphics control is to terms
as 'windows DC', 'memory DC', CreateCompaticleDC, BitBlt, etc... I read  a
lot of articles related to those terms.

Marc
Title: Re: New graphics control (part 2)
Post by: José Roca on October 05, 2012, 07:26:48 PM
What the graphic control does is to simplify these tasks for you. It uses a memory device context for double buffering (to avoid flicker) and features persistence. Therefore, you don't have to worry about redrawing the contents in WM_PAINT or WM_SIZE. You get an handle to is memory device context with GraphCtx_GetDc when you need it and you just draw in it.
Title: Re: New graphics control (part 2)
Post by: Marc van Cauwenberghe on October 06, 2012, 04:34:47 AM
Good morning Jose,

Con gracias repetidas.

Marc