9 Replies Latest reply on Dec 5, 2006 4:49 PM by Newsgroup_User

    Buddy API: WinHandle from file path?

    Applied CD Level 1
      I’d like to close the directory window containing file ABC.ini. I’ve got the full path to my ini file but the window title/caption may have been changed by the user (it’s a flash drive so the media is r/w). Anyone know an easy way to close this window?
        • 1. Re: Buddy API: WinHandle from file path?
          Level 7
          On Mon, 04 Dec 2006 21:19:14 GMT, Applied CD posted in
          macromedia.director.lingo:

          > I?d like to close the directory window containing file ABC.ini. I?ve got
          > the full path to my ini file but the window title/caption may have been
          > changed by the user (it?s a flash drive so the media is r/w). Anyone
          > know an easy way to close this window?

          It may depend on which program was used to open the file. I just ran a test
          with baWindowList where I had start.ini opened in UltraEdit (my default .ini
          app) and in Notepad. It returned both window handles:

          put baWindowList("","start.ini",0)
          -- [76743226, 67646]

          Now, when I opened a another file in UE (uses tabbed document interface) and
          had it as the front-most tab, I only got one result.

          -- [76743226]

          So if the user has done something similar, this method won't work all that
          well.

          However, if you're using Buddy API to open that file, you can get the window
          handle via other means. Possibly using baWaitForWindow in conjunction with
          baRunProgram or some combination. I did something like this in the distant
          past, so I can't give details, but it can be done.

          baRunProgram with the wait state set to true
          baWaitForWindow to get the WinHandle

          If that doesn't quite get it, dig around in the other Window functions.


          --
          Mark A. Boyd
          Keep-On-Learnin' :)
          • 2. Re: Buddy API: WinHandle from file path?
            Level 7
            On Mon, 04 Dec 2006 21:55:24 GMT, Mark A. Boyd posted in
            macromedia.director.lingo:

            >> I?d like to close the directory window containing file ABC.ini. I?ve got

            Ack!

            Upon re-reading this, I think you're asking about Windows Explorer or
            whatever the Mac equivanent is (finder?).

            Again, if using baRunProgram and baWaitForWindow to open that window, it
            might work. However, if my guess above is correct, I wouldn't mess with it at
            all. Leave it up to the user to determine when they're done with file
            management.

            Just my $.02


            --
            Mark A. Boyd
            Keep-On-Learnin' :)
            • 3. Re: Buddy API: WinHandle from file path?
              Applied CD Level 1
              Thanks Mark, but yeah, it’s a directory window so it would be owned by Windows Explorer. Actually I’m not really closing it on the user, Windows automatically opens the root directory when the flash media is mounted, I would like to close it to reduce desktop clutter when my autorun app starts*. My app has a button to open the drive or the user can do it on their own, I just don’t want Windows opening the directory automatically before my app has run.

              *Actually, this is a bit of an understatement. I'm using a special type of flash media that has two mountable partitions, a conventional r/w storage partition and a "virtual CD-ROM" partition that is r/o. My app launches from the CD partition however there is a chance the storage partition will mount second and end up on top of my app ... I could probably use Buddy API to just keep pushing my app forward but even then I don't want to give users access to the storage partition until my app has made it available.
              • 4. Re: Buddy API: WinHandle from file path?
                Level 7
                This is going to be tedious, but I think it can work.

                Somehow, you are going to need to know the drive letter of the drive you
                are trying to close.

                Once you know which drive letter it is, you can use baFindWindow to get
                the handle of the one that one. To get the handle of a Windows Explorer
                window that has the g:\ drive open, for instance, you could do this:

                put baFindWindow("CabinetWClass","g:\")
                -- 526232

                Or, to make it all in one line, this will close the 1st Windows Explorer
                window it can find that has "g:\" in the title. Since it is a freshly
                mounted drive, there should not be more than one open at this time.

                baCloseWindow(baFindWindow("CabinetWClass","g:\"))


                So the tricky bit is finding out the drive letter.

                The next step depends on how your drive appears to Windows. In a test
                environment, mount the drives and find out what drive letter it is on
                your computer. In my example I assume it is the g:\ drive. Do this:

                put baDiskInfo(,"g","type")
                put baDiskInfo(,"g","name")
                put baDiskInfo(,"g","number")
                put baDiskInfo(,"g","size")

                Hopefully it comes up with something unique and controllable. If you
                know you can always make the volume name something distinct, then you
                are golden. If you can guarantee that all the drives will go out and
                they will be named "Whoopiee", then you can find the drive that has that
                name easily:

                repeat with i in ["a","b","c","d","e","f","g"] --make this go up until z
                if baDiskInfo(i,"name")="Whoopiee" then
                baCloseWindow(baFindWindow("CabinetWClass",i&":\"))
                exit repeat
                end if
                end repeat

                If you can't guarantee the name of the partition, perhaps you can use
                the free space or size options? Since it is read only, it should be
                standardized.

                If all else fails, you can try using baFindNextFile to search for that
                ABC.ini you referred to, but that may take way too long.
                • 5. Re: Buddy API: WinHandle from file path?
                  Level 7
                  On Mon, 04 Dec 2006 23:29:45 GMT, Mike Blaustein posted in
                  macromedia.director.lingo:

                  > So the tricky bit is finding out the drive letter.

                  :-)

                  theDrive = (the moviePath).char[1..3]
                  baCloseWindow(baFindWindow("CabinetWClass",theDrive))


                  --
                  Mark A. Boyd
                  Keep-On-Learnin' :)
                  • 6. Re: Buddy API: WinHandle from file path?
                    Level 7
                    That only works if the projector is running off that partition. He had
                    mentioned that the drive has 2 partitions, so if the exe is on the other
                    partition, you'll need to use the long version. If not, then yours
                    certainly sames some time and typing!
                    • 7. Re: Buddy API: WinHandle from file path?
                      Applied CD Level 1
                      Thanks all,

                      I’ve got the drive letter, so baCloseWindow(baFindWindow("CabinetWClass",myDriveLetter)) should be the solution.

                      For anyone that’s curious, the exe runs from the r/o CD partition, the ini file is a hidden file on the root level of the r/w storage partition. I’ve included my code for finding the ini file (and hence, the drive letter) below but it’s not rocket science. I know it’s possible that even though hidden, the end user may have deleted the ini file, my app uses a fall back plan if the ini file can’t be located (getIniPath returns “”)

                      • 9. Re: Buddy API: WinHandle from file path?
                        Level 7
                        On Tue, 05 Dec 2006 01:14:04 GMT, Mike Blaustein posted in
                        macromedia.director.lingo:

                        > That only works if the projector is running off that partition. He had
                        > mentioned that the drive has 2 partitions, so if the exe is on the other
                        > partition, you'll need to use the long version.

                        Right, you are.


                        --
                        Mark A. Boyd
                        Keep-On-Learnin' :)