Subclassing CFileDialog woes

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im attempting to subclass or derive the CFileDialog. I initially attempted to hook it by using the OFN_EXPLORER | OFN_ENABLEHOOK flags. This caused a really annoying ASSERT fail inside the actual MFC code, so I stepped down from that and continued with handling messages. <br/> <br/> The reason I am trying to derive the CFileDialog is because Im experiencing strange behaviour under Windows Vista and Windows 7 when using the CFileDialog in an EXE/COM set up. When I open the CFileDialog from the EXE and set the lpstrInitialDir to C:UsersUserAppDataAppName and load a file from an alternate location than the initial dir and re-open the CFileDialog again, it will be in the alternate location. This is the expected behavior also found in the MSDN. However, when I now open the CFileDialog from within the COM DLL(Due to weird past design decisions part of the code is in the COM DLL and change all that requires massive re-working) and set the initial dir to the AppData again, it will indeed show up in the AppData folder, even after I opened it in the EXE part. Even after I loaded a file from an alternate location in the DLL, it will always default to the initial dir for some reason.<br/> <br/> Im trying to get rid of this problem as I cannot find a cause for it, nor a decent solution for it. Perhaps Im not taking the best route here, but what Im trying to do is store the last used location in both the EXE and the COM DLL and synchronize these so theyre always the same. <br/> <br/> The problem: <br/> Im currently having problems setting the m_ofn.lpstrFile variable. I dont want to set the lpstrInitialDir of the OFN struct, but the File var. However, when I use the constructor of my subclassed the CFileDialog doesnt show up at all, and I cannot use the CFileDialog::OnInitDialog as Vista(and 7) doesnt support it.<br/> <br/> Any ideas?

View the full article
 
Back
Top