[v2] make PictureControl.Value return current picture's filepath

Propose new features and changes
neogna2
Posts: 591
Joined: 15 Sep 2016, 15:44

[v2] make PictureControl.Value return current picture's filepath

28 Dec 2022, 12:49

https://www.autohotkey.com/docs/v2/lib/GuiControl.htm#Value
Picture
RetrievedValue is the picture's file name as it was originally specified when the Picture control was created. This name does not change even if a new picture file name is specified.
I wish RetrievedValue was the control's current picture's filepath
lexikos
Posts: 9593
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2] make PictureControl.Value return current picture's filepath

29 Dec 2022, 20:39

If you want the path that was used to load the picture, you have to store it. The control itself only has a bitmap handle, and text that was set when the control was created. The control's text cannot be changed without removing the SS_BITMAP or SS_ICON style, but that can be done temporarily when you are changing the image. (It may be best to remove the image with STM_SETIMAGE and delete it, as it would probably be leaked if you simply removed the style.)

The program could internally call SetWindowText to update the control's text after removing its previous bitmap, but this would break the previously documented behaviour. The control's text can be used to identify the control (in lieu of a name for Gui[Name] or ClassNN for other functions) even after the picture has been changed.

If you want to know where the image came from, you don't need to get it from the control's text; you can store the path somewhere whenever you change the picture. The value returned by Pic.Value is of limited use if you did not set it yourself (if, for example, you're code for others to use), as it isn't necessarily a valid file path. For instance, a picture can be loaded from a relative path, and the working directory may have changed. A picture can also be loaded from a dll file, in which case the path often isn't an absolute path and isn't relative to the working directory either.
neogna2
Posts: 591
Joined: 15 Sep 2016, 15:44

Re: [v2] make PictureControl.Value return current picture's filepath

30 Dec 2022, 05:38

lexikos wrote:
29 Dec 2022, 20:39
you can store the path somewhere whenever you change the picture.
Yeah, I currently create a property like PicCtrlObj.Path or GuiObj["CtrlName"].Path and update it when I change the picture. Would be nice as a built in, that's all. To the user (internal implementation details aside) the Picture control has a Value property with get/set syntax similar to e.g. Text or Edit.
Ctrl.Value := Set
Get := Ctrl.Value

Get on Text and Edit returns the current value. So it would be a nice fit if Picture behaved the same.
lexikos wrote:
29 Dec 2022, 20:39
> but this would break the previously documented behaviour.
True. When posting I assumed it would be uncommon to rely on that behaviour, but in fact who knows? A non-breaking version of my wish is a built in .Path or .CurrentPath property for Picture then.

Also thanks for the other details. In general I like how your posts are often like that, leaving a breadcrumb trail of information that may later turn out to be useful and turn up in search results.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 21 guests