保存/打开Win32中没有MFC的公共对话框 [英] Save/Open Common Dialog boxes in win32 without MFC

查看:143
本文介绍了保存/打开Win32中没有MFC的公共对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用纯非管理Win32 API创建保存/打开对话框?
遵循指南这里,当在主窗口的消息循环中处理 WM_CREATE 消息时,执行以下代码:
Ive 包括< Commdlg.h>

How do you create the deafault Save/Open dialog boxes using pure unmanaged Win32 API ? Following the guide here, the following code is executed when WM_CREATE message is handled in the message loop of the main window: Ive included <Commdlg.h> also.

            OPENFILENAMEA ofn;
        char Buffer[300];
        fill(Buffer, Buffer + 300, '\0');
        ofn.lStructSize = sizeof(OPENFILENAMEA);
        ofn.hwndOwner = hWnd;
        ofn.lpstrFile = Buffer;
        ofn.nMaxFile = 300;
        ofn.Flags = OFN_EXPLORER;
        ofn.lpstrFilter = NULL;
        ofn.lpstrCustomFilter = NULL;
        ofn.nFilterIndex = 0;
        ofn.lpstrFileTitle = NULL;
        ofn.lpstrInitialDir = NULL;
        ofn.lpstrTitle = NULL;
        out << GetOpenFileNameA(&ofn) << endl;
        out << Buffer << (int)CommDlgExtendedError();

但是,此代码会提供输出。帮助?

However, this code gives NO output whatsoever. Help?!

推荐答案


下面的代码在处理WM_CREATE消息时执行

the following code is executed when WM_CREATE message is handled

查看Output窗口并观察0xc0000005(AccessViolation异常)的第一次机会异常通知。在Wow64模拟器中有一个支持,在WM_CREATE被调度时吞下异常。

Look in the Output window and observe the first-chance exception notification for 0xc0000005, an AccessViolation exception. There's a backstop in the Wow64 emulator that swallows exceptions while WM_CREATE is being dispatched.

异常是由未完全初始化OPENFILENAMEA结构引起的。快速修复:

The exception is caused by not fully initializing the OPENFILENAMEA structure. Quick fix:

 OPENFILENAMEA ofn = {0};

并且希望在调用ShowWindow()而不是WM_CREATE消息处理程序之前显示对话框。

And favor displaying the dialog before calling ShowWindow() instead of the WM_CREATE message handler.

这篇关于保存/打开Win32中没有MFC的公共对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆