What displays when no image available?
Moderator: Rathinagiri
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
What displays when no image available?
Hi All,
We can create a special image file when just start a new record and we solve the missing image. But you can make it better and like as is done in HMG IDE
There is a simple way to display without any file.
Just improve your lean apps with powerous Boss Taurus resources.
In this example, are defined hmg2.bmp, hmg3.bmp and hmg4.bmp for Images controls at Demo2.fmg file. Those bmp files will not be found then not will be loaded too but it will be displayed a cross as empty image at each control image.
Here's source files to see IfNotFoundImg function and Crop images from rc files and replacement in image controls.
<Attached source files and executable was removed because there is a newer version released more ahead of this message in this same topic>
We can create a special image file when just start a new record and we solve the missing image. But you can make it better and like as is done in HMG IDE
There is a simple way to display without any file.
Just improve your lean apps with powerous Boss Taurus resources.
In this example, are defined hmg2.bmp, hmg3.bmp and hmg4.bmp for Images controls at Demo2.fmg file. Those bmp files will not be found then not will be loaded too but it will be displayed a cross as empty image at each control image.
Here's source files to see IfNotFoundImg function and Crop images from rc files and replacement in image controls.
<Attached source files and executable was removed because there is a newer version released more ahead of this message in this same topic>
Last edited by Pablo César on Fri Sep 23, 2016 11:54 pm, edited 6 times in total.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: What displays when no image available?
WINDRES: can't open file `Images\hmg.png': No such file or directory
Harbour 3.2.0dev (r1509031202)
Copyright (c) 1999-2015, http://harbour-project.org/
gcc.exe: error: C:/temp/test/WhenNoImg/_temp.o: No such file or directory
Harbour 3.2.0dev (r1509031202)
Copyright (c) 1999-2015, http://harbour-project.org/
gcc.exe: error: C:/temp/test/WhenNoImg/_temp.o: No such file or directory
Viva INTERNATIONAL HMG
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
What displays when no image available?
I have done second version for following reasons:
1. Compiling source error by the reason is missing images files. Now I know there is not sense to post a demo with missing files. My intention was to avoid attaching images files and provide only sources files for learning proposes.
2. I've improved the code when an image has been loaded instead to check if file exists.
Thischecking if file exists is a mistake because images can be cropped from rc file then existence will not work properlly.
Test it and enjoy it !
1. Compiling source error by the reason is missing images files. Now I know there is not sense to post a demo with missing files. My intention was to avoid attaching images files and provide only sources files for learning proposes.
2. I've improved the code when an image has been loaded instead to check if file exists.
Thischecking if file exists is a mistake because images can be cropped from rc file then existence will not work properlly.
Test it and enjoy it !
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Re: What displays when no image available?
Ευχαριστώ Παύλο !
Best Regards,
Nikos.
os: Windows Server 2019 - 64
Nikos.
os: Windows Server 2019 - 64
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: What displays when no image available?
If image really not found :
Viva HMG
Viva HMG
Viva INTERNATIONAL HMG
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
What displays when no image available?
Submit option extacts images from rc file for images replacement. Check you rc file, should not be empty before you compile and Images must be as subfolder where exe is running.esgici wrote:If image really not found
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: What displays when no image available?
Does this is a irreversible method
Code: Select all
#include <hmg.ch>
Function Main()
PRIVATE hBitmap := 0
LOAD WINDOW Demo2 AS Demo_2
// SET CONTROL Image_1 OF Demo_2 CLIENTEDGE
SET CONTROL Label_3 OF Demo_2 CLIENTEDGE
SET CONTROL Label_5 OF Demo_2 CLIENTEDGE
SET CONTROL Label_7 OF Demo_2 CLIENTEDGE
SET CONTROL Label_8 OF Demo_2 CLIENTEDGE
ON KEY ESCAPE OF Demo_2 ACTION ThisWindow.Release
Demo_2.Center
/*
IfNotFoundImg("Demo_2","Image_1",{255,153,153})
IfNotFoundImg("Demo_2","Image_2",CYAN)
IfNotFoundImg("Demo_2","Image_3",GREEN)
IfNotFoundImg("Demo_2","Image_4",YELLOW)
*/
Demo_2.Activate
Return Nil
Function IfNotFoundImg(cFormName,cControlName,aRGBcolor_Fill_Bk)
LOCAL i := GetControlIndex ( cControlName, cFormName )
LOCAL nWidth := _HMG_SYSDATA [ 31 ] [i]
LOCAL nHeight := _HMG_SYSDATA [ 32 ] [i]
LOCAL cImgFile := _HMG_SYSDATA [ 25 ] [i]
LOCAL hDC, BTstruct
hBitmap := BT_HMGGetImage (cFormName, cControlName)
If !File(cImgFile) .AND. hBitmap = 0
hBitmap := BT_BitmapCreateNew (nWidth, nHeight, aRGBcolor_Fill_Bk)
hDC := BT_CreateDC (hBitmap, BT_HDC_BITMAP, @BTstruct)
BT_DrawRectangle (hDC, 0, 0, nWidth-1, nHeight-1, BLACK, 1)
BT_DrawLine (hDC, 0, 0, nHeight, nWidth, BLACK, 1)
BT_DrawLine (hDC, nHeight, 0, 0, nWidth, BLACK, 1)
BT_DeleteDC (BTstruct)
BT_HMGSetImage (cFormName, cControlName, hBitmap, .T.)
Endif
Return Nil
Function Proc_ON_RELEASE
BT_BitmapRelease (hBitmap) // Very important
Return Nil
Function Submit(cFileName)
SetNewImage("Image_1","HMG")
SetNewImage("Image_2","PAUL")
SetNewImage("Image_3","AVAILABLE")
SetNewImage("Image_4","PRODUCT")
Return Nil
Function SetNewImage(cControl, cFileName)
LOCAL hBitmap_aux := 0
LOCAL cForm := "Demo_2"
LOCAL w := GetProperty(cForm,cControl,"Width")
LOCAL h := GetProperty(cForm,cControl,"Height")
hBitmap_aux := BT_BitmapLoadFile (cFileName)
hBitmap := BT_BitmapCopyAndResize (hBitmap_aux, w, h, NIL, BT_RESIZE_HALFTONE)
BT_BitmapRelease (hBitmap_aux)
BT_HMGSetImage (cForm, cControl, hBitmap, .F.)
Return Nil
PROC DrawEmpty()
IfNotFoundImg("Demo_2","Image_1",{255,153,153})
IfNotFoundImg("Demo_2","Image_2",CYAN)
IfNotFoundImg("Demo_2","Image_3",GREEN)
IfNotFoundImg("Demo_2","Image_4",YELLOW)
RETU // DrawEmpty()
Viva INTERNATIONAL HMG
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
What displays when no image available?
Irreversible?esgici wrote:Does this is a irreversible method
Code: Select all
#include <hmg.ch> Function Main() PRIVATE hBitmap := 0 LOAD WINDOW Demo2 AS Demo_2 // SET CONTROL Image_1 OF Demo_2 CLIENTEDGE SET CONTROL Label_3 OF Demo_2 CLIENTEDGE SET CONTROL Label_5 OF Demo_2 CLIENTEDGE SET CONTROL Label_7 OF Demo_2 CLIENTEDGE SET CONTROL Label_8 OF Demo_2 CLIENTEDGE ON KEY ESCAPE OF Demo_2 ACTION ThisWindow.Release Demo_2.Center /* IfNotFoundImg("Demo_2","Image_1",{255,153,153}) IfNotFoundImg("Demo_2","Image_2",CYAN) IfNotFoundImg("Demo_2","Image_3",GREEN) IfNotFoundImg("Demo_2","Image_4",YELLOW) */ Demo_2.Activate Return Nil Function IfNotFoundImg(cFormName,cControlName,aRGBcolor_Fill_Bk) LOCAL i := GetControlIndex ( cControlName, cFormName ) LOCAL nWidth := _HMG_SYSDATA [ 31 ] [i] LOCAL nHeight := _HMG_SYSDATA [ 32 ] [i] LOCAL cImgFile := _HMG_SYSDATA [ 25 ] [i] LOCAL hDC, BTstruct hBitmap := BT_HMGGetImage (cFormName, cControlName) If !File(cImgFile) .AND. hBitmap = 0 hBitmap := BT_BitmapCreateNew (nWidth, nHeight, aRGBcolor_Fill_Bk) hDC := BT_CreateDC (hBitmap, BT_HDC_BITMAP, @BTstruct) BT_DrawRectangle (hDC, 0, 0, nWidth-1, nHeight-1, BLACK, 1) BT_DrawLine (hDC, 0, 0, nHeight, nWidth, BLACK, 1) BT_DrawLine (hDC, nHeight, 0, 0, nWidth, BLACK, 1) BT_DeleteDC (BTstruct) BT_HMGSetImage (cFormName, cControlName, hBitmap, .T.) Endif Return Nil Function Proc_ON_RELEASE BT_BitmapRelease (hBitmap) // Very important Return Nil Function Submit(cFileName) SetNewImage("Image_1","HMG") SetNewImage("Image_2","PAUL") SetNewImage("Image_3","AVAILABLE") SetNewImage("Image_4","PRODUCT") Return Nil Function SetNewImage(cControl, cFileName) LOCAL hBitmap_aux := 0 LOCAL cForm := "Demo_2" LOCAL w := GetProperty(cForm,cControl,"Width") LOCAL h := GetProperty(cForm,cControl,"Height") hBitmap_aux := BT_BitmapLoadFile (cFileName) hBitmap := BT_BitmapCopyAndResize (hBitmap_aux, w, h, NIL, BT_RESIZE_HALFTONE) BT_BitmapRelease (hBitmap_aux) BT_HMGSetImage (cForm, cControl, hBitmap, .F.) Return Nil PROC DrawEmpty() IfNotFoundImg("Demo_2","Image_1",{255,153,153}) IfNotFoundImg("Demo_2","Image_2",CYAN) IfNotFoundImg("Demo_2","Image_3",GREEN) IfNotFoundImg("Demo_2","Image_4",YELLOW) RETU // DrawEmpty()
IfNotFoundImg function was created with propose to display something in place of empty image.
In my demo2, if you delete any file at Images folder you will see a cross inside image control instead of blank or non existential control by viewing. This can happen when users deletes files or when open a new register when image of client was not taken picture yet.
IfNotFoundImg function you can use it as you want and where you want at place of your app.
I do not know if I've understood what you means with your example of DrawEmpty.
In case of deleting image from the control and is this would be your case, can be solved with this:
Code: Select all
// PROC DrawEmpty()
Function DeleteRecord()
SetProperty("Demo_2","Image_2","PICTURE","") // Paul's removing
IfNotFoundImg("Demo_2","Image_2",CYAN)
Return Nil
Then will be displayed empty image as cross in image control, like this:
Last edited by Pablo César on Mon Sep 26, 2016 2:06 pm, edited 2 times in total.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: What displays when no image available?
"Irreversible" means drawing ability on a picture assigned (and become visible) on a IMAGE control.Pablo César wrote:...
Irreversible?
...
I did not understood what your example with DrawEmpty means.
"DrawEmpty" attempt do this ...
More, when clicking that two button randomly and successively produce very bad results (crash prg, entirely black screen and lost of keyboard and mouse functionality.
Added later :
Please give up changing sent post
Viva INTERNATIONAL HMG
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
What displays when no image available?
How we could have ability to become any image without the image file ?esgici wrote:"Irreversible" means drawing ability on a picture assigned (and become visible) on a IMAGE control.
If you want to apply a "new" picture at your image control, you must use SetProperty with "PICTURE" parameter as always be done in HMG.
This not happen with me. I've tested in Win7, XP and Windows 10.esgici wrote:More, when clicking that two button randomly and successively produce very bad results (crash prg, entirely black screen and lost of keyboard and mouse functionality.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein