Results 1 to 10 of 10

Thread: How to remove graphic from a label control?

  1. #1

    How to remove graphic from a label control?

    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.
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Have you tried just to send %NULL?

    Control Send hwnd, %ID_LISTVIEW3, %STM_SETIMAGE, %IMAGE_BITMAP, %NULL
    
    and then redraw?
    Last edited by ErosOlmi; 21-01-2019 at 15:32.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    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.

    Thank you for quick reply. Had forgotten about %NULL

    Regards,
    catventure/Phil.
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    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))
    
    Last edited by ErosOlmi; 24-01-2019 at 18:46.

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Thanks a lot José for fixing my reply.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7
    Ok. Thanks for info...

    Eros, so what does the "GDIp_DeleteGraphics(graphic)" do? I can find no example of usage in the help file.
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    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/dot...ts-for-drawing

    thinBasic GDIp module is one module I want to implement and document much more in future thinBasic versions.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  9. #9
    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 TextNow 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.
    Last edited by rossi; 06-02-2019 at 11:30.

  10. #10
    What? Do you have read reply #5?

Similar Threads

  1. Set FontSize on Dialog Label
    By dcromley in forum UI (User Interface)
    Replies: 3
    Last Post: 23-01-2016, 01:25
  2. different font for a label
    By sandyrepope in forum UI (User Interface)
    Replies: 4
    Last Post: 26-02-2012, 19:48
  3. click on a Label
    By zak in forum UI (User Interface)
    Replies: 2
    Last Post: 16-04-2011, 14:49
  4. add label bug or my mistake
    By sandyrepope in forum UI (User Interface)
    Replies: 2
    Last Post: 08-09-2007, 23:07
  5. get label background color
    By sandyrepope in forum UI (User Interface)
    Replies: 1
    Last Post: 09-07-2007, 00:45

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •