MFC – 青春部落,流年似水 http://www.youthtribe.com 青春是一场远行,总记不起来时的路。 Tue, 16 Sep 2014 14:20:43 +0000 zh-CN hourly 1 https://wordpress.org/?v=6.1.7 MFC – 青春部落,流年似水 http://www.youthtribe.com/archives/1350 http://www.youthtribe.com/archives/1350#respond Tue, 16 Sep 2014 14:20:43 +0000 http://www.youthtribe.com/?p=1350 vc++[mfc]递归删除文件夹及其里边的文件

void DeleteDirectory(LPCTSTR path)
{
	CFileFind findfile;
	CString str;
	str=path;
	if(str.Right(1)!="\\")
		str.Format("%s\\*.*",path);
	else
		str.Format("%s*.*",path);
	BOOL find=findfile.FindFile(str);

	while(find)
	{
		find=findfile.FindNextFile();
		if(findfile.IsDirectory())
		{
			if(!findfile.IsDots())
			{

				DeleteDirectory(findfile.GetFilePath());
			}
		}
		else
		{
			DeleteFile(findfile.GetFilePath());
		}
	}
	findfile.Close();
	if(!RemoveDirectory(path))
	{
		DWORD ret=::GetLastError();
		CString strerr;
		strerr.Format("%d",ret);
		MessageBox(strerr,"错误代码",MB_OK);
	}
}
]]>
http://www.youthtribe.com/archives/1350/feed 0
MFC – 青春部落,流年似水 http://www.youthtribe.com/archives/1342 http://www.youthtribe.com/archives/1342#respond Mon, 08 Sep 2014 04:03:49 +0000 http://www.youthtribe.com/?p=1342 1.添加一个右键响应消息

	//右键就显示一个菜单;包括:1、item1 2、item2 and so on....
	CMenu Menu;
	//创建一个弹出式菜单
	Menu.CreatePopupMenu();
	//添加菜单项
	
	Menu.AppendMenu(MF_STRING, ID_POP_MENU_PICS_FIND_0, "◆ 单独阅此张答题卡");

	//根据当前光标位置显示菜单
	CPoint Pos;
	GetCursorPos(&Pos); 
	Menu.TrackPopupMenu(TPM_RIGHTBUTTON, Pos.x, Pos.y, this);
	Menu.DestroyMenu();

2.在资源那里添加对应的菜单
3.添加meNuc响应消息函数
h头文件,函数定义:

afx_msg void OnFunction1();

cpp文件:

ON_COMMAND(ID_POP_MENU_PICS_FIND_0, OnFunction1)

ok,that’s all.

]]>
http://www.youthtribe.com/archives/1342/feed 0
MFC – 青春部落,流年似水 http://www.youthtribe.com/archives/1130 http://www.youthtribe.com/archives/1130#respond Thu, 08 May 2014 07:52:38 +0000 http://www.youthtribe.com/?p=1130 CFileDialog infofile(FALSE,NULL,"请输入要保存的模板名称",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_NOCHANGEDIR, "TPL文件(*.tpl)|*.TPL| |",AfxGetMainWnd()); infofile.m_ofn.lpstrInitialDir = "c:\\"; CString strTplFileName; if(infofile.DoModal()==IDOK) { strTplFileName=infofile.GetPathName()+".tpl"; }

这样就能保存到c盘下了。

]]>
http://www.youthtribe.com/archives/1130/feed 0
MFC – 青春部落,流年似水 http://www.youthtribe.com/archives/1114 http://www.youthtribe.com/archives/1114#respond Sat, 03 May 2014 14:54:41 +0000 http://www.youthtribe.com/?p=1114 m_hWnd,buffer,255); CString strWindowName = ""; strWindowName.Format("%s",buffer); MessageBox(strWindowName); delete [] buffer;]]> [mfc][vc++]

如何得到对话框标题
	LPTSTR buffer=   new   TCHAR[255];
	::GetWindowText(GetActiveWindow()->m_hWnd,buffer,255);
	CString strWindowName = "";
	strWindowName.Format("%s",buffer);
	MessageBox(strWindowName);
	delete [] buffer;
]]>
http://www.youthtribe.com/archives/1114/feed 0
MFC – 青春部落,流年似水 http://www.youthtribe.com/archives/1036 http://www.youthtribe.com/archives/1036#comments Fri, 20 Dec 2013 14:41:02 +0000 http://www.youthtribe.com/?p=1036 今天在操作线程的时候,遇到一个问题:
那就是如何在线程里把数据写到对话框控件中去,比如一个listctrl控件中。百度了一下,竟然有说不可以的。。
不过我动了一个脑筋,还是可以搞定的,我都实现 了的。
做法如下:
1.在你的cpp文件中定义你的对话框指针,要定义成全局变量哦。
static Cnbqq_upload_mysqlDlg * pDlg;
2.在你的对话框初始化函数(BOOL Cnbqq_upload_mysqlDlg::OnInitDialog())中添加:
pDlg = this;//知道这是什么意思吧?就是把你的对话框指针弄成一个静态全局变量!
3.这就可以在你的线程里调用啦!

UINT Cnbqq_upload_mysqlDlg::MyThreadFunction(LPVOID pParam)
{
      CFtpConnection* FtpConnection = (CFtpConnection*)pParam;
      for (int i=0 ;im_CtrlListCtrlPicsFind.GetItemCount();i++)//这样就可以啦
    {
       CString strFile;
	strFile = pDlg->m_CtrlListCtrlPicsFind.GetItemText(i,1);
        }

}

代码我是自己测试ok,可用的,有问题的可以给我留言讨论。这个方法其实是非常有用处的!!!

]]>
http://www.youthtribe.com/archives/1036/feed 1