[RESOLVED] How to setup a UserControl Property to Browse for a file - Page 2-VBForums
Page 2 of 3 FirstFirst 123 LastLast
Results 41 to 80 of 119

Thread: [RESOLVED] How to setup a UserControl Property to Browse for a file

  1. #41
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    One method of unloading the property page would be to send an ESC key to the page. ESC doesn't activate the "apply" button, but in your case, there isn't anything to "apply". In that project I linked to in first reply, there is a method called: PropertyPageClose within the cCustomPropertyDisplay class. With exception of the ConvertGUIDtoArray, DispCallFunc calls & constants used, it is pretty much a self-contained function.

    Edited: The DispCallFunc API calls are only required because no TLBs were used in that project. If you have a TLB that defines the IPropertyPage interface, you can call an interface method directly from that instead. And the ConvertGUIDtoArray function can be skipped if you use IIDFromString API or hard code your GUID, i.e.,
    Code:
    Dim aGUID(0 to 3) As Long
    ' fill in the four GUID parts
    Last edited by LaVolpe; Sep 9th, 2017 at 03:14 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  2. #42
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    3,146

    Re: How to setup a UserControl Property to Browse for a file

    Alright, here's an idea...

    I've just started playing with it, so it's not fleshed out very much. It's just a concept at this point.

    Let's say we create a new property that's a StdPicture type property (in some UC). Doing this will cause the ellipse button to appear for the property's name on the Properties Window.

    Now, through testing, I've found that the Get half of a property is always called when an ellipse button is clicked. It's also called many other times, but it always seems to be called when the ellipse button is clicked. Just as an FYI, the Set half isn't called until after a file is selected, which makes sense.

    Now, here's my idea. When the Get property is fired, I'm wondering if we could monitor (for some short length of time) to see if the "Load Picture" dialog appears. If it does, cancel it, and then take over the dialog process ourselves.

    Like I say, I haven't fleshed it out, and there may be some problems. For instance, I suspect that "Load Picture" dialog is modal. So I'm not sure how we're going to keep our monitoring code executing. Also, I haven't sorted how to put our own filename into a property that's declared as a StdPicture. But I'm thinking that both of these problems may be surmountable with a bit of ingenuity.

    I'm a bit short on time today, but I'll keep playing around with it.

    Best Regards,
    Elroy

  3. #43
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    @Elroy. Don't spend too much time on that idea. Even using subclassing like I did in my project, I was not able to stop VB from displaying the Picture/Font dialogs in order to substitute a custom one. Wasn't motivated to find a workaround. And if you did get it to work, I don't think there is any possibility of substituting the value "(None)" that would be displayed in the property sheet/window without subclassing.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #44
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    3,146

    Re: How to setup a UserControl Property to Browse for a file

    Yeah, I'm starting to lose motivation. I was playing around with spawning a "free thread" to monitor for the dialog window, but that was getting weird, especially when doing it in design mode of the IDE.

    Also, I have to keep reminding myself that all of this is just to make "my" life a bit prettier, and had nothing to do with the "end product". Therefore, not everything has to be absolutely perfect for me, so long as I can still get the things done that I'd like for the user.

    Take Care,
    Elroy

  5. #45

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2014
    Posts
    527

    Re: How to setup a UserControl Property to Browse for a file

    One last try, I could be wrong but it seems as if there is very little exposed to the programmer when inside of a PropertyPage Code Window.

    Is there any reliable way of getting the Handle to the PropertyPage Window while in the PropertyPage_Initialize procedure? Running within the IDE environment seems to foil most attempts with known methods.


    Duh! Never mind, just ignore me like my wife does.
    Last edited by stuck-n-past; Sep 9th, 2017 at 07:16 PM.

  6. #46

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2014
    Posts
    527

    Re: How to setup a UserControl Property to Browse for a file

    I'm driving myself crazy with this, Perhaps my last post shouldn't be ignored as the PropertyPage.hWnd property is the Handle to the 'Tab' not the actual Handle to the PropertyPage Window, and using GetWindow with an argument of 'Parent' doesn't work as it returns a 0. Using FindWindow with 'Property Pages' as the title also returns a zero.

    So I'm still in search of how to get the PropertyPage Window Handle, Thanks.

  7. #47
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    The top level property page is 2 levels up from PropertyPage.hWnd. The 1st level up is the 'frame' that contains the buttons at bottom of the page. GetParent() API does return a parent window, but it appears is only a temporary parent until the property page is ready to be sited. Then it gets a different parent. Even in the PropertyPageClose function I mentioned at top of this page, the comments I've included with the code indicates not to call it during the Initialize event. Have you tried the Paint event? Property page has to be 'finalized' by the time that event is triggered.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #48
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    Another option could be to take the time and create a professional looking file browser contained by the dialog. For example, when you first start VB, you get that dialog that offers opening a new, recent or existing project. The "Existing" tab is like a mini-Explorer. Looks really good, and wouldn't require any subclassing (unless desired). The property page's default Ok, Cancel, and Apply buttons would be intuitive enough I'd think. The Apply button can be left as permanently disabled.

    Just an idea.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #49

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2014
    Posts
    527

    Re: How to setup a UserControl Property to Browse for a file

    A world class headache sets in just with the thought of heading back to sift through the Sub-Classed solution for an Ellipse button. LaVolpe’s example posted above is simply an amazing piece of code. Actually it’s mind boggling to think that anybody has such a deep level of knowledge into the internal workings of VB’s IDE. It’s quite impressive to say the least.

    My efforts to find a ‘simpler’ solution have been thwarted with every new direction I’ve attempted. I had planned to throw in the towel much earlier, but with others having a similar interest to create an ellipse button I thought I’d try a few more crazy ideas. Unfortunately, VB’s PropertyPages are very limited and expose only the bare minimum to the programmer.

    From what I’ve seen and tested, LaVolpe’s example works extremely well and solves the problem. Short of that, using a dummy boolean property to trigger the loading of the Common Dialog is a simple alternative.

    Without an easy way to obtain a handle to the PropertyPages after being invoked, but before they are displayed, has killed the last couple of ideas I had.

    Thanks for all of the help.

  10. #50
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    I PM'd Fafalone asking if he'd consider creating a self-contained property page for just the purpose of selecting a file. Don't know if he'll jump on it, but maybe. He's very familiar with the Shell interfaces and think he could create such a property page with the help of a TLB -- kinda like replicating the "Existing" tab of VB's initial project selection dialog. If he does take on the task, I'd suspect we'd see a codebank submission in the coming weeks. May want to check back there occasionally.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #51
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,782

    Re: How to setup a UserControl Property to Browse for a file

    Is something like this what we're going for?



    This property page comes up when you hit the ellipsis button on a user control property.


    Edit:
    The benefit here is simplicity; there's no subclassing involved, and the event sink shouldn't be needed. It uses the IExplorerBrowser object and therefore my TLB, but that can be replaced with direct calls to the vtable if desired.

    I had mentioned a few other options to LaVolpe; I do have ListView/TreeView explorer browsers, like Brad Martinez's VBExplorer/EnumDeskVB, only done with all the more modern shell features implemented, and just about all of the options Explorer does, like extended columns, the ratings column with the stars, active drag&drop that shows images and highlights folders/zip on mouseover, etc, and any subset of those features could be done. But obviously that's far more involved and would definitely require subclassing.

    If the bars on the top/bottom are too much of an issue, it's possible to eliminate those, but that also eliminates the TreeView. We could put it back, but the only way to do that (presuming you want full Explorer prettiness and functionality) would require a different COM interface that *would* require a event sink (can a property page use Implements and use itself as a sink? otherwise that's a class module depend unless somebody knows how to do that fantastically complicated object virtualization thing, I don't), or a regular TreeView that does Explorer, which again I have but it uses extensive subclassing.

    Edit2
    I saw the note about TLB size... recall that that doesn't effect the compiled exe, since only what's used gets compiled in. I checked before and after adding the oleexp reference and browser interface... the exe increased from 32kb to 36kb, and half of that 4kb is probably just the code that calls it.

  12. #52
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,782

    Re: How to setup a UserControl Property to Browse for a file

    So I'm going to actively develop this... there's quite a bit of options we can apply to the view. Don't forget, since it's the standard Windows implementation, it implements the full range of interfaces-- lots of different options reside in lots of different interfaces.

    So let me know what behavior we're looking for... obviously the main object supports the big ones like setting it to Details view and navigating to any path we want, and the FOLDERFLAGS options like FWF_SINGLESEL; but we also have access to all the other options we get with IShellView, IShellView2, IShellView3, IFolderView, IFolderView2, and the interfaces they implement.

    Let me know what behavior it should have, odds are the option can be found somewhere in one of the interfaces it implements.



    For folder navigation I might make a dropdown tree list (but still keep the Explorer view for files-- removing the side nav tree and top/bottom bars), I'd be interested in feedback if it's worth it. The drawbacks are it's a lot of complicated code, using the ImageCombo doesn't reduce complexity that much, but would make it easier to customize since most people aren't comfortable with all API controls, at the expense of Unicode support; so my instinct would be to go all-API. Either way though, it adds the complexity of subclassing. Worth it?

    I'm actually pretty far along with the base code for it;

    Have the initial loading of the desktop/computer, then the ability to add any local file system path, with all parent folders automatically recursively added.
    So I want to put that on top of the file browser to control its paths, but to do that I am going to need to subclass the ComboBoxEx (need WM_COMMAND->CBN_SELCHANGE, so the box, not the parent or child cb); LaVolpe mentioned self-subclass with thunks, which would be great, but a little above my head.

    ++crap, just realized doing it this way also means needing the event sink for the explorer browser to catch navigation events

  13. #53
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,782

    Re: How to setup a UserControl Property to Browse for a file

    Ok guys so since I'm not that familiar with property pages yet, I developed on a form... we can convert this to a property page later, I just wanted to get the main ideas down. It seems to be working good, even with libraries. Maybe test with networks? But should be ok... it never manually deals with file names, just always deals with the absolute parsing name (which for virtual locations is just a GUID) or pidl, so it can handle navigating around the virtual objects like Computer and Library; this method even lets it keep subfolders of the User folder under the main entry, instead of opening up the Computer\C:\.

    Two major issues at this point; one is that it uses the Windows setting for whether to open in a new window or not. So if you have it set to open in a new window, a new window opens when you double click a folder (you can hold down Control to open in place, but since the control doesn't fire its events there's no easy way to know when to automatically trigger it through code). The second is needing to find a way to suppress a file opening externally when double-clicked.
    Might just have to go to a normal ListView... but that brings its own problems. Moving beyond just a basic display is a pretty big issue; to get all the big features, thumbnail view, tile view, drag/drop (especially active d/d), extended columns for details view, group mode... it'll be pushing 10,000 lines and take forever to duplicate in a standalone project (I do already have a program with a ListView that does all of that, but it's tightly interwoven with the rest of the app, which isn't a browser); drop support is impossible without COM classes if you want it to look like Explorer; extended columns would mean a new form to pick them, which might have to be done by API.

    Only depend is oleexp.tlb.


    I was thinking there might be ways around the event sink class; like a normal subclass that detects double clicks or enter, the just manually pulls the new location. But one step at a time. Just wanted to get the navigation right at first. Obviously will collapse the combo box defs too and remove that module for the PP.
    Attached Files Attached Files

  14. #54
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,752

    Re: How to setup a UserControl Property to Browse for a file

    Even if you get this to work you are left with nothing but ashes in your hands. File paths are almost never fixed, and may change between compiling and your first run. For example an elevated compile vs. a standard user run. At best it might possibly be safe to retrieve a relative path this way but not an absolute path.

    That isn't how properties work anyway. Even when there is an ellipsis button the dialog raised is for fetching some resource as the property's value, not to fetch a path String to use as a value.

    This entire enterprise is laughably ill-conceived.

  15. #55

  16. #56
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    Quote Originally Posted by fafalone View Post
    Yes I thought the point was to pick the resource to load directly on the property page, instead of spawning a common dialog to pick it.
    Yes. As for its purpose, think of the FileName property of the RTF control or even the Picture property of a form. Design-time retrieval of the file and applying it to the usercontrol. If you have no other property pages for your control, a file browser page is a good solution. What's displayed in the property window when in design time is up to the coder.

    Note: Do any of your solutions offer filters, i.e., *.txt; *.dat, etc? I'd think that would be a must-have.

    Quote Originally Posted by fafalone View Post
    Two major issues at this point; one is that it uses the Windows setting for whether to open in a new window or not. The second is needing to find a way to suppress a file opening externally when double-clicked.
    If double clicks can be trapped and discarded/treated as single clicks, that could be the workaround. Remember that a property page will have a "Ok", "Apply" button, as long as the selected item can be determined from the view. If context menus work, then someone could launch via the menu.

    As for the full options, I'd say that would be overkill for this purpose; a reasonable limitation.
    Last edited by LaVolpe; Sep 13th, 2017 at 08:11 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  17. #57
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,782

    Re: How to setup a UserControl Property to Browse for a file

    I was able to solve the double-click issue by subclassing the IShellView hWnd and cancelling the double-click notification (will have to add a file/folder check later, but that's no issue). Even better it can just be used to raise an event that a file has been picked like the common dialog does. Of course now we have a separate hWnd that needs to go to a separate wndproc.

    As to a filter... it's definitely supported, but with the caveat that I'm not yet sure if an alternative method I found will work-- it requires an interface (IShellFolderViewDual3) that doesn't seem VB friendly; it's not in my tlb yet. Without that alternative method, the documented method requires a class that implements IFolderFilter, the same filter method that I used with SHBrowseForFolder's BFFM_IUNKNOWN-- because as a Windows shell view object both the browse for folder window and IExplorerBrowser implement IFolderFilterSite.

    If we switch to a ListView it's obviously manually controlled... but I think that won't be neccessary. With the shell view subclass, I believe I can simply block automatic navigation, then call the manual navigate function. So that solves both behavioral issues.

  18. #58
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    If you can get it working as a "form" object even with minimal subclassing (combo/ IShellView hWnd), I can play with writing a simple thunk to keep this property page self-contained so it could be a simple drop-in for any coder.

    However, the filters would be a legitimate concern and not sure if your final sentence above was also addressing that. In a usercontrol scenario, if someone needs a FileName type property page, odds are the UC is coded for specific file type(s). And one wouldn't want the view cluttered with unusable files. If IFolderFilter will work, great. If subclassing a COM interface is involved, then we're kinda back to nasty vtable hacking.

    I know your project is a proof-of-concept. Might suggest using a proper "back" icon. We can get that from shell32.dll or elsewhere and 32bpp, drawing to a small borderless picbox (autoredraw=true) maybe?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  19. #59
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,782

    Re: How to setup a UserControl Property to Browse for a file

    Oh of course there'd be a pretty toolbar for the final version, I'll even drop in a proper view menu with all of those icons.

    The filter is the same deal as the event sink that's in the demo. A class module with Implements, but no SwapVtable call needed. IFolderFilter will absolutely 100% work, the problem is hauling around the class module that implements it.
    The IShellFolderViewDual3 interface and all its crazy depends (e.g. the Folder object from shell32, now an interface in the tlb.. ugh) compiled... but I'm running out of steam for the day so won't make it til tomorrow. (Edit: I'm talking about this interface because it has a .FilterView call that accepts a string filter, so if that works it means we have a filter method that doesn't require a separate class module)
    Incidentally with the subclass handling the double-click anyway, I might be able to eliminate the need for the event sink, since I'm doing manual nav anyway (though the manual navigate is asynch, so need another way to know when it completes... it could be several seconds for a large folder or powered down drive that needs to spin up).


    Edit:
    Sometimes I have the worst brain farts... I don't need a separate class module for the event sink, I can have my form have Implements and just set the event sink to Me.

    So the question is, can a Property Page do the same thing? I'm too tired to test it out today, by the time I wake up maybe somebody can enlighten us.

    On a form there's a problem; Err.Raise isn't working, so that means vtable swap; can't be done on a form, so propertysheet is probably out.



    Bottom line: It's entirely self-contained except for the following 3 items:

    -WndProc that the ComboBoxEx hWnd is subclassed to
    -WndProc that the IShellView hWnd is subclassed to
    -Filter proc from SwapVtable on IFolderFilter.ShouldShow (since Err.Raise didn't work; but the swapped one does)

    So before going any further, is it possible to relocate those three procedures onto the same form/propertypage using thunks?

    Attached is an updated version with maximum self-containment without thunks. Just the form and a single module with the functions for subclass/swapvtable. This update also implements the file-double-click block without affecting folders (by identifying if a file or folder was double clicked-- so we can raise a final selection event from this too), and has a button to apply a filter (set at *.bas and compared with PathMatchSpecW for now).
    Tomorrow I'll try that alternate filter; but there's no getting around the subclassing.

    Also... Unicode *seems* to be supported in the edit box without subclassing the edit hwnd; if someone with more experience with unicode can verify? And WM_NOTIFYFORMAT never seems to come up for anything besides the edit hwnd too; but the dropdown seems to be ok.

    Btw, that dropdown directory view is going to make a nice usercontrol too. Might do the file view too; completely replace the ugly old VB folder/file picker with a nice modern one. So no matter what something good is going to be coming out of this, besides just the raw code to create this file view.
    Attached Files Attached Files

  20. #60
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    I'll take a look-see when I get home. Out of curiosity, if you are using Implements on IFolderFilter, why are you trying to swap vTables?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  21. #61
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,556

    Re: How to setup a UserControl Property to Browse for a file

    Quote Originally Posted by LaVolpe View Post
    I'll take a look-see when I get home. Out of curiosity, if you are using Implements on IFolderFilter, why are you trying to swap vTables?
    he's saying that raising an error from IFolderFilter_ShouldShow isn't working.
    Not sure why
    Imagine what it would be like to set breakpoints in, or step through subclassing code;
    and then being able to hit stop/end/debug or continue, without crashing the IDE.

    VB6.tlb | Bulletproof Subclassing in the IDE

  22. #62
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    I see now, had to do a bit of research... VB error handler when Implementing TLB interfaces won't return S_False or any other error. Thus HRESULT 0 appears always returned. The vTable redirect ensures a non-zero return result to force item filtered.

    So, a thunk solution requires:
    1. Subclass handler for image combo (WM_NOTIFYFORMAT, WM_COMMAND|CBN_SELCHANGE, WM_DESTROY)
    2. Subclass handler for view double clicks (WM_NOTIFY|NM_DBLCLK & WM_DESTROY)
    3. Subclass handler for IFolderFilter.ShouldShow
    Last edited by LaVolpe; Sep 13th, 2017 at 05:33 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  23. #63
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    3,146

    Re: How to setup a UserControl Property to Browse for a file

    Say LaVolpe,

    I did cut your project down, isolating the code that gives you a property with an ellipse button.

    Pretty nifty what you did ... spoofing the Property Window into thinking that you're displaying a Property Page, and then taking over. I just cut it all down and used an InputBox when you click the ellipse button, and let that change the property.

    The code in the UC is quite brief, but the "behind-the-scenes" supporting code is still pretty involved.

    I thought about posting it, but then thought that you and Fafalone were probably on a different track. But I'll post it if you (or anyone) would like.

    What the heck, I'll just post it now...

    Remember that this is all an IDE design-time issue we're discussing. To see what I did in action, open Form1, select the cyan UC, open the Property Window, and then play with EllipseProp1 and EllipseProp2.

    The implemented class is cut-down to almost nothing. However, the cCustomPropertyDisplay class is still largely intact. I suspect it can be cut down, but that's some low-level stuff.

    Best Regards,
    Elroy
    Attached Files Attached Files

  24. #64
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    @Elroy. Take a look a bit later
    Edited: Yepper. The idea was to allow coder to display any modal window/dialog of their choosing. Still don't like the way I had to use SetRedraw on the desktop.

    @fafalone.
    So before going any further, is it possible to relocate those three procedures onto the same form/propertypage using thunks?
    I've used thunks in property pages before, nothing really different than using in a class form what I recall. But not likely to confirm/deny that until this weekend. Regarding your code working in a property page -- it does.

    For simple test, used the module as-is with minor modifications and placed the form's controls onto a property page. Graphically not perfect, but good 'nuf for a test

    1. The form's initialize/load and unload code transferred to property page's Initialize/Terminate events. Changed Me to PropertyPage when sizing controls.

    2. The module required a temp public variable: PPG as Object. Then anywhere you used Form1 as a prefix, changed to PPG

    3. The first statement in property page's Initialize event is: Set PPG = Me
    Last edited by LaVolpe; Sep 13th, 2017 at 06:16 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  25. #65
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,782

    Re: How to setup a UserControl Property to Browse for a file

    Quote Originally Posted by LaVolpe View Post
    I see now, had to do a bit of research... VB error handler when Implementing TLB interfaces won't return S_False or any other error. Thus HRESULT 0 appears always returned. The vTable redirect ensures a non-zero return result to force item filtered.

    So, a thunk solution requires:
    1. Subclass handler for image combo (WM_NOTIFYFORMAT, WM_COMMAND|CBN_SELCHANGE, WM_DESTROY)
    2. Subclass handler for view double clicks (WM_NOTIFY|NM_DBLCLK & WM_DESTROY)
    3. Subclass handler for IFolderFilter.ShouldShow
    Interestingly enough, Err.Raise to return S_FALSE (or other HRESULTS) *does* sometimes work in a class module, but only sometimes, it varies from interface to interface and function to function. That's why that code is still there under IFolderFilter_ShouldShow; in the SHBrowseForFolder project, it works without SwapVtable. But it stopped working when moved to a Form. It's worth testing whether a property page will work like a class module, or fail like a form. I'll check that out later.

  26. #66
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    Quote Originally Posted by fafalone View Post
    It's worth testing whether a property page will work like a class module, or fail like a form. I'll check that out later.
    Didn't. I first ran it without vtable swap and filter failed.

    Probably should've saved my test project ;(
    Selected view item and hit return to see what would happen... property page stopped responding & had to terminate. No thunks employed as of yet. Will need to look at order of what happens in terminate event I think. The "enter" key probably activated the property page OK button, but not sure. During my tests, I was just escaping from the property page.
    Last edited by LaVolpe; Sep 13th, 2017 at 06:51 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  27. #67
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    This may become more of a pain...

    While pEBrowse is alive the property page does not get a Terminate event. There is no Unload event in property pages. This means you can't clean up when the property page closes. You'd have to determine when the user hit ESC or OK button then release pEBrowse. Can't do it in the subclassed window's WM_DESTROY, because not sent until the Terminate event is called.

    P.S. I did get the property page to eventually terminate by opening it in design view.
    P.S.S. Still crashing when pressing Enter/Return on a selected view listitem.
    Edited: Up/Dn arrows are hosed. They are being sent to intrinsic controls on the page, not the listview which has focus. Maybe too much is going on behind the scenes with VB to make this a simple vs complex task?

    So much for an easy fix. Gonna need some thinking on this that doesn't require more advanced thunks; otherwise, might want to go with your first option back in post #51 if property page will terminate properly.
    Last edited by LaVolpe; Sep 13th, 2017 at 08:46 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  28. #68
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,782

    Re: How to setup a UserControl Property to Browse for a file

    The first post in this thread I made was of the browser alone on a property page; it wasn't interfering with the property page unloading then so I'm not sure how that got started.

    And I know it's best practice to clean up but if the object hosting the browser terminates without calling .Destroy, it's not that big a deal, I was working on it quite a while before I even remembered to call it on unload. Can't recall whether not calling .unadvise causes an issue tho.
    enter key needs to be intercepted and blocked in the shell view anyway, because it will launch the file. maybe that will help?
    Can try a few other things too; hosting it directly on the page instead of a frame comes to mind; and making sure the immediate parent hwnd is the same as other controls.
    I'm not entirely sure these issues wouldn't be present on a subclassed listview either though.


    I'll have to load it into a property page myself to see what's happening with the keypresses; possible to post the one you set up?

  29. #69

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2014
    Posts
    527

    Re: How to setup a UserControl Property to Browse for a file

    Yikes, some intense stuff going on here, sorry I don't have much to offer as I've exhausted my limited knowledge of PropertyPages.

    Hey LaVolpe, from reading post 67 looks as if you were working on terminating the PropertyPage which I was struggling with for sometime. I don't know if this would help or not but I was finally able to cleaning shutdown the pages using the following:


    Code:
           Call SendMessage(PPG_Handle, WM_SYSCOMMAND, SC_CLOSE, 0)

    A bit neurotic, like talking to oneself, but it works well.

  30. #70
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    Quote Originally Posted by fafalone View Post
    ... possible to post the one you set up?
    Here you go. Note to call the property page from the module, that's where the PPG variable comes to play. The page won't fire terminate until that variable is set to nothing. But even then, it still wouldn't terminate until pEBrowser was reset. Not included in the attached was a button I added that reset those, then the Terminate event triggered when I hit ESC or the OK/Cancel button.

    Open project, then add 2nd project and then add the usercontrol to the form in 2nd project.
    Attached Files Attached Files
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  31. #71

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2014
    Posts
    527

    Re: How to setup a UserControl Property to Browse for a file

    I just download and tried the project but I am getting an error after clicking on the Ellipse button


    Can't find DLL entry point SHCreateItemFromIDList in SHELL32.DLL
    After clicking on the OK from the MsgBox, the IDE sits there in the 'Run' state until I stop it.
    Last edited by stuck-n-past; Sep 13th, 2017 at 11:18 PM.

  32. #72
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    Quote Originally Posted by stuck-n-past View Post
    Can't find DLL entry point SHCreateItemFromIDList in SHELL32.DLL
    XP? That API function introduced with Vista per MSDN
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  33. #73
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,556

    Re: How to setup a UserControl Property to Browse for a file

    you must be on XP. According to MSDN SHCreateItemFromIDList is Vista+

    LaVolpe beat me to it!
    Imagine what it would be like to set breakpoints in, or step through subclassing code;
    and then being able to hit stop/end/debug or continue, without crashing the IDE.

    VB6.tlb | Bulletproof Subclassing in the IDE

  34. #74
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    859

    Re: How to setup a UserControl Property to Browse for a file

    DEX

    Talk about whispering .. sheesh ..

    Spoo

  35. #75
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,782

    Re: How to setup a UserControl Property to Browse for a file

    Yeah a lot of the APIs and interfaces are Vista+, particularly the explorer browser (bottom part). XP support would be a total re-write, need the bottom to be replicated with a ListView, and probably would have some issues with virtual objects.

    I've been out for a couple days so I'm just taking a look at your project now LaVolpe.


    Edit: So when I ran it, it closed when I clicked ok, no errors... when you say it wouldn't terminate, what were you seeing? I don't see any clues that it's still there; the page closed and can re-open, and close again, both with OK and Cancel.
    Nevermind I see it now, the Terminate event isn't being called.

    Edit2: It's not even the subclassing that's doing it. I ran it without setting either subclass, and the vtable swap was already off. And like I said, on my first test run I just reconfirmed that simply putting an IExplorerBrowser doesn't block terminate either.

    So where could the issue be coming from???
    It's even weirder that it doesn't seem to be triggering ANY events. The propertypage and both subclasses aren't even getting a lost focus event, nevermind any closing related WM_ messages.

    What if we set a timer in one of the subclasses (WM_TIMER), to check every few ms if we can find the window?

    Edit3: I tried getting rid of the ppg public variable, but that didn't help. Moved it in-function instead (passed ObjPtr(Me) as dwRefData in the subclass call, then vbaObjSetAddRef to get the object)



    PS- How should we store the icons for the back button, maybe view menu... if we're trying to avoid depends a res file or image file in the project folder are out; an imagelist control adds a dependency that we don't really need, so...



    And obviously we need to do something with the file we're picking, so here's the code to get the selection (the sample is single sel, but multi-sel is fully supported by the control, and the method to get the selection must be done with an array too, even if it's only one member)

    Code:
    Private Function GetSelectedFile(out_sFile As String, Optional bAllowFolder As Boolean = False) As Long
    Dim psia As IShellItemArray
    Dim penm As IEnumShellItems
    Dim Filename As String, lpName As Long
    Dim psiChild As IShellItem
    Dim psv As IShellView
    Dim i As Long
    Dim lAtr As SFGAO_Flags
    On Error GoTo e0
    pEBrowse.GetCurrentView IID_IShellView, psv
    If (psv Is Nothing) Then
        Debug.Print "Failed to created IShellView"
        Exit Function
    End If
    
    
    psv.GetItemObject SVGIO_SELECTION, IID_IShellItemArray, psia
    If (psia Is Nothing) = False Then
        psia.EnumItems penm
        If (penm Is Nothing) = False Then
            Do While (penm.Next(1&, psiChild, i) = NOERROR)
                If bAllowFolder = False Then
                    psiChild.GetAttributes SFGAO_FOLDER Or SFGAO_STREAM, lAtr
                    If (lAtr And SFGAO_FOLDER) = SFGAO_FOLDER Then
                        If (lAtr And SFGAO_STREAM) = 0 Then
                            'is a folder but not a zip folder
                            GetSelectedFile = -1
                            Exit Function
                        End If
                    End If
                End If
                
    '            psiChild.GetDisplayName SIGDN_NORMALDISPLAY, lpName
    '            Filename = LPWSTRtoStr(lpName)
                psiChild.GetDisplayName SIGDN_FILESYSPATH, lpName
                Filename = LPWSTRtoStr(lpName)
            Loop
        Else
            Debug.Print "Failed to enumerate selection."
        End If
    Else
        Debug.Print "Failed to get selection array."
    End If
    If Filename = "" Then
        GetSelectedFile = -2
    Else
        GetSelectedFile = 1
    End If
    out_sFile = Filename
    Exit Function
    e0:
        GetSelectedFile = -3
        Debug.Print "GetSelectedFile->Error: " & Err.Description & ", 0x" & Hex$(Err.Number)
    End Function
    For multi-select, just make Filename an array.

  36. #76
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,782

    Re: How to setup a UserControl Property to Browse for a file

    Ok I found the cause of the event not firing... it's the IExplorerBrowserEvents and IFolderFilter callback interfaces.

    When I commented it out, the terminate event fired. With folder filter, just being there was ok, but when I applied a filter then it also blocked terminate.

    It's the interface itself, not the subclassing, since I had previously tried disabling the subclassing.

    Going to try to figure out a way around this...

    --
    Update 1
    Going back to an external class module doesn't solve the issue. And getting around those events is harder than you think... .BrowseToObject/IDList is async, it returns immediately, so you can't just subclass right after, because the old view isn't always destroyed fast enough. Finding out when navigation completes, for that and its own function, is an ever harder problem.


    Sadly I think LaVolpe might be right about needing to move to a ListView

    We don't really need thumbnails, extended columns, and drag/drop though right? Group view...ehh.. I suppose.

    Update 2

    The ListView (shown here) should work out better; will just need 2 3* standard WndProcs (the existing ComboBoxEx one, and one for the new ListView to handle doubleclick/return). Went with API-created.. I know it's more complex but to use the system imagelist the VB one would have to be subclassed anyway.
    It's just a question of how far to go implementing Explorer features. I've got code for all the things mentioned above, but cutting it out of my bigger project is just barely quicker than re-writing from scratch.
    It might look good in that pic but I haven't even done navigation and sorting yet, so still a ways to go. *Sorting..grrr..that needs a callback


    This has got to be the most work ever done to avoid a single extra click (putting a button on the property page that launches a common dialog). Thanks for getting me obsessed with it LaVolpe

  37. #77
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,782

    Re: How to setup a UserControl Property to Browse for a file

    If anyone else wants to play around with what we're working on, here's the property page version that LaVolpe posted, with the IExplorerBrowser replaced by a ListView.
    Navigation is working now, but that's about it so far. Still need to implement other views (large/small icon, tiles, etc), sorting, and whatever else is worthwhile. Basic filter support is there, still with PathMatchSpecW, but no more IFolderFilter; just checking the name before adding it to the LV.
    Only depend is oleexp.tlb; and it's got the full lv/header def module while the listview is being developed; once we have the final set the defs needed will be moved over and the module removed, like what was done with the combo.

    Update
    Since sorting involves callbacks, wanted to post that right away (v2)
    Traded some sort speed for convenience, re-wrote sorting system to use only 1 sort callback proc instead of one for each type, disabled date created column for space considerations (if you want it back the code is still all there-just uncomment it), and stopped random crashes by freeing imagelists in terminate (v3)
    Attached Files Attached Files

  38. #78
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    859

    Re: How to setup a UserControl Property to Browse for a file

    fafalone

    Great stuff ..

    But a suggestion ..

    The font color you tend towards, namely lite grey, is kinda hard to read.
    Maybe go with bold or red or highlight.

    Spoo

  39. #79
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,648

    Re: How to setup a UserControl Property to Browse for a file

    Quote Originally Posted by fafalone
    This has got to be the most work ever done to avoid a single extra click (putting a button on the property page that launches a common dialog). Thanks for getting me obsessed with it LaVolpe
    You're welcome . I basically said the same thing about the project I linked to in post #2. A lot of work for little gain. But then again, many of us add more for a better appearance.

    I'll be looking at your latest update a bit later and will post back suggestions, if any.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  40. #80
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,782

    Re: How to setup a UserControl Property to Browse for a file

    Quote Originally Posted by Spooman View Post
    fafalone

    Great stuff ..

    But a suggestion ..

    The font color you tend towards, namely lite grey, is kinda hard to read.
    Maybe go with bold or red or highlight.

    Spoo
    That's the point really... there's no strikethrough on this forum so I use light gray for stuff that would otherwise be crossed out because it's no longer applicable, and just there for archive/continuity purposes. Emphasizing it in bold or bright would be the opposite effect

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.