getopenfilename功能没有打开对话框
GetOpenFileName function is not opening the dialog box
所以我有一个简单的代码,因为我是Win32的新手
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY: PostQuitMessage (0); break;
case WM_CREATE : make_controls(hwnd); break;
case WM_COMMAND: handle_commands(hwnd, wParam, lParam); break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
这是handle_commands
函数
void handle_commands(HWND hwnd, WPARAM wp, LPARAM lp){
if( HIWORD(wp) == BN_CLICKED && LOWORD(wp) == openBtn ){
// openBtn is the only button in the whole application
OPENFILENAME ofn; // common dialog box structure
char szFile[260]; // buffer for file name
HWND hwnd; // owner window
HANDLE hf; // file handle
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
// Set lpstrFile[0] to ' ' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = ' ';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All *.* Text *.TXT ";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
// Display the Open dialog box.
if (GetOpenFileName(&ofn)==TRUE)
hf = CreateFile(ofn.lpstrFile,
GENERIC_READ,
0,
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);
}
}// this is the end of the handle_commands functions
但问题是它没有打开任何对话框
尽我所能,互联网上的人们成功开放了相同的代码。
是的!我包括Commdlg.h和相应的库
预先感谢!
,因此问题是在handle_commands
中,hwnd
已更改。这意味着OPENFILENAME
结构不知道其正确的所有者,尽管单击按钮要触发正确的代码,但仍未打开对话框。
因此,只需评论handle_commands
功能中的HWND hwnd
行
相关文章:
- MSDN 示例:未编译的"打开"对话框
- Qt从主窗口打开对话框
- 窗口对话框未打开
- getopenfilename功能没有打开对话框
- 如何使用Ifileopendialog打开 *模态 *文件对话框
- VC++ 2010:从 VC6++ 转换后显示打开对话框时出错
- 在 MFC C++中打开对话框
- 如何设置 windows 文件打开对话框筛选器以包含"必须完成"选项
- MFC 菜单项未打开对话框
- 我的命名空间扩展未在“文件打开”对话框中列出
- Qt应用程序在使用文件打开对话框后将焦点切换到其他应用程序
- wxpython文件打开对话框
- 按条件打开对话框
- 打开对话框
- Qt鼠标光标不改变时,打开对话框后下降事件
- 打开对话框
- MSDN打开对话框示例代码
- Win32 API:打开对话框窗口后应用程序冻结
- 点击Visual c++时打开对话框按钮
- C++/Qt-从主窗口打开对话框-错误LNK2019-LNK2001:未解析的外部符号