方法积累
来源:互联网 发布:欧阳坤 知乎 编辑:程序博客网 时间:2024/05/16 01:04
//////////////////////////////////////////////////////////////////////////////////////////////////
///启动文件/////////////////////////////////////////////////////////////////////////////启动文件
//获得文件路径
GetCurrentDirectory(MAX_PATH, szFilePath);
strcat(szFilePath, _T("//"));
strcat(szFilePath, m_szFileName);
//申明结构体
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = szFilePath; //路径
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
//启动
ShellExecuteEx(&ShExecInfo);
/////////////////////////////////////////////////////////////////////////////////////////////////////
///下载文件cstrUrl是文件地址url//////////////////////////////////////////////////下载文件/////
BOOL CRequestFile::DownloadFile(CString cstrUrl)
{
//解析文件名
char *pszUrl = NULL;
char *pszFileName = NULL;
string strUrl = cstrUrl.GetBuffer();
//pszUrl = strUrl.c_str();
//memset(pszUrl, 0, MAX_PATH * 2);
pszUrl = new char[MAX_PATH];
sprintf_s(pszUrl, MAX_PATH, "%s", strUrl.c_str());
string::size_type sizeType;
sizeType = strUrl.find_last_of('/');
pszFileName = &pszUrl[sizeType + 1];
CInternetSession cis;
CHttpConnection *pHttpCon;
DWORD dwType;
CString cstrFilePath;
CString cstrServer;
INTERNET_PORT INTERPort;
AfxParseURL((LPCTSTR)cstrUrl, dwType
, cstrServer, cstrFilePath, INTERPort);
cis.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, 5000);
if (cstrServer.IsEmpty())
{
return FALSE;
}
pHttpCon = cis.GetHttpConnection(cstrServer, INTERPort);
CHttpFile *pHttpFile = pHttpCon->OpenRequest(CHttpConnection::HTTP_VERB_GET, /
cstrFilePath, /
NULL, /
1, /
NULL, /
NULL, /
HSR_DOWNLOAD | INTERNET_FLAG_EXISTING_CONNECT
| INTERNET_FLAG_NO_AUTO_REDIRECT);
try
{
m_bSendRet = pHttpFile->SendRequest();
}
catch (CInternetException* pEx)
{
TCHAR tszError[MAX_PATH] = {0};
pEx->GetErrorMessage(tszError, MAX_PATH);
MessageBox(tszError, "Error");
}
if (pHttpFile)
{
CString cstrQuery;
pHttpFile->QueryInfo(HTTP_QUERY_STATUS_CODE, cstrQuery);
if (atol(cstrQuery) != DOWNLOAD_SUCCESS)
{
pHttpFile->Close();
return FALSE;
}
int n;
char szDownFileLocalPath[MAX_PATH] = {0};
GetCurrentDirectory(MAX_PATH, szDownFileLocalPath);
strcat(szDownFileLocalPath, _T("//"));
strcat(szDownFileLocalPath, pszFileName);
CStdioFile csf;
if (!csf.Open(szDownFileLocalPath, CFile::modeCreate | CFile::modeWrite
| CFile::typeBinary | CFile::shareDenyWrite))
{
pHttpFile->Close();
return FALSE;
}
char szBuff[MAX_PATH * 2] = {0};
DWORD dwRead = 0;
DWORD SendRead = 0;
while ((n = pHttpFile->Read(szBuff, sizeof(szBuff))) > 0)
{
dwRead += (DWORD)n;
csf.Write(szBuff, n);
memset(szBuff, 0, MAX_PATH * 2);
SendRead = dwRead / MAX_PATH;
::SendMessage(m_hWndProDlg, WM_UPDATE, dwRead, 0);
}
MessageBox("completed");
csf.Close();
}
else
{
return FALSE;
}
try
{
m_bSendRet = pHttpFile->SendRequest();
}
catch (CInternetException* pEx)
{
TCHAR tszError[MAX_PATH] = {0};
pEx->GetErrorMessage(tszError, MAX_PATH);
pHttpFile->Close();
return FALSE;
}
pHttpFile->Close();
delete []pszUrl;
pszUrl = NULL;
return TRUE;
}
////////////////////////////////////////////////////////////////////////////////////////
///使窗体半透明//////////////////////////////////////////////////////////////使窗体半透明/////
void CTestrDlg::SetLayeredWndAttr(int iSetTransprc, int iSetTrancAttr)
{
//加入WS_EX_LAYERED扩展属性
SetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE,
GetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE)^0x80000);
HINSTANCE hInst = LoadLibrary("User32.DLL");
if (hInst)
{
typedef BOOL (WINAPI *MYFUNC)(HWND, COLORREF, BYTE, DWORD);
MYFUNC fun = NULL;
//取得SetLayeredWindowAttributes函数指针
fun = (MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
if (fun)
{
fun(this->GetSafeHwnd(), 0, iSetTransprc, iSetTrancAttr);
FreeLibrary(hInst);
}
}
}
////////////////////////////////////////////////////////////////////////////////////////
///如何弹出鼠标提示框///////////////////////////////////////////////////如何弹出鼠标提示框/////
- 方法积累
- 数据库连接,方法积累大全
- 方法积累系列一
- 方法积累系列二
- VS Debug 方法积累
- NSString方法用法积累
- perl方法积累
- 博弈方法积累
- CodeBlocks配置方法积累
- js小方法积累
- 工具方法积累
- 【joda-time】方法积累
- pandas方法积累
- 【js】js中方法积累
- Mat的初始化方法积累
- Linq 自己常用方法积累
- git rebase 方法,积累学习
- GreenDao3.0查询方法积累
- 云计算是IT行业的集体炒作还是可以触摸的未来?
- C++中new和malloc的区别
- 改变VC6.0程序方法。
- 排除DNS解析故障方法 Windows系统名称解析过程
- 安全技巧:映像劫持与反劫持技术
- 方法积累
- UVa OJ 272-TEX Quotes
- 全局变量
- 详尽分析:AV终结者采用重定向劫持技术(转)
- 解决mysql“Access denied for user 'root'@'localhost'”
- iterator与const_iterator
- 常用sql自定义函数以及存储过程
- Intel系统编程指南第十一章——11.1 内部Cache、TLB和缓存
- UVa OJ 458-The Decoder