效果截图:
-----------------------------------------------------------------------------------------------------------------------------------------------------
这次显示的是QQ空间的登陆验证码,关键代码如下:
//下载验证码线程
void CShowVertificationCodeDlg::ThreadDownVertificationCode()
{
CString msg;
wchar_t *szURL=L"http://captcha.qq.com/getimage?uin=407583721&aid=549000912&cap_cd=4r8HnDflIm8m_Zb-flCA7MvXQ39gU3Hq&0.8621867699548602";
wchar_t szFileName[]=L"D:\\vertificationcode.bmp"; //WIN7 64下载到C盘会失败,没权限???
DeleteFile(szFileName);
DeleteUrlCacheEntry(szURL); //记得清理IE缓存,不然每次获取到的都是同一张图片
HRESULT retVal=URLDownloadToFile(NULL,szURL,szFileName,0,NULL);
if(S_OK!=retVal)
{
msg.Format(_T("下载失败:GetLastError()=%d \n"),GetLastError());
OutputDebugString(msg);
return;
}
msg.Format(_T("下载完毕:GetLastError()=%d \n"),GetLastError());
OutputDebugString(msg);
CImage imgVer;
retVal=imgVer.Load(szFileName);
if(S_OK!=retVal)
{
return;
}
CDC *pDc=m_imgVertificationCodeCtrl.GetDC();
if (NULL==pDc)
{
msg.Format(_T("获取图片框DC失败:GetLastError()=%d \n"),GetLastError());
OutputDebugString(msg);
return;
}
CRect rc;
m_imgVertificationCodeCtrl.GetClientRect(&rc);
::SetStretchBltMode(pDc->m_hDC, HALFTONE); //如果不设置这两个函数图片就会变色
::SetBrushOrgEx(pDc->m_hDC, 0, 0, NULL); //图片太大会造成色彩失调,用0,0代替rc会很清晰
imgVer.Draw(pDc->m_hDC,rc);
ReleaseDC(pDc);
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
VS2010工程下载:
VC显示QQ空间登录验证码.zip
http://download.csdn.net/detail/friendan/7618129
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
您的十分满意是我追求的宗旨。
您的一点建议是我后续的动力。