Jump to content
  • Advertisement
Sign in to follow this  
Juliean

OPENFILENAME lpstrFilter won't display any files

This topic is 2072 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

when trying to specifiy filters for my windows based file open dialog, I've encountered the problem that whathever filter I set, no files are being shown. Unless I specifiy no filter, where all files are shown like normal. The code is rather simple:

        FileDialog::FileDialog(DialogType type, const std::wstring& stTitle, LPCWSTR lpFilter): Widget(0, 0, 0, 0), m_pFileBuffer(nullptr), m_stTitle(stTitle), m_stFilter(lpFilter)
        {
            m_pFileBuffer = new wchar_t[1024];
            memset(m_pFileBuffer, 0, 1024);

            m_pNameBuffer = new wchar_t[1024];
            memset(m_pNameBuffer, 0, 1024);
            
            memset(&m_ofn, 0, sizeof(m_ofn));
            m_ofn.lStructSize = sizeof(m_ofn);
            m_ofn.lpstrFile = m_pFileBuffer;
            m_ofn.lpstrFileTitle = m_pNameBuffer;
            m_ofn.nMaxFileTitle = 1024;
            m_ofn.nMaxFile = 1024;
            m_ofn.lpstrFilter = m_stFilter.c_str();
			m_ofn.nFilterIndex = !m_stFilter.empty();
            m_ofn.lpstrTitle = m_stTitle.c_str();

			if (type == DialogType::OPEN)
				m_ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
			else
				m_ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
        }

So I'm storing the filter thats being passed in an std::wstring. Then I set the c_str() of this as the lpstrFilter. I've tried differnt filters and browsed through different directories making sure that fitting files are present:

L"Acclimate Project files(.acp)\0*.*\0" // my custom fromat I want to support, the first one I tried and lead me to belive it only didn't work for this format first
L"All\0*.*\0Text\0*.TXT\0" // only displays rubbish for the second selection (a filled out dot), and doesn't show any files for neigther of those two selections => I'm not sure if the display problem is related here, or just something else.

Any ideas what I could've missed?

 

Share this post


Link to post
Share on other sites
Advertisement

I suspect that std::string is cutting your text short at the first \0.

 

A std::vector<wchar_t> or a plain old const wchar_t* might be a better option.

Edited by Adam_42

Share this post


Link to post
Share on other sites
By the way, the format terminates with double \0 characters, not just one:
 
L"Acclimate Project files(.acp)\0*.*\0\0"
L"All\0*.*\0Text\0*.TXT\0\0"
 
 
L. Spiro

Share this post


Link to post
Share on other sites


I suspect that std::string is cutting your text short at the first \0.



A std::vector or a plain old const wchar_t* might be a better option.

 

Ah, yes, that appeared to be the problem. I was already using wchar_t buffers for the others (title & file), so it isn't that hard to use here. However, I suppose there is no other option than to manually loop through the passed LPCWSTR lpFilter and check for the double \0\0 for copying the content of the buffer, since strlen & memcpy will ultimately also clamp the buffer to the first \0... or is there a simpler alternative? (I'm going to have a specific structure for setting the filters at some point anyway, but just so I know...).

 


By the way, the format terminates with double \0 characters, not just one:

L"Acclimate Project files(.acp)\0*.*\0\0"
L"All\0*.*\0Text\0*.TXT\0\0"


L. Spiro

 

I was aware of that, however I supposed that std::wstring would automatically add a \0 to the end of the string, and didn't realize it would instead cut the string of at the first \0 that there is :/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!