6

I am using custom file dialog which is extended from the CFileDialog. The problem is that, OninitDialog() does not get called before DoModal().

I have customized the CFileDialog in the OninitDialog().

I am using VS 2012 with Win7 OS.

I could not find out, what is going wrong.

Ajay
  • 18,086
  • 12
  • 59
  • 105

2 Answers2

3

I just run into same issue today; I think I found a valid solution, in constructor of your class just set m_bVistaStyle = FALSE; After doing this, I got OnInitDialog and I was able to customize this dialog just fine.

CMyOpenDlg::CMyOpenDlg(LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
      DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
      CFileDialog(TRUE, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
{
   m_bVistaStyle = FALSE;
  • 1
    Up-voted, but `m_bVistaStyle` should not be set in constructor (at least, it should be restored in destructor). Instead, one should pass FALSE to the last parameter `bVistaStyle` when construct CFileDialog object. – guan boshen May 23 '16 at 06:44
  • Up-voted, i agree with Guan, i had the same problem, if you only set the variable in the constructor you will get an error while you close the dialogue, the fastest and cleanest way to do this would probably set it as false in the constructor parameters. – Amine Tagui Oct 12 '22 at 14:12
2

The Microsoft documentation says that OnInitDialog is not supported on Windows Vista. The same is true for Windows 7 (and probably also for Windows 8).

Ajay
  • 18,086
  • 12
  • 59
  • 105
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • Is there any other option to customize CFileDialog ?? Or is there any other dialog by which i may get the solution..?? Please suggest. –  Mar 26 '13 at 09:40
  • Maybe you can get some information here http://forum.codejock.com/forum_posts.asp?TID=10550&title=cfiledialog-using-mfc-on-vista and here http://msdn.microsoft.com/en-us/library/vstudio/bb775912.aspx. BTW why do you need a OnInitDialog in your CFileDialog ? – Jabberwocky Mar 26 '13 at 10:02
  • Actually, I want to modify that dialog, I mean want to add checkbox,button and combobox as per my app requirment. –  Mar 26 '13 at 10:47
  • You probably will need to do it the hard way, see links in my previous comment. Good Luck. – Jabberwocky Mar 26 '13 at 11:29