织梦CMS - 轻松建站从此开始!

罗索

Dialog for Selecting (and Creating) Folders

罗索客 发布于 2007-03-06 11:21 点击:次 
FileDialog,文件选择窗口 Dialog for Selecting (and Creating) Folders
TAG:

点击浏览该文件

Dialog for Selecting (and Creating) Folders
Nguyen Tan Hung
May 11, 2000

Class Purpose
The CPathDialog class lets users select or create a folder. It's just a simple extension of SHBrowseForFolder function.
Functions
Class Constructor

CPathDialog::CPathDialog(
LPCTSTR lpszCaption=NULL, //Caption of dialog
LPCTSTR lpszTitle=NULL, //Prompt of program
LPCTSTR lpszInitialPath=NULL, //Initial path
CWnd* pParent=NULL //Parent of dialog
);

Display Dialog

int CPathDialog::DoModal();

CPathDialog returns the return value of the DoModal function (can be either IDOK or IDCANCEL).
Ensure Path Exists

int CPathDialog::MakeSurePathExists(
LPCTSTR lpPath //Path to driectory you want to exist
);

The MakeSurePathExists function ensures that the path presented by the lpPath argument exists. If it does not exist, the function attempts to create it.
Returns of the fucntion can be:

* -1: user cancels create the lpPath directory.
* 0 : lpPath directory exists or was created.
* 1 : lpPath is invalid.
* 2 : can not create lpPath directory.

Integrating the CPathDialog into Your Project

1. Import two files "pathdialog.h" and "pathdialog.cpp" into your project.
2. Include the header file "pathdialog.h"
3. Declare an object for CPathDialog class
4. Invoke DoModal function to show dialog
5. If user press OK button, get path name user's entered by using GetPathName function.

Example of Using the CPathDialog Class:

#include "PathDialog.h"
void CTestPathDialogDlg::OnBrowserButton()
{
CString strInitialPath;
CString strYourCaption(_T("Your caption here..."));
CString strYourTitle(_T("Your tilte here..."));

m_ctrlPathName.GetWindowText(strInitialPath);

CPathDialog dlg(strYourCaption, strYourTitle, strInitialPath);

if (dlg.DoModal()==IDOK)
{
m_ctrlPathName.SetWindowText(dlg.GetPathName());
}
}

void CTestPathDialogDlg::OnOKButton()
{
CString strPath;
m_ctrlPathName.GetWindowText(strPath);

if(CPathDialog::MakeSurePathExists(strPath)==0)
{
CDialog::OnOK();
}
}
http://www.codeguru.com/Cpp/W-D/dislog/dialogforselectingfolders/article.php/c2019

(Tan Hung)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/200703/6575.html]
本文出处:网络博客 作者:Tan Hung
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
相关文章
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容