1

I'm getting an error CDERR_DIALOGFAILURE from GetOpenFileName. here's the code...

// In WndProc

   LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
   {        
    static HINSTANCE    hInstance;
    switch (message) 
    {  
      case WM_CREATE:
          hInstance = (HINSTANCE) GetWindowLong (hWnd, GWL_HINSTANCE);

// In message processing within WndProc

  case ID_READ_LOG_FILE:
  {
      OPENFILENAME  ofn;
      char      fn[MAX_PATH]="\0";
      char      filter[32]="Text Files\0*.TXT;\0\0";
      char      title[]="Open Log File";
      char      defext[]="TXT";
      int       status;

      ofn.lStructSize           = sizeof(ofn);
      ofn.hwndOwner         = hWnd;
      ofn.hInstance         = hInstance;
      ofn.lpstrFilter           = filter;
      ofn.nFilterIndex          = 0;
      ofn.lpstrCustomFilter         = NULL ;
      ofn.nMaxCustFilter        = 0 ;
      ofn.lpstrFile         = fn;
      ofn.nMaxFile          = sizeof(fn);
      ofn.lpstrFileTitle        = NULL;
      if (ReadLogFileLastDir[0] == '\0')
      {
         SHGetSpecialFolderPath (NULL,ReadLogFileLastDir,0x0005,false);
      };
      ofn.lpstrInitialDir               = ReadLogFileLastDir;
      ofn.lpstrTitle            = title;
      ofn.Flags             =  OFN_FILEMUSTEXIST  | 
                                           OFN_PATHMUSTEXIST  | 
                                       OFN_EXPLORER       | 
                                           OFN_ENABLETEMPLATE | 
                                               OFN_ENABLESIZING   | 
                                               OFN_ENABLEHOOK ;
      ofn.lpstrDefExt           = NULL;
      ofn.lpfnHook          = HookFileOpen;
      ofn.lCustData         = 1234;     // just for fun
      ofn.lpTemplateName        = MAKEINTRESOURCE(IDD_HOOKFILEOPEN);
      ofn.nFileOffset           = 0 ;
      ofn.nFileExtension        = 0 ;
      ofn.lpstrDefExt = defext;

      status = GetOpenFileName (&ofn);
      if (status == 0)
      {
    DWORD iStat, z;
    iStat = CommDlgExtendedError();
    if (iStat == CDERR_DIALOGFAILURE)

// The dialog procedure looks like this but never gets called.

   UINT_PTR CALLBACK HookFileOpen (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
   {
Mike D
  • 2,753
  • 8
  • 44
  • 77
  • I have another version of this that works. I think the problem might be that the sizeof(ofn) is 76 in this program while it is 88 in the one that works. I've tried putting a #define _WIN32_WINNT 0x0500 in front of a include for windows.h and Commdlg.h but to no avail. There seems to be a include windows.h in my rc file so maybe that takes precedence? – Mike D Apr 15 '11 at 18:34
  • I added a #define _WIN32_WINNT 0x0500 in my StdAfx.h and now sizeof(ofn) is 88 but I still get the CDERR_DIALOGFAILURE. :-( – Mike D Apr 15 '11 at 18:44
  • Ok, I changed the dialog to be a child with clip siblings and eliminated every other style and now it works. – Mike D Apr 15 '11 at 19:16

1 Answers1

1

I don't know exactly what is needed but I modified the dialog making it a child with clip siblings and eliminated all other styles and extended styles and now it works.

Mike D
  • 2,753
  • 8
  • 44
  • 77