PDA

View Full Version : imageCTX two in one



Lionheart008
11-11-2009, 19:52
hi all.

...I am testing the new thinbasic beta :)

I have tried to include two pictures in one imagectx. it's possible ? how can I place these pictures with different width, height values? help manual says nothing about this case.


'------------------------------------------------------------------------------
' IMAGECTX demo
'------------------------------------------------------------------------------

uses "UI"
USES "UIAdv"
uses "File"


begin const
%IDC_IMAGEOPEN = 100
%IDC_IMAGENAME
%ID_Button_01 = 150
%ID_Button_02 = 160
%ButtonClose = 161
%IDC_IMAGECTX_Stretch = 147
%IDC_IMAGECTX_STRETCH2 = 151
%IDC_IMAGEOPEN2 = 152
%IDC_IMAGENAME2 = 153
End Const

'---Globals
dim CurrentFileName as string

'----------------------------------------------------------------------------
FUNCTION TBMain() as long
'----------------------------------------------------------------------------
local hDlg AS DWORD '---Used to store window handle

'---Create a new dialog
Dialog NEW PIXELS, 0, "thinBasic - IMAGECTX_2 Control test", -1, -1, 390, 340, _
%WS_DLGFRAME | _
%DS_CENTER | _
%WS_CAPTION | _
%WS_SYSMENU | _
%WS_OVERLAPPEDWINDOW | _
%WS_CLIPCHILDREN, 0 TO hDlg
'---Set window minimum size
Dialog SET MINSIZE hDlg, 200, 200
Control ADD BUTTON , hDlg ,%ID_Button_01, "good button" ,40,310,80,20, %BS_NOTIFY | %WS_TABSTOP | %BS_DEFAULT , Call cancelButton
Control ADD BUTTON , hDlg, %ButtonClose, "evil button" ,160,310,80,20, %BS_NOTIFY | %WS_TABSTOP , Call cancelButton

'---Show dialog
DIALOG SHOW modal hDlg, call cbDialog_Proc

END FUNCTION

'------------------------------------------------------------------------------
' Callback procedure for main window
'------------------------------------------------------------------------------
callback FUNCTION cbDialog_Proc() as long
'------------------------------------------------------------------------------

DIM sFilter AS STRING

select case cbmsg
case %WM_INITDIALOG
'---Add controls
Control ADD TEXTBOX , CBHNDL, %IDC_IMAGENAME , "" , 5, 5, 285, 20, %ES_READONLY
Control ADD TEXTBOX , CBHNDL, %IDC_IMAGENAME2 , "" , 55, 130, 285, 20, %ES_READONLY
Control ADD BUTTON , CBHNDL, %IDC_IMAGEOPEN , ".1." , 295, 5, 50, 20
Control ADD BUTTON , CBHNDL, %IDC_IMAGEOPEN2 , ".2." , 295, 155, 50, 20
Control ADD IMAGECTX , CBHNDL, %IDC_IMAGECTX_STRETCH , "" , 5, 30, 240, 165, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER
Control ADD IMAGECTX , CBHNDL, %IDC_IMAGECTX_STRETCH2 , "" , 55, 130, 240, 165, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER
IMAGECTX_SetBkColor cbhndl, %IDC_IMAGECTX_STRETCH, rgb(255, 255, 255), %TRUE
IMAGECTX_SetBkColor CBHNDL, %IDC_IMAGECTX_STRETCH2, RGB(255, 255, 255), %TRUE
'---Set resize properties
control set resize cbhndl, %IDC_IMAGEOPEN , 0, 1, 1, 0
control set resize cbhndl, %IDC_IMAGENAME , 1, 1, 1, 0
control set resize cbhndl, %IDC_IMAGECTX_STRETCH , 1, 1, 1, 1

'IMAGECTX_LoadImage cbhndl, %IDC_IMAGECTX_STRETCH, "http://www.virtual-london.com/images/camlive/cam.jpg"

case %WM_COMMAND
select case cbctl
case %IDC_IMAGEOPEN

sFilter = "Image Files (*.BMP, *.GIF, *.JPG, *.PNG)|*.BMP;*.GIF;*.JPG;*.PNG|"
sFilter += "All Files (*.*)|*.*"

CurrentFileName = Dialog_OpenFile(cbhndl, "Open an image file", _
DIR_GetCurrent, _
sFilter, _
"tBasic", _
%OFN_FILEMUSTEXIST OR %OFN_HIDEREADONLY or %OFN_ENABLESIZING)

if file_exists(CurrentFileName) then
control set text cbhndl, %IDC_IMAGENAME, CurrentFileName
IMAGECTX_LoadImage cbhndl, %IDC_IMAGECTX_STRETCH, CurrentFileName
IMAGECTX_SetImageAdjustment cbhndl, %IDC_IMAGECTX_STRETCH, %IMAGECTX_STRETCH, %TRUE
End If

Case %IDC_IMAGEOPEN2

sFilter = "Image Files (*.BMP, *.GIF, *.JPG, *.PNG)|*.BMP;*.GIF;*.JPG;*.PNG|"
sFilter += "All Files (*.*)|*.*"

CurrentFileName = Dialog_OpenFile(CBHNDL, "Open an image file", _
DIR_GetCurrent, _
sFilter, _
"tBasic", _
%OFN_FILEMUSTEXIST Or %OFN_HIDEREADONLY Or %OFN_ENABLESIZING)

If FILE_Exists(CurrentFileName) Then
Control SET TEXT CBHNDL, %IDC_IMAGENAME, CurrentFileName
IMAGECTX_LoadImage CBHNDL, %IDC_IMAGECTX_STRETCH2, CurrentFileName
IMAGECTX_SetImageAdjustment CBHNDL, %IDC_IMAGECTX_STRETCH2, %IMAGECTX_STRETCH, %TRUE
End If

end select

case %WM_SIZE

case %WM_DESTROY
'---Do whatever needed just before dialog is destroyed.

end select


END FUNCTION

CallBack Function CancelButton () As Long

If CBHNDL = %BN_CLICKED Then
Dialog End CBHNDL, 0
Function = 1
End If

End Function


one wish: it's possible to scale the text size (100%, 75%, 50%) of thinair editor ?

I add a photo of adobe reader example what I am meaning with text size scaling.

good evening, thanks in advance, frank

Petr Schreiber
11-11-2009, 23:38
Hi Frank,

I am happy to see your new experiments :)

Sadly your code listing is missing definition of "%ButtonClose" equate, so I had to change "ButtonClose" to "ID_Button_02" to make it run. Is it how it should be?

Which result would you expect by adding 2 pictures to one button? "Combine two images" is quite a science, you can do it in 1000+1 way, but I think this is task for some graphic canvas, TBGL (blending or shaders), but not classic task for button. Maybe you meant one image when mouse is over button, and other when mouse is out?

Text scaling in ThinAir is interesting idea, could you please make a post in ThinAir/Suggest new features so Eros can easily locate related suggestions?


Thanks,
Petr

Lionheart008
12-11-2009, 16:53
hello petr, I have tried only to blend two or three pictures and place them. I will follow this idea, perhaps it's possible to make it with tbgl or canvas modus.

update my test code and you can close by button the window.

one question:

"IMAGECTX_ClearImage(Cbhndl, %IDC_IMAGECTX_STRETCH, %TRUE)" '%False

how can I use this a) to clear the image and b) by button click ?

my ui imagectx example with three pictures possible:


'------------------------------------------------------------------------------
' IMAGECTX demo
'------------------------------------------------------------------------------

uses "UI"
USES "UIAdv"
uses "File"


begin const
%IDC_IMAGEOPEN = 100
%IDC_IMAGENAME
%ID_Button_01 = 150
%ID_Button_02 = 151
%IDC_IMAGECTX_Stretch = 152
%IDC_IMAGECTX_STRETCH2 = 153
%IDC_IMAGECTX_STRETCH3 = 154
%IDC_IMAGEOPEN2 = 155
%IDC_IMAGEOPEN3 = 156
%IDC_IMAGENAME2 = 157
%IDC_IMAGENAME3 = 158
%ButtonClose = 159
End Const

'---Globals
dim CurrentFileName as string

'----------------------------------------------------------------------------
FUNCTION TBMain() as long
'----------------------------------------------------------------------------
local hDlg AS DWORD '---Used to store window handle

'---Create a new dialog
Dialog NEW PIXELS, 0, "thinBasic - IMAGECTX_2 Control test", -1, -1, 420, 460, _
%WS_DLGFRAME | _
%DS_CENTER | _
%WS_CAPTION | _
%WS_SYSMENU | _
%WS_OVERLAPPEDWINDOW | _
%WS_CLIPCHILDREN, 0 TO hDlg
'---Set window minimum size
Dialog SET MINSIZE hDlg, 200, 200
Control ADD BUTTON , hDlg ,%ID_Button_01, "good button" ,40,410,80,30, %BS_NOTIFY | %WS_TABSTOP | %BS_DEFAULT , Call cancelButton
Control ADD BUTTON , hDlg ,%ButtonClose, "close button" ,160,410,80,30, %BS_NOTIFY | %WS_TABSTOP , Call cancelButton

'---Show dialog
DIALOG SHOW modal hDlg, call cbDialog_Proc

END FUNCTION

'------------------------------------------------------------------------------
' Callback procedure for main window
'------------------------------------------------------------------------------
callback FUNCTION cbDialog_Proc() as long
'------------------------------------------------------------------------------

DIM sFilter AS STRING

select case cbmsg
case %WM_INITDIALOG
'---Add controls
Control ADD TEXTBOX , CBHNDL, %IDC_IMAGENAME , "" , 5, 5, 285, 20, %ES_READONLY
Control ADD TEXTBOX , CBHNDL, %IDC_IMAGENAME2 , "" , 55, 370, 285, 20, %ES_READONLY
Control ADD TEXTBOX , CBHNDL, %IDC_IMAGENAME3 , "" , 55, 370, 285, 20, %ES_READONLY

Control ADD BUTTON , CBHNDL, %IDC_IMAGEOPEN , ".1." , 295, 5, 50, 20
Control ADD BUTTON , CBHNDL, %IDC_IMAGEOPEN2 , ".2." , 346, 370, 50, 20
Control ADD BUTTON , CBHNDL, %IDC_IMAGEOPEN3 , ".3." , 295, 25, 50, 20

Control ADD IMAGECTX , CBHNDL, %IDC_IMAGECTX_STRETCH , "" , 5, 30, 240, 165, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER
Control ADD IMAGECTX , CBHNDL, %IDC_IMAGECTX_STRETCH2 , "" , 55, 190, 186, 165, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER
Control ADD IMAGECTX , CBHNDL, %IDC_IMAGECTX_STRETCH3 , "" , 155, 90, 186, 165, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER

IMAGECTX_SetBkColor cbhndl, %IDC_IMAGECTX_STRETCH, rgb(255, 255, 255), %TRUE
IMAGECTX_SetBkColor CBHNDL, %IDC_IMAGECTX_STRETCH2, RGB(255, 255, 255), %TRUE
IMAGECTX_SetBkColor CBHNDL, %IDC_IMAGECTX_STRETCH3, RGB(255, 255, 255), %TRUE

IMAGECTX_ClearImage(Cbhndl, %IDC_IMAGECTX_STRETCH, %TRUE)
IMAGECTX_ClearImage(Cbhndl, %IDC_IMAGECTX_STRETCH2, %TRUE)
IMAGECTX_ClearImage(Cbhndl, %IDC_IMAGECTX_STRETCH3, %TRUE)

'---Set resize properties
control set resize cbhndl, %IDC_IMAGEOPEN , 0, 1, 1, 0
control set resize cbhndl, %IDC_IMAGENAME , 1, 1, 1, 0
control set resize cbhndl, %IDC_IMAGECTX_STRETCH , 1, 1, 1, 1

'IMAGECTX_LoadImage cbhndl, %IDC_IMAGECTX_STRETCH, "http://www.virtual-london.com/images/camlive/cam.jpg"

case %WM_COMMAND
select case cbctl
case %IDC_IMAGEOPEN

sFilter = "Image Files (*.BMP, *.GIF, *.JPG, *.PNG)|*.BMP;*.GIF;*.JPG;*.PNG|"
sFilter += "All Files (*.*)|*.*"

CurrentFileName = Dialog_OpenFile(cbhndl, "Open an image file", _
DIR_GetCurrent, _
sFilter, _
"tBasic", _
%OFN_FILEMUSTEXIST OR %OFN_HIDEREADONLY or %OFN_ENABLESIZING)

if file_exists(CurrentFileName) then
control set text cbhndl, %IDC_IMAGENAME, CurrentFileName
IMAGECTX_LoadImage cbhndl, %IDC_IMAGECTX_STRETCH, CurrentFileName
IMAGECTX_SetImageAdjustment cbhndl, %IDC_IMAGECTX_STRETCH, %IMAGECTX_STRETCH, %TRUE
End If

Case %IDC_IMAGEOPEN2

sFilter = "Image Files (*.BMP, *.GIF, *.JPG, *.PNG)|*.BMP;*.GIF;*.JPG;*.PNG|"
sFilter += "All Files (*.*)|*.*"

CurrentFileName = Dialog_OpenFile(CBHNDL, "Open an image file", _
DIR_GetCurrent, _
sFilter, _
"tBasic", _
%OFN_FILEMUSTEXIST Or %OFN_HIDEREADONLY Or %OFN_ENABLESIZING)

If FILE_Exists(CurrentFileName) Then
Control SET TEXT CBHNDL, %IDC_IMAGENAME, CurrentFileName
IMAGECTX_LoadImage CBHNDL, %IDC_IMAGECTX_STRETCH2, CurrentFileName
IMAGECTX_SetImageAdjustment CBHNDL, %IDC_IMAGECTX_STRETCH2, %IDC_IMAGECTX_STRETCH2, %TRUE
End If

Case %IDC_IMAGEOPEN3

sFilter = "Image Files (*.BMP, *.GIF, *.JPG, *.PNG)|*.BMP;*.GIF;*.JPG;*.PNG|"
sFilter += "All Files (*.*)|*.*"

CurrentFileName = Dialog_OpenFile(CBHNDL, "Open an image file", _
DIR_GetCurrent, _
sFilter, _
"tBasic", _
%OFN_FILEMUSTEXIST Or %OFN_HIDEREADONLY Or %OFN_ENABLESIZING)

If FILE_Exists(CurrentFileName) Then
Control SET TEXT CBHNDL, %IDC_IMAGENAME, CurrentFileName
IMAGECTX_LoadImage CBHNDL, %IDC_IMAGECTX_STRETCH3, CurrentFileName
IMAGECTX_SetImageAdjustment CBHNDL, %IDC_IMAGECTX_STRETCH3, %IDC_IMAGECTX_STRETCH3, %TRUE
End If


end select

case %WM_SIZE

case %WM_DESTROY
'---Do whatever needed just before dialog is destroyed.

end select


END FUNCTION

CallBack Function CancelButton () As Long

Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then Dialog End CBHNDL

Case %WM_DESTROY
MsgBox 0, "Window is to be destroyed."
End Select

End Function


and I have thought it would be possible to use only one "%IDC_IMAGECTX_Stretch" to bind more than one picture.

best regards, thanks, frank

Petr Schreiber
12-11-2009, 17:57
Hi Frank,

"stretch" means to not use image native size, but stretch it to the area of button.
ImageCTX_ClearImage works ok on my PC, just load some images and press "Evil button":


'------------------------------------------------------------------------------
' IMAGECTX demo
'------------------------------------------------------------------------------

Uses "UI"
Uses "UIAdv"
Uses "File"


Begin Const
%IDC_IMAGEOPEN = 100
%IDC_IMAGENAME
%ID_Button_01 = 150
%ID_Button_02 = 151
%IDC_IMAGECTX_Stretch = 152
%IDC_IMAGECTX_STRETCH2 = 153
%IDC_IMAGECTX_STRETCH3 = 154
%IDC_IMAGEOPEN2 = 155
%IDC_IMAGEOPEN3 = 156
%IDC_IMAGENAME2 = 157
%IDC_IMAGENAME3 = 158
%ButtonClose = 159
End Const

'---Globals
Dim CurrentFileName As String

'----------------------------------------------------------------------------
Function TBMain() As Long
'----------------------------------------------------------------------------
Local hDlg As DWord '---Used to store window handle

'---Create a new dialog
Dialog NEW PIXELS, 0, "thinBasic - IMAGECTX_2 Control test", -1, -1, 420, 460, _
%WS_DLGFRAME | _
%DS_CENTER | _
%WS_CAPTION | _
%WS_SYSMENU | _
%WS_OVERLAPPEDWINDOW | _
%WS_CLIPCHILDREN, 0 To hDlg
'---Set window minimum size
Dialog SET MINSIZE hDlg, 200, 200
Control ADD BUTTON , hDlg ,%ID_Button_01, "good button" ,40,410,80,30, %BS_NOTIFY | %WS_TABSTOP | %BS_DEFAULT , Call cancelButton
Control ADD BUTTON , hDlg ,%ButtonClose, "close button" ,160,410,80,30, %BS_NOTIFY | %WS_TABSTOP , Call cancelButton

'---Show dialog
Dialog SHOW MODAL hDlg, Call cbDialog_Proc

End Function

'------------------------------------------------------------------------------
' Callback procedure for main window
'------------------------------------------------------------------------------
CallBack Function cbDialog_Proc() As Long
'------------------------------------------------------------------------------

Dim sFilter As String

Select Case CBMSG
Case %WM_INITDIALOG
'---Add controls
Control ADD TEXTBOX , CBHNDL, %IDC_IMAGENAME , "" , 5, 5, 285, 20, %ES_READONLY
Control ADD TEXTBOX , CBHNDL, %IDC_IMAGENAME2 , "" , 55, 370, 285, 20, %ES_READONLY
Control ADD TEXTBOX , CBHNDL, %IDC_IMAGENAME3 , "" , 55, 370, 285, 20, %ES_READONLY

Control ADD BUTTON , CBHNDL, %IDC_IMAGEOPEN , ".1." , 295, 5, 50, 20
Control ADD BUTTON , CBHNDL, %IDC_IMAGEOPEN2 , ".2." , 346, 370, 50, 20
Control ADD BUTTON , CBHNDL, %IDC_IMAGEOPEN3 , ".3." , 295, 25, 50, 20

Control ADD IMAGECTX , CBHNDL, %IDC_IMAGECTX_STRETCH , "" , 5, 30, 240, 165, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER
Control ADD IMAGECTX , CBHNDL, %IDC_IMAGECTX_STRETCH2 , "" , 55, 190, 186, 165, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER
Control ADD IMAGECTX , CBHNDL, %IDC_IMAGECTX_STRETCH3 , "" , 155, 90, 186, 165, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER

IMAGECTX_SetBkColor CBHNDL, %IDC_IMAGECTX_STRETCH, RGB(255, 255, 255), %TRUE
IMAGECTX_SetBkColor CBHNDL, %IDC_IMAGECTX_STRETCH2, RGB(255, 255, 255), %TRUE
IMAGECTX_SetBkColor CBHNDL, %IDC_IMAGECTX_STRETCH3, RGB(255, 255, 255), %TRUE

IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH, %TRUE)
IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH2, %TRUE)
IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH3, %TRUE)

'---Set resize properties
Control SET RESIZE CBHNDL, %IDC_IMAGEOPEN , 0, 1, 1, 0
Control SET RESIZE CBHNDL, %IDC_IMAGENAME , 1, 1, 1, 0
Control SET RESIZE CBHNDL, %IDC_IMAGECTX_STRETCH , 1, 1, 1, 1

'IMAGECTX_LoadImage cbhndl, %IDC_IMAGECTX_STRETCH, "http://www.virtual-london.com/images/camlive/cam.jpg"

Case %WM_COMMAND
Select Case CBCTL
Case %IDC_IMAGEOPEN

sFilter = "Image Files (*.BMP, *.GIF, *.JPG, *.PNG)|*.BMP;*.GIF;*.JPG;*.PNG|"
sFilter += "All Files (*.*)|*.*"

CurrentFileName = Dialog_OpenFile(CBHNDL, "Open an image file", _
DIR_GetCurrent, _
sFilter, _
"tBasic", _
%OFN_FILEMUSTEXIST Or %OFN_HIDEREADONLY Or %OFN_ENABLESIZING)

If FILE_Exists(CurrentFileName) Then
Control SET TEXT CBHNDL, %IDC_IMAGENAME, CurrentFileName
IMAGECTX_LoadImage CBHNDL, %IDC_IMAGECTX_STRETCH, CurrentFileName
IMAGECTX_SetImageAdjustment CBHNDL, %IDC_IMAGECTX_STRETCH, %IMAGECTX_STRETCH, %TRUE
End If

Case %IDC_IMAGEOPEN2

sFilter = "Image Files (*.BMP, *.GIF, *.JPG, *.PNG)|*.BMP;*.GIF;*.JPG;*.PNG|"
sFilter += "All Files (*.*)|*.*"

CurrentFileName = Dialog_OpenFile(CBHNDL, "Open an image file", _
DIR_GetCurrent, _
sFilter, _
"tBasic", _
%OFN_FILEMUSTEXIST Or %OFN_HIDEREADONLY Or %OFN_ENABLESIZING)

If FILE_Exists(CurrentFileName) Then
Control SET TEXT CBHNDL, %IDC_IMAGENAME, CurrentFileName
IMAGECTX_LoadImage CBHNDL, %IDC_IMAGECTX_STRETCH2, CurrentFileName
IMAGECTX_SetImageAdjustment CBHNDL, %IDC_IMAGECTX_STRETCH2, %IDC_IMAGECTX_STRETCH2, %TRUE
End If

Case %IDC_IMAGEOPEN3

sFilter = "Image Files (*.BMP, *.GIF, *.JPG, *.PNG)|*.BMP;*.GIF;*.JPG;*.PNG|"
sFilter += "All Files (*.*)|*.*"

CurrentFileName = Dialog_OpenFile(CBHNDL, "Open an image file", _
DIR_GetCurrent, _
sFilter, _
"tBasic", _
%OFN_FILEMUSTEXIST Or %OFN_HIDEREADONLY Or %OFN_ENABLESIZING)

If FILE_Exists(CurrentFileName) Then
Control SET TEXT CBHNDL, %IDC_IMAGENAME, CurrentFileName
IMAGECTX_LoadImage CBHNDL, %IDC_IMAGECTX_STRETCH3, CurrentFileName
IMAGECTX_SetImageAdjustment CBHNDL, %IDC_IMAGECTX_STRETCH3, %IDC_IMAGECTX_STRETCH3, %TRUE
End If

Case %ID_BUTTON_02
If Callback_Control_Message = %BN_CLICK Then
IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH, %TRUE)
IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH2, %TRUE)
IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH3, %TRUE)
End If


End Select


Case %WM_SIZE

Case %WM_DESTROY
'---Do whatever needed just before dialog is destroyed.

End Select


End Function

CallBack Function CancelButton () As Long

Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then Dialog End CBHNDL

Case %WM_DESTROY
MsgBox 0, "Window is to be destroyed."
End Select

End Function


The only added code was:


Case %ID_BUTTON_02
If Callback_Control_Message = %BN_CLICK Then
IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH, %TRUE)
IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH2, %TRUE)
IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH3, %TRUE)
End If

Lionheart008
12-11-2009, 19:48
hello petr again :)

sorry, your example doesn't work here for clearing images in your suggested way. have tried it. thanks, but I found a better solution by callback... see attached script. worked fine, thanks for help, it's new for me to work with imagectx.

correct code with clearing image:

'------------------------------------------------------------------------------
' IMAGECTX demo by Lionheart 12.nov.2009 :)
'------------------------------------------------------------------------------

Uses "UI","console"
Uses "UIAdv"
Uses "File"


Begin Const
%IDC_IMAGEOPEN = 100
%IDC_IMAGENAME
%ID_Button_01 = 150
%ID_Button_02 = 151
%IDC_IMAGECTX_Stretch = 152
%IDC_IMAGECTX_STRETCH2 = 153
%IDC_IMAGECTX_STRETCH3 = 154
%IDC_IMAGEOPEN2 = 155
%IDC_IMAGEOPEN3 = 156
%IDC_IMAGENAME2 = 157
%IDC_IMAGENAME3 = 158
%ButtonClose = 159
%BN_CLICK = 160
End Const

'---Globals
Dim CurrentFileName As String
DIM Callback_Control_Message as long

'----------------------------------------------------------------------------
Function TBMain() As Long
'----------------------------------------------------------------------------
Local hDlg As DWord '---Used to store window handle

'---Create a new dialog
Dialog NEW PIXELS, 0, "thinBasic - IMAGECTX_2ax Control test", -1, -1, 420, 460, _
%WS_DLGFRAME | _
%DS_CENTER | _
%WS_CAPTION | _
%WS_SYSMENU | _
%WS_OVERLAPPEDWINDOW | _
%WS_CLIPCHILDREN, 0 To hDlg
'---Set window minimum size
Dialog SET MINSIZE hDlg, 200, 200
Control ADD BUTTON , hDlg ,%ID_Button_01, "good button" ,40,410,80,30, %BS_NOTIFY | %WS_TABSTOP | %BS_DEFAULT , Call cancelButton
Control ADD BUTTON , hDlg ,%ButtonClose, "close button" ,160,410,80,30, %BS_NOTIFY | %WS_TABSTOP , Call cancelButton
Control ADD BUTTON , hDlg ,%ID_Button_02, "evil button" ,240,410,80,30, %BS_NOTIFY | %WS_TABSTOP , Call stretch

'---Show dialog
Dialog SHOW MODAL hDlg, Call cbDialog_Proc

End Function

'------------------------------------------------------------------------------
' Callback procedure for main window
'------------------------------------------------------------------------------
CallBack Function cbDialog_Proc() As Long
'------------------------------------------------------------------------------

Dim sFilter As String

Select Case CBMSG
Case %WM_INITDIALOG
'---Add controls
Control ADD TEXTBOX , CBHNDL, %IDC_IMAGENAME , "" , 5, 5, 285, 20, %ES_READONLY
Control ADD TEXTBOX , CBHNDL, %IDC_IMAGENAME2 , "" , 55, 370, 285, 20, %ES_READONLY
Control ADD TEXTBOX , CBHNDL, %IDC_IMAGENAME3 , "" , 55, 370, 285, 20, %ES_READONLY

Control ADD BUTTON , CBHNDL, %IDC_IMAGEOPEN , ".1." , 295, 5, 50, 20
Control ADD BUTTON , CBHNDL, %IDC_IMAGEOPEN2 , ".2." , 346, 370, 50, 20
Control ADD BUTTON , CBHNDL, %IDC_IMAGEOPEN3 , ".3." , 295, 25, 50, 20

Control ADD IMAGECTX , CBHNDL, %IDC_IMAGECTX_STRETCH , "" , 5, 30, 240, 165, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER
Control ADD IMAGECTX , CBHNDL, %IDC_IMAGECTX_STRETCH2 , "" , 55, 190, 186, 165, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER
Control ADD IMAGECTX , CBHNDL, %IDC_IMAGECTX_STRETCH3 , "" , 155, 90, 186, 165, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER

IMAGECTX_SetBkColor CBHNDL, %IDC_IMAGECTX_STRETCH, RGB(255, 255, 255), %TRUE
IMAGECTX_SetBkColor CBHNDL, %IDC_IMAGECTX_STRETCH2, RGB(255, 255, 255), %TRUE
IMAGECTX_SetBkColor CBHNDL, %IDC_IMAGECTX_STRETCH3, RGB(255, 255, 255), %TRUE

IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH, %TRUE)
IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH2, %TRUE)
IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH3, %TRUE)

'---Set resize properties
Control SET RESIZE CBHNDL, %IDC_IMAGEOPEN , 0, 1, 1, 0
Control SET RESIZE CBHNDL, %IDC_IMAGENAME , 1, 1, 1, 0
Control SET RESIZE CBHNDL, %IDC_IMAGECTX_STRETCH , 1, 1, 1, 1

'IMAGECTX_LoadImage cbhndl, %IDC_IMAGECTX_STRETCH, "http://www.virtual-london.com/images/camlive/cam.jpg"

Case %WM_COMMAND
Select Case CBCTL
Case %IDC_IMAGEOPEN

sFilter = "Image Files (*.BMP, *.GIF, *.JPG, *.PNG)|*.BMP;*.GIF;*.JPG;*.PNG|"
sFilter += "All Files (*.*)|*.*"

CurrentFileName = Dialog_OpenFile(CBHNDL, "Open an image file", _
DIR_GetCurrent, _
sFilter, _
"tBasic", _
%OFN_FILEMUSTEXIST Or %OFN_HIDEREADONLY Or %OFN_ENABLESIZING)

If FILE_Exists(CurrentFileName) Then
Control SET TEXT CBHNDL, %IDC_IMAGENAME, CurrentFileName
IMAGECTX_LoadImage CBHNDL, %IDC_IMAGECTX_STRETCH, CurrentFileName
IMAGECTX_SetImageAdjustment CBHNDL, %IDC_IMAGECTX_STRETCH, %IMAGECTX_STRETCH, %TRUE
End If

Case %IDC_IMAGEOPEN2

sFilter = "Image Files (*.BMP, *.GIF, *.JPG, *.PNG)|*.BMP;*.GIF;*.JPG;*.PNG|"
sFilter += "All Files (*.*)|*.*"

CurrentFileName = Dialog_OpenFile(CBHNDL, "Open an image file", _
DIR_GetCurrent, _
sFilter, _
"tBasic", _
%OFN_FILEMUSTEXIST Or %OFN_HIDEREADONLY Or %OFN_ENABLESIZING)

If FILE_Exists(CurrentFileName) Then
Control SET TEXT CBHNDL, %IDC_IMAGENAME, CurrentFileName
IMAGECTX_LoadImage CBHNDL, %IDC_IMAGECTX_STRETCH2, CurrentFileName
IMAGECTX_SetImageAdjustment CBHNDL, %IDC_IMAGECTX_STRETCH2, %IDC_IMAGECTX_STRETCH2, %TRUE
End If

Case %IDC_IMAGEOPEN3

sFilter = "Image Files (*.BMP, *.GIF, *.JPG, *.PNG)|*.BMP;*.GIF;*.JPG;*.PNG|"
sFilter += "All Files (*.*)|*.*"

CurrentFileName = Dialog_OpenFile(CBHNDL, "Open an image file", _
DIR_GetCurrent, _
sFilter, _
"tBasic", _
%OFN_FILEMUSTEXIST Or %OFN_HIDEREADONLY Or %OFN_ENABLESIZING)

If FILE_Exists(CurrentFileName) Then
Control SET TEXT CBHNDL, %IDC_IMAGENAME, CurrentFileName
IMAGECTX_LoadImage CBHNDL, %IDC_IMAGECTX_STRETCH3, CurrentFileName
IMAGECTX_SetImageAdjustment CBHNDL, %IDC_IMAGECTX_STRETCH3, %IDC_IMAGECTX_STRETCH3, %TRUE
End If

Case %ID_BUTTON_02
If Callback_Control_Message = %BN_CLICK Then

IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH, %TRUE)
IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH2, %TRUE)
IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH3, %TRUE)

End If


End Select


Case %WM_SIZE

Case %WM_DESTROY
'---Do whatever needed just before dialog is destroyed.

End Select


End Function

CallBack Function CancelButton () As Long

Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then Dialog End CBHNDL

Case %WM_DESTROY
MsgBox 0, "Window is to be destroyed."
End Select

End Function


CallBack Function stretch () As Long

Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ID_BUTTON_02 Then

IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH, %TRUE)
IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH2, %TRUE)
IMAGECTX_ClearImage(CBHNDL, %IDC_IMAGECTX_STRETCH3, %TRUE)

End If
END SELECT
End Function


as you can see I have included second function (stretch) to clear images and for "evil button" a callback.

best regards, nice evening, frank

Petr Schreiber
12-11-2009, 19:52
I see why my example did not worked for you - you do not have the latest beta! :)

Then it would work ok, do not hesitate and grab it here: http://community.thinbasic.com/index.php?topic=2899.msg22571#msg22571