[RESOLVED] Get Filename from Initialized Object
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: [RESOLVED] Get Filename from Initialized Object

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    [RESOLVED] Get Filename from Initialized Object

    I'm afraid I already know the answer to this question, but hey, it never hurts to ask right?

    I have an application where several images are loaded as properties of control(s) at design time and / or at runtime. Ones that are loaded at runtime are loaded via Commondialog and the filename is stored in an parallel array to the image object array so I can keep the file names for subsequent loads, however if the image is loaded at design time via the property panel I can't programatically get the filename. The long pointer of course does me no good once the instance of the object expires.

    I was hoping there was an API call that would retrieve the filename and possibly other file information from the initialized Picture Object. Anyone have any 'pointers' (No pun intended)

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: Get Filename from Initialized Object

    You got premonitions about this?

    Imagery that is loaded at design time on a form or a form's control is stored as bitmap ressources in the file .frx which accompanies the code file .frm of a form. You have no later access to the filename, because you don't need. The image data will be compiled into the exe file.
    You better load the initial images at program start if you require them to be changeable files.

  3. #3
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    Re: Get Filename from Initialized Object

    WoF,

    Thanks. That was pretty much the conclusion I had come to. I have another workaround but I just don't like it as much.

    My Situation is this. I have developed a custom control that has 5 different Image properties. For the most part, once the images are set at design time thats it, most new instances of the control will use the same 5 images. However, in order to simplify matters for myself, I'm writing my property values out to an INI file so that the next time I fire up VB, pop the control on a form it grabs the last used settings, including the image file names, sets the variables and voila' I'm in business without having to reconfigure the control. It all works great, BUT. I've done this by use of a property page that uses contains a Common Dialog box, the image property fields are on the property page. They also appear in the Property Panel in VB, but since I'm loading string values instead of Picture Objects, the Property Panel just has text fields. If I use Get/Set instead of Get/Let and use StdPicture types instead of String Types, I get the nice little Select Image dialog straight from the Property Panel. But as you can imagine, there's no way for me to Write that value to an INI file. So it's either stick with the Property Page or reconfigure the control each time I use a new instance of it. I know this sounds a little Petty, it just bugs me that I can't have my cake and eat it too.

    Eric

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: Get Filename from Initialized Object

    If a reconfiguration of your control does not mean to completely replace all of the images by other image files, you can consider of putting all possible images int an image list and make a selection machanism within your control, to selct the images according to configuration information. So NONE of the possible mages are in files anymore. All imagery is contained within the control.

  5. #5
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    Re: Get Filename from Initialized Object

    Wof,

    Yes, I had considered that option as well, but in the particular case I'm developing the control for, there is the likelihood of a dozen or more instances of the control on a single form, and potentially up to 32 instances, and the image list with images loaded would create a lot of additional overhead, not to mention redundancy. The property page actually works out pretty nicely, I just don't like the text fields in the Property Panel.

  6. #6
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Get Filename from Initialized Object

    What I've done in the past, is to set the Picture property to use a PropertyPage. Then, that PropertyPage has the filename field, and a browse button to locate the file. So it's basically using your own custom dialog to get the picture, allowing you to also get the filename. From there, your code can save the filename, and/or create an StdPicture object. The control's property works the same from code as it does without the PropertyPage association. You can also create Friend or Public properties so the control can get the filename in addition to the StdPicture object.

    Make the PropertyPage association by opening the control, and selecting "Procedure Attributes..." from the Tools menu.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center