Announcement

Collapse
No announcement yet.

Filenames that are TOO long for a LABEL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Filenames that are TOO long for a LABEL

    We've all seen how Microsoft shortens filenames for display while processing/copying files???

    Turns this
    C:\WINDOWS\Application Data\Microsoft\Address Book\tngbbs.exe

    Into this:

    C:\WINDOWS\....\tngbbs.exe

    Is there an api for this or is it just tricky footwork?

    I may have filenames that run across labels, am considering just displaying the DIR$ of it.

    Anybody got a good suggestion for beautifying a label that can't be say, over 125?


    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    DrawText, with %DT_PATH_ELLIPSIS does this automatically for you.
    I even think you can use %DT_MODIFYSTRING to get the given string
    changed. Very handy for this purpose..

    To show you what I mean (you may have to set rc.nLeft to a value
    that makes it draw outside of the dialog..
    Code:
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Create dialog and controls, etc
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN () AS LONG
      LOCAL hDlg AS LONG, hDc AS LONG, rc AS RECT, zText AS ASCIIZ * %MAX_PATH
     
      DIALOG NEW 0, "DrawText test ",,, 130, 40, %WS_SYSMENU, 0 TO hDlg
      CONTROL ADD LABEL, hDlg, 10, "", 4, 4, 120, 12, %WS_BORDER
      zText = "c:\VeryLong\VeryLong\VeryLong\VeryLong\VeryLong\VeryLong\VeryLong\Path.txt"
     
      GetClientRect GetDlgItem(hDlg, 10), rc
      hDc = GetDC(hDlg)
      CALL DrawText(hDC, zText, LEN(zText), rc, %DT_PATH_ELLIPSIS OR %DT_MODIFYSTRING)
      ReleaseDc hDlg, hDc
     
      CONTROL SET TEXT hDlg, 10, zText
     
      DIALOG SHOW MODAL hDlg CALL DlgProc
     
    END FUNCTION
    ------------------


    [This message has been edited by Borje Hagsten (edited February 05, 2001).]

    Comment


    • #3
      Code:
      #Compile EXE
      Declare Function PathSetDlgItemPath Lib "Shlwapi.dll" _
        Alias "PathSetDlgItemPathA"( Byval hDlg&, _     'handle to Dialog
                                    Byval wID&, _      'ControlId
                                    pszPath as Asciiz)As Long 'Ptr to textbuffer
      
      Function PBMain()as long
      Local hDlg&, Path$
      
        DIALOG NEW 0, "Testing PathSetDlgItemPath... ",,, 230, 40 TO hDlg&
        CONTROL ADD LABEL, hDlg&, 10, "", 4, 4, 220, 12 
        Dialog Show ModeLess hDlg&
        Path$ = "C:\WINDOWS\FILENAME.EXT"
        Call PathSetDlgItemPath(hDlg&,10,ByVal StrPtr(Path$))
        Dialog DoEvents
        Sleep 2000
        Path$ = "C:\WINDOWS\SYSTEM32\FILENAME.EXT"
        Call PathSetDlgItemPath(hDlg&,10,ByVal StrPtr(Path$))
        Dialog DoEvents
        Sleep 2000
        Path$ = "C:\WINDOWS\SYSTEM32\FOLDER1\FILENAME.EXT"
        Call PathSetDlgItemPath(hDlg&,10,ByVal StrPtr(Path$))
        Dialog DoEvents
        Sleep 2000
        Path$ = "C:\WINDOWS\SYSTEM32\FOLDER1\FOLDER2\FILENAME.EXT"
        Call PathSetDlgItemPath(hDlg&,10,ByVal StrPtr(Path$))
        Dialog DoEvents
        Sleep 2000
        Path$ = "C:\WINDOWS\SYSTEM32\FOLDER1\FOLDER2\FOLDER3\FILENAME.EXT"
        Call PathSetDlgItemPath(hDlg&,10,ByVal StrPtr(Path$))
        Dialog DoEvents
        Sleep 5000
        Dialog End hDlg&
      End Function

      ------------------
      Fred
      mailto:[email protected][email protected]</A>
      http://www.oxenby.se



      [This message has been edited by Fred Oxenby (edited February 05, 2001).]
      Fred
      mailto:[email protected][email protected]</A>
      http://www.oxenby.se

      Comment


      • #4
        Preciate all the suggestions, where DO you dig up these API's??

        This one did it the fastest and easiest since the label was already in place:

        Code:
        For lLoop = 1 to g_FileIndex
            lResult = PathSetDlgItemPath(pDlg,%FILECOPYLABEL2,ByVal StrPtr(g_Files(lLoop)))
            compress, encrypt etc
        Next
        Thanks!

        Scott

        ------------------
        Scott
        mailto:[email protected][email protected]</A>
        Scott Turchin
        MCSE, MCP+I
        http://www.tngbbs.com
        ----------------------
        True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

        Comment


        • #5
          Freds example is excellent, but for the purposes of clarity, it has to be pointed out that the DIALOG DOEVENTS handling is sadly lacking... there are not enough calls to DIALOG DOEVENTS for the dialog to display correctly at all times. I point this out because this is a common problem with modeless dialogs.

          For example, add the style %SS_SUNKEN OR %WS_BORDER to the LABEL control and watch what happens. Now cover & uncover the dialog with another window and it does not update correctly.

          A "proper" message pump strategy would sort that out completely. Essentially, the message pump should be running for the duration of the dialog.

          In summary, as long as this example is treated purely as an example of the specific API, and not one of GUI programming, everyone will be OK.

          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            Which is why I prefer the other method. Even if a tiny bit slower,
            all redrawing is handled by the control itself..


            ------------------

            Comment


            • #7
              This will truncate a path to a given number of characters
              Note that MaxNoOfChar is including trailing NULL
              Note also that dwFlags are 'reserved For future use'
              Note that you Do Not Get an example.....

              Code:
                 
              Declare Function PathCompactPathEx Lib "Shlwapi.dll" _
                        Alias "PathCompactPathExA"(ReturnedString As Asciiz, _ 
                                                   StringToTruncate As Asciiz, _
                                                   ByVal MaxNoOfChar As long, _ 
                                                   Byval dwFlags As DWord) As Long
                 
              
              Returns %TRUE if successful, or %FALSE otherwise.
              ------------------
              Fred
              mailto:[email protected][email protected]</A>
              http://www.oxenby.se



              [This message has been edited by Fred Oxenby (edited February 06, 2001).]
              Fred
              mailto:[email protected][email protected]</A>
              http://www.oxenby.se

              Comment


              • #8
                In this example yes, but in the "Live" code it actually works good!
                (Modal dialog also)


                Scott

                ------------------
                Scott
                mailto:[email protected][email protected]</A>
                Scott Turchin
                MCSE, MCP+I
                http://www.tngbbs.com
                ----------------------
                True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                Comment


                • #9
                  Apart from Lance's comment (I don't use it in a modeless dlg): Fred's example works perfectly - "like a charm", as some of you folks use to say.

                  ------------------
                  mailto:[email protected][email protected]</A>
                  www.basicguru.com/zijlema/

                  Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
                  http://zijlema.basicguru.eu
                  *** Opinions expressed here are not necessarily untrue ***

                  Comment


                  • #10
                    As an alternative to using the elipses, I insert a blank space at
                    appropriatly spaced intervals (preferably following a slash), then
                    set the label to a multiline height.

                    ------------------
                    Thanks,

                    John Kovacich
                    Thanks,

                    John Kovacich
                    Ivory Tower Software

                    Comment


                    • #11
                      Depending on the version of windows you are using you can try the new styles for labels.
                      For example,
                      SS_LEFT OR SS_PATHELLIPSIS

                      ------------------
                      Dominic Mitchell
                      Dominic Mitchell
                      Phoenix Visual Designer
                      http://www.phnxthunder.com

                      Comment


                      • #12
                        CONTROL ADD LABEL says if you use %SS_PATHELLIPSIS it will "Replace
                        the file path portion of the given string with ellipses as needed
                        to fit the result in the specified rectangle.

                        Well if I send a string to the label that is longer than the
                        xx& value of the label, the path either wraps around or is truncated
                        by the xx& value and does not show ellipsis. What to do????

                        ------------------
                        Well, I answered my own question. I searched the web since my API
                        help file does not list any of the SS_ constants and found
                        the two ellipsis constants work only for NT or 2000. I wish the PB
                        doc's stated these items.

                        [This message has been edited by Barry Erick (edited July 29, 2001).]
                        Barry

                        Comment


                        • #13
                          This works very nicely:

                          lResult = PathSetDlgItemPath(CbHndl,%IDLABEL6,ByVal StrPtr(YourString$))


                          ------------------
                          Scott
                          Scott Turchin
                          MCSE, MCP+I
                          http://www.tngbbs.com
                          ----------------------
                          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                          Comment


                          • #14
                            One caution about using SHWLAPI.DLL:

                            This DLL is not installed by default on NT or on Win95 or 98 (ist edidition), and is only installable if the user installes Internet Explorer. (i.e., there is no such thing a "download the DLL from the MS web site).

                            (I got hurt by this.)

                            Note: there is an EXACT function for this purpose in SHWLAPI.DLL: "PathCompactPath[Ex]").

                            DT_PATH_ELLIPSIS is much safer and more generic.

                            MCM
                            Michael Mattias
                            Tal Systems (retired)
                            Port Washington WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              Here is what I did since the label is not in the dialog when that
                              dialog is created. I used the example in here from Borje with the
                              Call SendText items, but made a dummy window that I never did
                              a 'Dialog Show' whatever. I used this to convert the path passed
                              to the call and returned and then display it in the window I want.
                              If I didn't I get two displays on the screen. Anyway, I have it
                              worked out now. I duplicate the label, except for the hdlg, so it has
                              the same size as the one I will put it into. I'll post this method
                              as soon as I make a smaller version of it, as my current one
                              is in a big program.
                              --- Barry


                              ------------------




                              [This message has been edited by Barry Erick (edited July 30, 2001).]
                              Barry

                              Comment

                              Working...
                              X