PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: CImageCtx Class  (Read 766 times)

Bumblebee

  • Junior Member
  • **
  • Posts: 58
CImageCtx Class
« on: June 24, 2020, 08:32:02 AM »

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.
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9323
  • Windows 10
    • PlanetSquires Software
Re: CImageCtx Class
« Reply #1 on: June 24, 2020, 01:57:38 PM »

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"

Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Bumblebee

  • Junior Member
  • **
  • Posts: 58
Re: CImageCtx Class
« Reply #2 on: June 25, 2020, 02:18:11 AM »

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?
Logged

Bumblebee

  • Junior Member
  • **
  • Posts: 58
Re: CImageCtx Class
« Reply #3 on: June 25, 2020, 11:14:42 AM »

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: [Select]
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)

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)
« Last Edit: June 25, 2020, 11:21:04 AM by Bumblebee »
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9323
  • Windows 10
    • PlanetSquires Software
Re: CImageCtx Class
« Reply #4 on: June 25, 2020, 02:59:12 PM »

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: [Select]

#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

Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9323
  • Windows 10
    • PlanetSquires Software
Re: CImageCtx Class
« Reply #5 on: June 25, 2020, 04:06:25 PM »

Here you go. Fully working now. I forgot to instantiate the control with NEW and then DELETE it when the Form destroys.

Code: [Select]
#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 = new 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

''
''
Function frmMain_FormClosed( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
   if pImageCtx then
      delete pImageCtx
      pImageCtx = 0
   end if
   Function = 0
End Function

Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Bumblebee

  • Junior Member
  • **
  • Posts: 58
Re: CImageCtx Class
« Reply #6 on: June 25, 2020, 09:49:09 PM »

Thank-you.
I look forward to the era when I understand what's going on with this code.
I really need to study the .inc and .bi files that are being referenced.
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9323
  • Windows 10
    • PlanetSquires Software
Re: CImageCtx Class
« Reply #7 on: June 26, 2020, 09:25:18 AM »

I have added the 'ImageFromFile' property to the PictureBox control so you should be able to change the picture via external disk files at runtime. Will be in the next update.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Bumblebee

  • Junior Member
  • **
  • Posts: 58
Re: CImageCtx Class
« Reply #8 on: June 26, 2020, 01:12:05 PM »

I'll be sure to try it out.
Question: Does this control receive focus when the tab key is pressed?
Logged

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3284
Re: CImageCtx Class
« Reply #9 on: June 26, 2020, 01:36:27 PM »

> Question: Does this control receive focus when the tab key is pressed?

Not by default, but you can specify the window control styles when you create it and add WS_TABSTOP.

Bumblebee

  • Junior Member
  • **
  • Posts: 58
Re: CImageCtx Class
« Reply #10 on: June 26, 2020, 01:44:14 PM »

I've attached a zipped project in the WinFBE version thread. Default behavior is unusual.
Logged