What displays when no image available?

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

What displays when no image available?

Post by Pablo César »

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.
Screen6.png
Screen6.png (26.18 KiB) Viewed 3733 times
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
User avatar
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?

Post by esgici »

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
Viva INTERNATIONAL HMG :D
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

What displays when no image available?

Post by Pablo César »

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.
Demo2_Exe.rar
Executable file
(1.37 MiB) Downloaded 304 times
Demo2.rar
Source files
(145.84 KiB) Downloaded 261 times
Test it and enjoy it ! :)
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
quartz565
Posts: 667
Joined: Mon Oct 01, 2012 12:37 pm
Location: Thessaloniki, Greece
Contact:

Re: What displays when no image available?

Post by quartz565 »

Ευχαριστώ Παύλο !
Best Regards,
Nikos.

os: Windows Server 2019 - 64
User avatar
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?

Post by esgici »

If image really not found :( :
If image really not found.JPG
If image really not found.JPG (58.55 KiB) Viewed 3647 times
Viva HMG :D
Viva INTERNATIONAL HMG :D
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

What displays when no image available?

Post by Pablo César »

esgici wrote:If image really not found :(
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.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
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?

Post by esgici »

Does this is a irreversible method :?: :(
Test draw empty.JPG
Test draw empty.JPG (101.27 KiB) Viewed 3538 times

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 :D
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

What displays when no image available?

Post by Pablo César »

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()
Irreversible?

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
Added later:

Then will be displayed empty image as cross in image control, like this:
Screen6.png
Screen6.png (85.34 KiB) Viewed 3518 times
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
User avatar
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?

Post by esgici »

Pablo César wrote:...
Irreversible?
...
I did not understood what your example with DrawEmpty means.
"Irreversible" means drawing ability on a picture assigned (and become visible) on a IMAGE control.

"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 :D
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

What displays when no image available?

Post by Pablo César »

esgici wrote:"Irreversible" means drawing ability on a picture assigned (and become visible) on a IMAGE control.
How we could have ability to become any image without the image file ?

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.
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.
This not happen with me. I've tested in Win7, XP and Windows 10.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Post Reply