mfc vc++ – 青春部落,流年似水 http://www.youthtribe.com 青春是一场远行,总记不起来时的路。 Thu, 30 Jun 2022 09:26:05 +0000 zh-CN hourly 1 https://wordpress.org/?v=6.1.6 mfc vc++ – 青春部落,流年似水 http://www.youthtribe.com/archives/1950 Sat, 05 Feb 2022 17:57:20 +0000 http://www.youthtribe.com/?p=1950 这两天在捣鼓测试阿里云的对象存储,阿里云称为 阿里云对象存储OSS(Object Storage Service)。

首先,相关sdk是放在 github的。so,需要科学上网。很是不方便。

再者就是遇到了提供的教程默认编译出来的lib是64位的。我的项目均是32位下开发的。如果设置为win32的,vs编译时会有如下的提示:

错误 LNK1112 模块计算机类型“x86”与目标计算机类型“x64”冲突 cpp-sdk F:\迅雷下载\aliyun-oss-cpp-sdk-1.9.0\build\sdk\Debug\OssClient.obj 1

解决办法是修改项目的属性中的 文档管理程序的-》所有选项-》附加选项,/machine:x64 改为 /machine:x86

但好像各个vs版本的这个属性的位置有所不一样,注意区别对待。

还有如下问题:

阿里云oss也集成了相关的第三方库,libcurl,ssleasy等,这和我当前项目的不兼容。生成的exe程序会有如下提示:

然后我就用他提供的dll直接替换了我的原先的。简单看是没问题,可以正常执行(但真不确保就没问题呀,内心还是比较担心的)。所以还是需要仔细测试。

还有就是,好像他的第三方库的dll只有release版本的,没有debug的,这样的话,我的程序 在debug模式下就不能正常运行了,只能在release模式下开发了。。。这,也是个问题呀。。。不知道怎么整。。。

最开始是打算捣鼓腾讯云对象存储的,感觉腾讯的第三方库 也不好弄。poco。就放弃了。

]]>
mfc vc++ – 青春部落,流年似水 http://www.youthtribe.com/archives/1765 http://www.youthtribe.com/archives/1765#respond Tue, 30 Oct 2018 12:29:21 +0000 http://www.youthtribe.com/?p=1765 MFC获取整个文件夹的大小

//获取整个文件夹的大小
double CEvent::GetDirSize(CString strFullPath)
{
     double dwDirSize,dwSubDirSize;  
     CFileFind finder;  
      
     dwDirSize=dwSubDirSize=0; 
     strFullPath+=_T("\\*.*"); 
     if(finder.FindFile(strFullPath)) 
     {
         while(1)  
         {  
              BOOL   bFound;  
              bFound=finder.FindNextFile();  
              if (finder.IsDirectory())  
              {  
                   if (!finder.IsDots())  
                   {  
                       dwSubDirSize=GetDirSize(finder.GetFilePath());
                       dwDirSize+=dwSubDirSize;  
                   }  
              }  
              else  
              {  
                   CFile file;  
                   if   (file.Open(finder.GetFilePath(),CFile::modeRead))  
                   {  
                       dwDirSize+=file.GetLength();  
                       file.Close();  
                   }  
              }  
              if(bFound==FALSE)  
                   break;  
         }  
     }
     finder.Close(); 
     return dwDirSize;  
}
]]>
http://www.youthtribe.com/archives/1765/feed 0
mfc vc++ – 青春部落,流年似水 http://www.youthtribe.com/archives/1746 http://www.youthtribe.com/archives/1746#respond Thu, 25 Oct 2018 07:34:03 +0000 http://www.youthtribe.com/?p=1746 自己写原始的一个链表,还是很麻烦的,mfc是有一个很好用的类的。就是CPtrList,他就是存储多个指针的。

CPtrList添加指针,pItem是一个指针:

m_pSubjectItemList.AddTail(pItem);

 

CPtrList的遍历方法如下:

	POSITION pos = m_pSubjectItemList.GetHeadPosition();
	while (pos != NULL)
	{
		CSubjectItem * pOne = (CSubjectItem * )m_pSubjectItemList.GetNext(pos);
		if (pOne != NULL)
		{
			delete pOne;
		}
	}		
	m_pSubjectItemList.RemoveAll();
]]>
http://www.youthtribe.com/archives/1746/feed 0
mfc vc++ – 青春部落,流年似水 http://www.youthtribe.com/archives/1739 http://www.youthtribe.com/archives/1739#respond Tue, 25 Sep 2018 10:47:50 +0000 http://www.youthtribe.com/?p=1739 首先工程需要引用 Version.lib,这个库。
项目》属性页》配置属性》链接器》输入》附加依赖项
debug和release都要添加。

CString GetSoftwareVersion()
{

	TCHAR szFullPath[MAX_PATH];
	DWORD dwVerInfoSize = 0;
	DWORD dwVerHnd;
	VS_FIXEDFILEINFO * pFileInfo;

	::GetModuleFileName(NULL, szFullPath, sizeof(szFullPath));
	dwVerInfoSize = ::GetFileVersionInfoSize(szFullPath, &dwVerHnd);
	if (dwVerInfoSize)
	{
		// If we were able to get the information, process it:
		HANDLE  hMem;
		LPVOID  lpvMem;
		unsigned int uInfoSize = 0;

		hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
		lpvMem = GlobalLock(hMem);
		GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);

		::VerQueryValue(lpvMem, (LPTSTR)_T("\\"), (void**)&pFileInfo, &uInfoSize);

		WORD m_nProdVersion[4];

		// Product version from the FILEVERSION of the version info resource 
		m_nProdVersion[0] = HIWORD(pFileInfo->dwProductVersionMS); 
		m_nProdVersion[1] = LOWORD(pFileInfo->dwProductVersionMS);
		m_nProdVersion[2] = HIWORD(pFileInfo->dwProductVersionLS);
		m_nProdVersion[3] = LOWORD(pFileInfo->dwProductVersionLS); 

		CString strVersion ;
		//strVersion.Format(_T("The file's version : %d.%d.%d.%d"),m_nProdVersion[0],m_nProdVersion[1],m_nProdVersion[2],m_nProdVersion[3]);
		strVersion.Format(_T("%d.%d.%d.%d"),m_nProdVersion[0],m_nProdVersion[1],m_nProdVersion[2],m_nProdVersion[3]);

		GlobalUnlock(hMem);
		GlobalFree(hMem);

		return strVersion;
		//AfxMessageBox(strVersion);
	}

}
]]>
http://www.youthtribe.com/archives/1739/feed 0
mfc vc++ – 青春部落,流年似水 http://www.youthtribe.com/archives/1737 http://www.youthtribe.com/archives/1737#respond Tue, 18 Sep 2018 03:47:25 +0000 http://www.youthtribe.com/?p=1737 最近vs2010 C++项目中用到了json库,选用了cjson,但由于是c库,就是cjson有两个文件,一个是.c和一个是.h。需要一定的处理才可以正确添加到工程中。

  1. 把cjson.c,改名为cjson.cpp
  2. 把cjson.c和cjson.cpp添加到工程根目录中去
  3. 工程包含这两个文件
  4. 在cjson.cpp文件中,首行添加

#include “StdAfx.h”

done

]]>
http://www.youthtribe.com/archives/1737/feed 0
mfc vc++ – 青春部落,流年似水 http://www.youthtribe.com/archives/1545 http://www.youthtribe.com/archives/1545#respond Thu, 01 Sep 2016 10:22:30 +0000 http://www.youthtribe.com/?p=1545

//要先把控件滚动到这个项这一数据行

int nSel = i;
int nItem2 = pMe->m_CtrlResultList->GetTopIndex();
CRect rc;
pMe->m_CtrlResultList->GetItemRect(nItem2, rc, LVIR_BOUNDS);
CSize sz(0, (nSel – nItem2)*rc.Height());
pMe->m_CtrlResultList->Scroll(sz);
//要先把控件滚动到这个项这一数据行 over

]]>
http://www.youthtribe.com/archives/1545/feed 0
mfc vc++ – 青春部落,流年似水 http://www.youthtribe.com/archives/1529 http://www.youthtribe.com/archives/1529#respond Sun, 22 May 2016 05:05:19 +0000 http://www.youthtribe.com/?p=1529 首先就是一个回调函数

static size_t getResponseString(void *ptr, size_t size, size_t nmemb, void *userdata)
{//参数userdata是存放数据的指针 其他三个获取内容
std::string *version = (std::string*)userdata;
version->append((char*)ptr, size * nmemb);

return (size * nmemb);
}

然后就是一个curl 请求 

curl_global_init(CURL_GLOBAL_WIN32); 
CURL *easy_handle = curl_easy_init(); 
curl_httppost *post = NULL; curl_httppost *last = NULL; 
curl_formadd(&post, &last, CURLFORM_COPYNAME, "school_id", CURLFORM_COPYCONTENTS, IntToCString(pMain->m_nSchoolID), CURLFORM_END); 
curl_formadd(&post, &last, CURLFORM_COPYNAME, "exam_id", CURLFORM_COPYCONTENTS, IntToCString(pExam->m_nExamID), CURLFORM_END); 
curl_formadd(&post, &last, CURLFORM_COPYNAME, "key", CURLFORM_COPYCONTENTS, pMain->m_sDataKey, CURLFORM_END); 
curl_easy_setopt(easy_handle, CURLOPT_URL, "http://www.xx.com/nn/" + pMain->m_sCustomerCode + "/client/school-sheet-upload" ); 
std::string szbuffer; 
curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, getResponseString); 
curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, &szbuffer); //curl_easy_setopt(easy_handle, CURLOPT_HTTPGET, post); curl_easy_setopt(easy_handle, CURLOPT_HTTPPOST, post); 
int nResult = curl_easy_perform(easy_handle); 
long http_code = 0; curl_easy_getinfo (easy_handle, CURLINFO_RESPONSE_CODE, &http_code); 
curl_formfree(post); 
curl_easy_cleanup(easy_handle); 
curl_global_cleanup(); 
CString strText = szbuffer.c_str(); 
strText = Utf_8ToUnicode(strText.GetBuffer(0)); 
//WriteLog(strText,"res.html"); 
if (strText == "1") {
 ( (CButton*)GetDlgItem(IDC_CHECK_SCHOOL_SHEET_UPLOAD))->SetCheck(TRUE); 
} 
else if ( strText == "0" ) { 
( (CButton*)GetDlgItem(IDC_CHECK_SCHOOL_SHEET_UPLOAD))->SetCheck(FALSE); 
}
]]>
http://www.youthtribe.com/archives/1529/feed 0
mfc vc++ – 青春部落,流年似水 http://www.youthtribe.com/archives/1489 http://www.youthtribe.com/archives/1489#respond Tue, 27 Oct 2015 15:30:42 +0000 http://www.youthtribe.com/?p=1489 opencv-hbitmap在内存中直接转jgp格式-bmp转jpg

IplImage* CMainFrame::Bitmap2IplImage(HANDLE hBitmap)
{
	BITMAP bmp; // 得到位图对象
	int nPicSize;
	nPicSize = sizeof(BITMAP);
	GetObject(hBitmap, sizeof(BITMAP), &bmp);

	int depth,nChannels;
	if(bmp.bmBitsPixel == 1)//得到图像深度和通道数
	{
		depth=IPL_DEPTH_1U;
		nChannels=1;
	}
	else
	{
		depth=IPL_DEPTH_8U;
		nChannels=bmp.bmBitsPixel/8;
	}
	long	nBuffer = bmp.bmHeight*bmp.bmWidth*nChannels;
	IplImage* pImg = cvCreateImage(cvSize(bmp.bmWidth,bmp.bmHeight), depth, nChannels); //创建图像
	BYTE *pBuffer = new BYTE[nBuffer]; //创建缓冲区
	//GetBitmapBits(hBmp, bmp.bmHeight*bmp.bmWidth*nChannels, pBuffer); //将位图信息复制到缓冲区
	GetBitmapBits((HBITMAP)hBitmap, nBuffer, pBuffer); //将位图信息复制到缓冲区
	memcpy(pImg->imageData, pBuffer, nBuffer);//将缓冲区信息复制给IplImage
	delete [] pBuffer;//防止内存泄露
	//cvSaveImage("kkk.jpg",pImg,0);
return pImg;
}

]]>
http://www.youthtribe.com/archives/1489/feed 0
mfc vc++ – 青春部落,流年似水 http://www.youthtribe.com/archives/1476 http://www.youthtribe.com/archives/1476#respond Thu, 25 Jun 2015 06:52:32 +0000 http://www.youthtribe.com/?p=1476 clistbox 项单击进行上下移动人工排序


void CMyDlg::OnBnClickedButtonMoveUp()
{
	// TODO: 在此添加控件通知处理程序代码
	int nIndex = m_CtrlListImages.GetCurSel();
	if ( nIndex != 0)
	{
		//不是第一行,就可以向上移动!
		CString strUp;
		m_CtrlListImages.GetText(nIndex-1,strUp);
		m_CtrlListImages.DeleteString(nIndex-1);
		m_CtrlListImages.InsertString(nIndex,strUp);
	}
}

]]>
http://www.youthtribe.com/archives/1476/feed 0
mfc vc++ – 青春部落,流年似水 http://www.youthtribe.com/archives/1468 http://www.youthtribe.com/archives/1468#respond Thu, 11 Jun 2015 08:42:47 +0000 http://www.youthtribe.com/?p=1468 这个控件是基于CStatic派生的一个类,可放大缩小,带滚动条,想做成功能强大的(想做成一个视觉图片软件中的)控件,结果发现很难。。。
也还好,只能说够用。。bug也会不少,权当参考吧。这个static区域重绘,实再是搞不定,这是目前最大的硬伤了。。。
还有,工程是柔合了opencv1.0的东西,版本太旧了。。
我贴出一个网址,如果您完善了,或者有什么疑问(不保证解决,解答),可以在我的博客上留言。。

mfc-static控件显示图片-滚动条-放大缩小-opencv


mfc显示图片,实再太难了,希望对大家有用!

]]>
http://www.youthtribe.com/archives/1468/feed 0