PDA

View Full Version : How to remove graphic from a label control?



catventure
21-01-2019, 14:57
How can I clear a label control of a picture put there by GDIp commands?



If FILE_Exists( szfile ) Then
'---Create an image handle
hGpBitmap = GDIp_CreateBitMapFromFile( szfile )
'---Convert to a BMP handle
hBitmap3 = GDIp_CreateHBitMapFromBitmap(hGpBitmap, 0)
GDIp_DisposeImage(hGpBitmap)
'---Show picture in Label control
Control Send hwnd, %ID_LISTVIEW3, %STM_SETIMAGE, %IMAGE_BITMAP, hBitmap3
'---Following commands ensure picture appears correctly and is sized correctly in control
SendMessage hwnd, %WM_SIZE, 0,1
Control Redraw hwnd, %id_listview3
Exit Function
End If


How can I erase/delete the graphic from the label instantly?
I tried:
Object_Delete (hBitmap3)
Didn't seem to work as I had thought and there is a
GDIp_DeleteGraphics
command but not sure how to use....

Any help appreciated.

Regards,
catventure.

ErosOlmi
21-01-2019, 15:15
Have you tried just to send %NULL?


Control Send hwnd, %ID_LISTVIEW3, %STM_SETIMAGE, %IMAGE_BITMAP, %NULL

and then redraw?

catventure
21-01-2019, 15:55
Hi Eros,

No - I had not tried to send %NULL
In fact, never even thought of that!!! :)

YES - I'm happy. It works as I thought it would do.:p

Thank you for quick reply. Had forgotten about %NULL

Regards,
catventure/Phil.

ErosOlmi
21-01-2019, 16:19
Happy it works.

When you assign an image handle to a control, the image is copied by Windows into the control in order to maintain that control as independent from the original image.
To remove the image from the control, just assign a %NULL and Windows will remove the assigned image and will also remove the image from its internal stock.

Ciao
Eros

José Roca
22-01-2019, 09:53
When you assign an image handle to a control, the image is copied by Windows into the control in order to maintain that control as independent from the original image.


No, it does not copy anything. It simply stores the passed handle in the extra bytes of the control and returns the previous stored handle, if any.

prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
...
return prevIcon



To remove the image from the control, just assign a %NULL and Windows will remove the assigned image and will also remove the image from its internal stock.


No, it does not remove any image. It will simply store a null value.

The caller is responsible of deleting the bitmap:



DeleteObject (SendMessage(hwnd, %ID_LISTVIEW3, %STM_SETIMAGE, %IMAGE_BITMAP, %NULL))


Change the above line to work with Control Send. Maybe something like



Control Send hwnd, %ID_LISTVIEW3, %STM_SETIMAGE, %IMAGE_BITMAP, hBitmap3 TO oldBitmap
DeleteObject oldBitmap


You must also delete the returned handle if instead of NULL you pass the handle of a new bitmap to replace an existing one:



DeleteObject (SendMessage(hwnd, %ID_LISTVIEW3, %STM_SETIMAGE, %IMAGE_BITMAP, newBitmapHandle))

ErosOlmi
24-01-2019, 18:48
Thanks a lot José for fixing my reply.

Ciao
Eros

catventure
25-01-2019, 17:10
Ok. Thanks for info...

Eros, so what does the "GDIp_DeleteGraphics(graphic)" do? I can find no example of usage in the help file.

ErosOlmi
30-01-2019, 08:47
That function is used to tell GDI+ engine to remove a graphics object not needed anymore.

Here info about what is a GDI+ graphics: https://docs.microsoft.com/en-us/dotnet/framework/winforms/advanced/how-to-create-graphics-objects-for-drawing

thinBasic GDIp module is one module I want to implement and document much more in future thinBasic versions.

rossi
05-02-2019, 16:30
When you relegate a picture handle to a control, the picture is duplicated by Windows into the control so as to keep up that control as free from the first picture Pnr Status (https://pnrstatus.vip/) TextNow (https://textnow.vip/) VPN (https://downloader.vip/vpn/).

To expel the picture from the control, simply dole out a %NULL and Windows will evacuate the doled out picture and will likewise expel the picture from its inner stock.

José Roca
05-02-2019, 19:42
What? Do you have read reply #5?