Support Forums > WinFBX - Windows Framework for FreeBASIC

CImageCtx Class

(1/3) > >>

Bumblebee:
How do I create an image control in an existing form?
I need an image control whose contents I can change programmatically.
The Picturebox control does not allow this, as far as I can tell.
My intention is to include the CImageCtx class as part of a visual designer project.

Paul Squires:
Use the PictureBox and change the Image property. Add the images to your project via the "Image Library" and ensure that the picture format is RCDATA (even for icons). The images will all have names that are prefixed by "IMAGE_".

For example, I added an icon called "WinFBE" (basically rhe blue star icon that you see as WinFBE's exe icon). The name that is assigned to that image is then:  IMAGE_WINFBE 

In a Button Click event I change the PictureBox image to use this new icon as follows:

frmMain.Picture1.Image = "IMAGE_WINFBE"

Bumblebee:
In this program, the image will be loaded from a file, when an associated item is selected in a list box. Can I do this with the picture box control?
For example:
a = "C:\My files\test.jpg"
pImageCtx.LoadImageFromFile a 'displays the image

With the picture box, I can select among images added via the Image Manager, using the names as you describe.
How do I add an image from a file at runtime, so the picture box can display it?

Bumblebee:
In the Ctx image demo, a Cwindow class named pWindow was created.
So if Form1 is a CWindow, can this control be added to a form at runtime?


--- Code: ---Application.Run(Form1)

#INCLUDE ONCE "Afx/CImageCtx.inc"

'Add an image control
'DIM pImageCtx AS CImageCtx = CImageCtx(@pWindow, IDC_IMAGECTX, "", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
DIM pImageCtx AS CImageCtx = CImageCtx(@Form1, IDC_IMAGECTX, "", 0, 0, Form1.Width, Form1.Height)

--- End code ---

C:\Decoy\Software\fb\WinFBE_VD_MAIN.bas(61) warning 3(1): Passing different pointer types, at parameter 1 (pWindow) of AFX.CIMAGECTX.constructor(as AFX.CWINDOW ptr, as long, as wstring, as long, as long, as long, as long, as ulong, as ulong, as long)
C:\Decoy\Software\fb\WinFBE_VD_MAIN.bas(61) error 24: Invalid data types, at parameter 1 (pWindow) of AFX.CIMAGECTX.constructor(as AFX.CWINDOW ptr, as long, as wstring, as long, as long, as long, as long, as ulong, as ulong, as long)

Original constructor as per the help file:
CONSTRUCTOR CImageCtx (BYVAL pWindow AS CWindow PTR, BYVAL cID AS INTEGER, _
   BYREF wszTitle AS CONST WSTRING = "", BYVAL x AS LONG = 0, BYVAL y AS LONG = 0, _
   BYVAL nWidth AS LONG = 0, BYVAL nHeight AS LONG = 0, BYVAL dwStyle AS DWORD = 0, _
   BYVAL dwExStyle AS DWORD = 0, BYVAL lpParam AS LONG_PTR = 0)

Paul Squires:
In theory, you would do like the code below to add the image control at runtime. (I put "ImageFromFile" on my to do list for an additional method for the PictureBox):

The problem is that when I run the code below I am not getting the image to display. I will troubleshoot it tomorrow as I am on very limited time this evening.


--- Code: ---
#INCLUDE ONCE "Afx/CImageCtx.inc"

dim shared pImageCtx AS CImageCtx PTR

const IDC_IMAGECTX = 200


''
''
Function frmMain_Button1_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT

   ' // Load an image from disk
   if pImageCtx then
      pImageCtx->LoadImageFromFile(".\WinFBE.ico")
   end if

   Function = 0
End Function

''
''
Function frmMain_Load( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
   
   ' // Add an image control
   dim pWindow as CWindow ptr = AfxCWindowPtr(sender.hWindow)
   if pWindow then
      pImageCtx = @CImageCtx( pWindow, IDC_IMAGECTX, , 10, 10, 200, 200 )
      if pImageCtx then
         pImageCtx->LoadImageFromFile(".\LeftArrow.png")
         pImageCtx->SetImageAdjustment(GDIP_IMAGECTX_AUTOSIZE, true)
      end if
   end if
   
   Function = 0
End Function


--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version