2

I have strange behaviour of CFileDialog once it is opened. The offered file name looks like it has been truncated, so that only last n characters are visible:

image http://ves.fijmovi.com/cpp/CFileDialog_1.jpg

As soon as I click on space for name, I get to see the whole file name:

image http://ves.fijmovi.com/cpp/CFileDialog_2.jpg

So it is not truly truncated, just the beginning position of shown string is not from the start. The complete file name is in this case 36 characters long and part of the string which I get upon opening of dialog is from the 21st character to the last. I tested with some other files which are longer and they also appear truncated, but not from the 21st character, but some other one. I don't see any sense in this.

This piece of code has been several years old:

// Ask user for name and location of the ZIP
CString  OfferName = DEFAULT_ZIPFILE_NAME;
CString  File_Mask = GetString (IDS_ZIP_SELECT);

CFileDialog fileDlg (TRUE, _T("zip"), OfferName,
                     OFN_EXPLORER | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_ENABLESIZING,
                     File_Mask, pStateThread->GetThreadWindow());

CString strTitleName     = GetString (IDS_ARCHIVE_CAPTION);
fileDlg.m_ofn.lpstrTitle = strTitleName;

CString  Default_Dir = pConfig->GetTricUserKey (_T("TricSupportDir"));
fileDlg.m_ofn.lpstrInitialDir = Default_Dir;

if (fileDlg.DoModal () != IDOK) {
        //..
}

Should I use some special flag for m_ofn? I've read article on MSN about OPENFILENAME structure but I see nothing worth adding to existing flags.

Any thoughts on what might be going on?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
ves
  • 21
  • 4
  • Looks like the entry field is simply scrolling to the right when displaying a long name, and then when you click on it, it scrolls back to the left. That has nothing to do with truncating data. – Remy Lebeau Aug 08 '14 at 19:05
  • If this would be ok, try disabling the "Vista style" file dialog (pass `FALSE` as the optional final parameter to the constructor). It sounds like the older version may not have this issue. – dlf Aug 08 '14 at 19:24
  • 1
    Or try setting the initial dialog size to something big instead of leaving it unspecified. It may be that the order of steps is: Create a narrow dialog. Populate the initial filename. Textbox is too narrow for the full filename, so scroll it right. Oh; we're supposed to autosize this thing, so let's do that now. Now the textbox is wide enough, but it's already been scrolled. – dlf Aug 08 '14 at 19:27
  • Oops; I misunderstood the meaning of the `dwSize` argument (it isn't window size). I see no way to set the initial window size directly (without deriving your own class?), but I still suspect something like what I described is what's happening. – dlf Aug 08 '14 at 19:56
  • @dlf Thanks. I've already tried to disable Vista style, and it did not help. I see your other thought..hmm to me it looks like initial dialog is big enough, but maybe I try to do what you say, derive my own class and figure out there something – ves Aug 08 '14 at 20:04
  • @RemyLebeau Thanks, that is why I said that it only appears as it is truncated. English is not my first language and at that moment I couldn't come out with better words to explain. – ves Aug 08 '14 at 20:05

1 Answers1

0

It happens in all software for me that uses the open file dialog. I think it's just a peculiarity of recent-ish incarnations of that dialog.

Roel
  • 19,338
  • 6
  • 61
  • 90
  • 1
    I notice that your answer was in 2014 and I still find the same behaviour six years later. Did anyone get anywhere with this? Did anyone raise it as a bug with Microsoft team? – Andrew Truckle Oct 19 '20 at 13:15
  • 1
    I reported it: https://developercommunity.visualstudio.com/content/problem/1225634/problem-with-using-the-cfiledialog-class.html – Andrew Truckle Oct 19 '20 at 13:27