带有钩子的 OpenFileName 会导致 CDERR_DIALOGFAILURE

发布于 2024-11-02 03:32:27 字数 2307 浏览 1 评论 0原文

我从 GetOpenFileName 收到错误 CDERR_DIALOGFAILURE。这是代码...

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

// 在 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)

// 对话框过程看起来像这样,但从未被调用。

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

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)
   {

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒儿 2024-11-09 03:32:27

我不知道到底需要什么,但我修改了对话框,使其成为具有剪辑兄弟姐妹的子项,并消除了所有其他样式和扩展样式,现在它可以工作了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文