windows - OpenFileName med krog resulterer i CDERR\_DIALOGFAILURE

Indlæg af Hanne Mølgaard Plasc

Problem



Jeg får en fejl CDERR\_DIALOGFAILURE fra GetOpenFileName. Her er koden ...


//I 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);


//I beskedbehandling inden for WndProc


  case ID\_READ\_LOG\_FILE:
  {
      OPENFILENAME  ofn;
      char      fn[MAX\_PATH]="";
      char      filter[32]="Text Files*.TXT;";
      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] == '')
      {
         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)


//Dialogproceduren ser ud som dette, men bliver aldrig kaldt.


   UINT\_PTR CALLBACK HookFileOpen (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
   {

Bedste reference


Jeg ved ikke præcis hvad der er brug for, men jeg ændrede dialogen, der gør det til et barn med clips søskende og elimineret alle andre stilarter og udvidede stilarter, og nu virker det.