用于自定义“另存为"公共对话框的示例对话框定义 [英] Sample dialog definition for customizing 'Save As' common dialog box
问题描述
我正在尝试自定义标准win32另存为"对话框.我的代码如下:
I'm trying to customize standard win32 "Save As" dialog box. My code looks like this:
OPENFILENAME ofn;
//... skipped
ofn.Flags = OFN_ENABLETEMPLATE;
ofn.lpTemplateName = MAKEINTRESOURCEW(RES); // what is the RES?
//... skipped
GetSaveFileName(&ofn);
但是我找不到任何关于RES的例子.它必须是资源文件或类似的东西.我需要一个简单的例子开始.目前,我只需要在标准另存为"对话框的底部添加文本行即可.
But I can't find any single example of what is the RES. It must be resource file or something like this. I need a simple example to start with. All I need at the moment is to add text line to the bottom of standard 'Save As' dialog box.
推荐答案
最后我找到了示例: CommDlgCust.zip
已14岁,但仍然可以使用.使用Visual C ++ 2013可以轻松打开旧项目文件.
It is 14 years old but still works. Old project file can be easily opened with Visual C++ 2013.
因此,"RES"是位于rc文件中的对话框定义.我想要的答案是这样的:
So the "RES" thing is a dialog definition located in rc file. The answer I wanted is this:
IDD_OPENSAVE DIALOG FIXED IMPURE 0, 0, 280, 53
STYLE WS_CHILD | WS_CLIPSIBLINGS
FONT 8, "MS Shell Dlg"
BEGIN
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,6,6,266,38
CTEXT "",IDC_STATIC_HINT,12,10,256,28,SS_CENTERIMAGE
END
以下是基于CommDlgCust.zip的代码示例:
Here is code sample based on the CommDlgCust.zip:
// ---------- resource.h
// last line of the file must be an empty line!
#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif
#define IDC_STATIC_HINT 1001
#define IDD_OPENSAVE 110
// ---------- project.rc
#include "resource.h"
#include "targetver.h"
#include "windows.h"
IDD_OPENSAVE DIALOG FIXED IMPURE 0, 0, 280, 53
STYLE WS_CHILD | WS_CLIPSIBLINGS
FONT 8, "MS Shell Dlg"
BEGIN
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,6,6,266,38
CTEXT "",IDC_STATIC_HINT,12,10,256,28,SS_CENTERIMAGE
END
// ---------- main.cpp
// ...skipped...
UINT CALLBACK OfnHookProc(HWND hDlg, UINT uMsg, UINT /*wParam*/, LONG lParam)
{
switch (uMsg)
{
case WM_NOTIFY:
OFNOTIFY* pofNotify = (OFNOTIFY*)lParam;
switch (pofNotify->hdr.code)
{
case CDN_FOLDERCHANGE:
{
LPTSTR pszPathName;
pszPathName = new TCHAR[_MAX_DIR];
HWND hTrueDlg = GetParent(hDlg);
SendMessage(hTrueDlg, CDM_GETFOLDERPATH, _MAX_PATH, (LONG)pszPathName);
SetDlgItemText(hDlg, IDC_STATIC_HINT, pszPathName);
delete[] pszPathName;
return TRUE;
}
}
}
return FALSE;
}
bool MyGetSaveFileName()
{
WCHAR lpstrFile[1024] = {0};
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.hInstance = (HINSTANCE)GetWindowLong(ofn.hwndOwner, GWL_HINSTANCE);
ofn.lpstrFilter = L"*.TXT";
ofn.lpstrFile = lpstrFile;
ofn.nMaxFile = 1023;
ofn.lpstrTitle = L"Save";
ofn.Flags = OFN_EXPLORER | OFN_ENABLETEMPLATE | OFN_ENABLEHOOK;
ofn.lpTemplateName = MAKEINTRESOURCE(IDD_OPENSAVE);
ofn.lpfnHook = OfnHookProc;
if (GetSaveFileName(&ofn) != 0)
return true;
return false;
}
我希望这会对某人有所帮助.
I hope this will help someone.
这篇关于用于自定义“另存为"公共对话框的示例对话框定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!