设为首页 加入收藏

TOP

VC笔记 (三)
2014-11-23 19:09:42 来源: 作者: 【 】 浏览:100
Tags:笔记
CString,int,string,char*之间的转换
123. string.c_str()只能转换成const char *,
124. 要转成char *这样写:
125.
126. string mngName;
127. char t[200]; memset(t,0,200); strcpy(t,mngName.c_str());

1..图片操作
此代码放入Onpaint
//编辑图片


//CDialog::OnPaint();//要禁止这个调用
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bmpBackground;
bmpBackground.LoadBitmap(IDB_BITMAP);
//IDB_BITMAP是你自己的图对应的ID
BITMAP bitmap;
bmpBackground.GetBitmap(&bitmap);
CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,
bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);

2.文件操作


(1)//放在OnInitDialog()中
m_list.InsertColumn(0,"文件名", LVCFMT_LEFT, 100, -1); //插入列
//m_list.InsertColumn(1,"大小", LVCFMT_LEFT, 100, -1);
m_list.InsertColumn(2,"路径",LVCFMT_LEFT,200,-1);

void CLOVEDlg::OnAddFile()
{
// TODO: Add your control notification handler code here
//复制文件并记录时间
/*CFileDialog fileDlg(TRUE);
fileDlg.m_ofn.lpstrTitle="添加文件";
fileDlg.m_ofn.lpstrFilter="All Files(*.*)\0*.*\0\0";
int result=fileDlg.DoModal();
if(result==IDOK)
{
CString newpath=path+CString("\\")+fileDlg.GetFileName();
CopyFile(fileDlg.GetPathName(),newpath,FALSE); //拷贝文件
//记录上传
CFile mFile;
mFile.Open(path+CString("\\file.txt"),CFile::modeNoTruncate|CFile::modeWrite);
mFile.SeekToEnd();//移至文件末端输入
//获取当前时间
CTime time=CTime::GetCurrentTime();
CString strTime = time.Format(" %Y-%m-%d %H:%M:%S");
mFile.Write(strTime,strlen(strTime));
mFile.Write("将",2);
mFile.Write(fileDlg.GetPathName(),strlen(fileDlg.GetFileName()));
mFile.Write("上传至共享目录",14);
mFile.Write("\r\n",2);
mFile.Close();
}*/


//打开共享文件
CFileDialog filedlg(TRUE);
if(filedlg.DoModal()==IDOK)
{
CFile file;
//CString strFileSize;
CString path = filedlg.GetPathName();
CString name = filedlg.GetFileName();
//long FileLength = file.GetLength();//文件大小
//strFileSize.Format("%0.1fk", ((float)FileLength)/1024);
LVFINDINFO FindText;
FindText.flags=LVFI_STRING | LVFI_PARTIAL;
FindText.psz = name;
int index=m_list.FindItem(&FindText,-1);
if(index!=-1)
{
MessageBox("文件已经共享!");
}
else
{
int iCount=GetPrivateProfileInt("Cont","count",0,"d:\\program\\本地共享文件.ini");
iCount++;//将记录写入ini中
CString max;
max.Format("%d",iCount);
::WritePrivateProfileString("cont","count",max,"d:\\program\\本地共享文件.ini");
max="file"+max;
::WritePrivateProfileString(max,"filename",name,"d:\\program\\本地共享文件.ini");
//::WritePrivateProfileString(max,"filepath",strFileSize,"d:\\program\\地共享文件.ini");
::WritePrivateProfileString(max,"filepath",path,"d:\\program\\本地共享文件.ini");
m_list.InsertItem(iCount - 1, name);
//m_list.SetItemText(iCount - 1,1,strFileSize);
m_list.SetItemText(iCount - 1,1,path);
}
}
}
//再打开本地共享文件之前添加一个list control的消息响应函数这样路径才会显示出来
void CLOVEDlg::DoDataExcha

首页 上一页 1 2 3 4 5 下一页 尾页 3/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇VC++ 树的孩子兄弟表示法 下一篇窗口滚动条与滚动条控件的区别

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: