New graphics control (part 2)

Started by Marc van Cauwenberghe, October 05, 2012, 10:48:03 AM

Previous topic - Next topic

Marc van Cauwenberghe

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

José Roca

You get the device context of the control calling hDc = GraphCtx_GetDc(<handle of the control>).


Marc van Cauwenberghe

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

José Roca

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)



Marc van Cauwenberghe

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


José Roca

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

Marc van Cauwenberghe

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

José Roca

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.

Marc van Cauwenberghe

Good morning Jose,

Con gracias repetidas.

Marc