Page 2 of 2 FirstFirst 12
Results 41 to 48 of 48

Thread: [VB6] Using the new IFileDialog interface for customizable Open/Save (TLB, Vista+)

  1. #41

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,819

    Re: [VB6] Using the new IFileDialog interface for customizable Open/Save (TLB, Vista+

    The redirects complicate it a bit; otherwise you could just use RaiseEvent.

    But you could do something like this in the events class:

    Code:
    Private mForm As Form
    
    Public Sub SetForm(ByVal obj As Form)
    Set mForm = obj
    End Sub
    Public Function GetForm() As Form
    Set GetForm = mForm
    End Function
    Public Sub DoThing()
    mForm.eventmethod
    End Sub
    Then you could assign that class instance a form, you could call DoThing from within the class, then from redirects you could add

    Code:
    Sub CallFormMethod(oClass As clsFileEvents)
    Dim f As Form
    Set f = oClass.GetForm
    f.eventmethod
    End Sub
    Then both types of events would call Sub eventmethod on the specific form;

    Code:
    Public Sub eventmethod()
    Debug.Print "called event"
    End Sub
    
    Private Sub Command1_Click()
    Dim c As clsFileEvents
    Set c = New clsFileEvents
     
    c.SetForm Form1
    c.DoThing
    CallFormMethod c

  2. #42
    Addicted Member
    Join Date
    Jun 2010
    Posts
    205

    Re: [VB6] Using the new IFileDialog interface for customizable Open/Save (TLB, Vista+

    Hmm, it looks a bit complicated but I will study it. Thing is, as it would be wasteful to repeat all the dialog code in every form, I was inspired by Dragokas fork and have wrapped it all in a class with a Public method for each dialog. Works very well, just have to figure out how I can get to the responses from the custom controls inside the class to keep it all smoothly contained and decoupled.

    It feels "wrong" to deal with this in the form as the actions doesn't really happen in that window. but in the dialog.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  3. #43

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,819

    Re: [VB6] Using the new IFileDialog interface for customizable Open/Save (TLB, Vista+

    You don't need to use a form at all; you can do whatever you want with the notifications. Including handling them in a class wrapping the rest; just implement the events interface too and pass Me to .Advise

  4. #44
    Addicted Member
    Join Date
    Jun 2010
    Posts
    205

    Re: [VB6] Using the new IFileDialog interface for customizable Open/Save (TLB, Vista+

    I'm probably stupid or something, maybe more something ;-) but I don't quite understand some stuff here. I looked in the object browser trying to figure it out but e.g. what exactly happens when an object/class is passed to .Advice, and what about the Cookie?

    BTW are these interfaces MS stuff so there are docs somewhere to figure it out? Guess I need a nights sleep to look at it with fresh eyes.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  5. #45

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,819

    Re: [VB6] Using the new IFileDialog interface for customizable Open/Save (TLB, Vista+

    These are Windows built in things yes; there's documentation for the interfaces but not VB6-specific guidelines on various implementation strategies.

    What you pass to advise in VB6 is any class that has "Implements IFileDialogEvents" and associated code; you can do that in the same class as everything else. dwCookie is just a Long variable you use to store a value... you can declare it at class level or as Public in a module.

  6. #46
    Addicted Member
    Join Date
    Jun 2010
    Posts
    205

    Re: [VB6] Using the new IFileDialog interface for customizable Open/Save (TLB, Vista+

    Ok thanks for replies and made some progress. Not sure this is the optimal way or even recommended, but adding public events to the cFileDialogEvents class, then declared the class Private WithEvents in my own FileDialog class (where I do all your stuff) seems to work at least.

    I was thinking of the possibility to have event handlers into the form as well, without hard coding the form names as in your example project, but not sure that's an easy thing to achieve. A better solution is probably to add one or more properties to the dialog class, which can be read before the dialog class is killed. Any action taken there typically would happen after the dialog has closed anyway e.g. loading the document file just saved.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  7. #47

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,819

    Re: [VB6] Using the new IFileDialog interface for customizable Open/Save (TLB, Vista+

    In your own FileDialog class, you can add all the stuff from cFileDialogEvents and just pass Me to the Advise methods. You don't strictly need 2 classes was my point. Whether like this or like my other idea.

    Then you could use the this argument in the .bas redirects to call methods in the right class instance.

  8. #48
    Addicted Member
    Join Date
    Jun 2010
    Posts
    205

    Re: [VB6] Using the new IFileDialog interface for customizable Open/Save (TLB, Vista+

    Ahh get it now or just slowly starts to wrap my head around this Shell interfaces stuff ;-) Your work here is just massive and amazing, thank you. I was trying something else as well, but without success and will comment in that example thread specifically.

    Anyway, previously I was using Lavolpe's old CmnDialogEx class which comes with a weight of 244k, which dropped to about 15k with this solution and maybe more if I join the 2 classes and streamline it with what I use and drop the rest. Well, size doesn't matter that much but a sign of progress when you can cut off some bloat ;-) Lavolpe's work in good as well, but this is the future, simply.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

Page 2 of 2 FirstFirst 12

Posting Permissions

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



Click Here to Expand Forum to Full Width