📄 vckbaseview.cpp
字号:
// vckbaseView.cpp : CvckbaseView 类的实现
//
#include "stdafx.h"
#include "vckbase.h"
#include "vckbaseDoc.h"
#include "vckbaseView.h"
#include ".\vckbaseview.h"
#include "SignDlg.h"
#include "UserInfo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CvckbaseView
IMPLEMENT_DYNCREATE(CvckbaseView, CHtmlView)
BEGIN_MESSAGE_MAP(CvckbaseView, CHtmlView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, CHtmlView::OnFilePrint)
ON_COMMAND(ID_32771, On32771)
ON_COMMAND(ID_32772, On32772)
ON_WM_CREATE()
ON_COMMAND(ID_VCKBASE_32774, OnVckbase32774)
END_MESSAGE_MAP()
// CvckbaseView 构造/析构
CvckbaseView::CvckbaseView()
{
// TODO: 在此处添加构造代码
m_strSign="";
m_strUserName="";
m_strPassword="";
}
CvckbaseView::~CvckbaseView()
{
}
BOOL CvckbaseView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
// 样式
return CHtmlView::PreCreateWindow(cs);
}
void CvckbaseView::OnInitialUpdate()
{
CHtmlView::OnInitialUpdate();
Navigate2(_T("http://www.vckbase.com/bbs"),NULL,NULL);
}
// CvckbaseView 打印
// CvckbaseView 诊断
#ifdef _DEBUG
void CvckbaseView::AssertValid() const
{
CHtmlView::AssertValid();
}
void CvckbaseView::Dump(CDumpContext& dc) const
{
CHtmlView::Dump(dc);
}
CvckbaseDoc* CvckbaseView::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CvckbaseDoc)));
return (CvckbaseDoc*)m_pDocument;
}
#endif //_DEBUG
// CvckbaseView 消息处理程序
//void CvckbaseView::OnBeforeNavigate2(LPCTSTR lpszURL, DWORD nFlags, LPCTSTR lpszTargetFrameName, CByteArray& baPostedData, LPCTSTR lpszHeaders, BOOL* pbCancel)
//{
// // TODO: 在此添加专用代码和/或调用基类
///*
// int nPos=0;
// char szFinded[]="&details";
// int nCount=0;
// for(int i=0;i<baPostedData.GetCount();i++)
// {
// int k=i;
// for(int j=0;j<strlen(szFinded);j++)
// {
// if(baPostedData[k]==szFinded[j])
// {
// k++;
// nCount++;
// }
// else
// {
// nCount=0;
// }
// }
//
// if(nCount>(strlen(szFinded)-2))
// {
// nPos=i;
// break;
// }
//
// }
//
// if(0)
// {
// int i=nPos+strlen(szFinded);
// for(;i<baPostedData.GetCount();i++)
// {
// if(baPostedData[i]=='&')
// {
// nPos=i;
// break;
// }
// }
//
// char msg[]={"my vckbase test"};
// for(int j=0;j<strlen(msg);j++)
// {
// baPostedData.InsertAt(nPos+j,msg[j]);
// }
//
//
// }
// */
//
// CHtmlView::OnBeforeNavigate2(lpszURL, nFlags, lpszTargetFrameName, baPostedData, lpszHeaders, pbCancel);
//}
void CvckbaseView::On32771()
{
// TODO: 在此添加命令处理程序代码
// char pVoid[]={"forumID=99&money=10&subject=test&details=-_-%21&subjecttemp=%D4%CE%B2%BB%C4%DC%CD%A8%B9%FDOnBeforeNavigate2%D0%DE%B8%C4ie%CF%F2%B7%FE%CE%F1%C6%F7%CC%E1%B9%A9%B5%C4post%CA%FD%BE%DD%B0%A1%A3%BF%A3%BF%A3%BF&detailstemp=-_-%21&URL=&imglink=&imageField.x=24&imageField.y=9"};
// this->Navigate2(_T("http://www.vckbase.com/bbs/addnewtopic.asp"),0,_T("bottom"),_T("Content-Type: application/x-www-form-urlencoded\r\n"),pVoid,strlen(pVoid));
}
void CvckbaseView::OnDocumentComplete(LPCTSTR lpszURL)
{
// TODO: 在此添加专用代码和/或调用基类
CHtmlView::OnDocumentComplete(lpszURL);
}
void CvckbaseView::OnDownloadComplete()
{
// TODO: 在此添加专用代码和/或调用基类
CComPtr<IHTMLDocument2> pDoc,pDoc1;
GetDHtmlDocument(&pDoc);
HRESULT hr;
hr=this->GetAddTopicFrame(pDoc,&pDoc1);
if(hr==S_OK)
{
CComPtr<IHTMLElementCollection> lpScripts;
if(pDoc1->get_scripts(&lpScripts)==S_OK && lpScripts!=NULL)
{
LONG nCount;
lpScripts->get_length(&nCount);
for(int i=0;i<nCount;i++)
{
CComPtr<IDispatch> ppvdisp;
_variant_t index = i;
if(lpScripts->item(index,index,&ppvdisp)==S_OK && ppvdisp!=NULL)
{
CComPtr<IHTMLScriptElement> nodeScript;
if(ppvdisp->QueryInterface(IID_IHTMLScriptElement,(void**)&nodeScript)==S_OK && nodeScript!=NULL)
{
CComBSTR strScript;
nodeScript->get_text(&strScript);
CString str(strScript);
if(str.Find("function checkinput(f)\r\n {")!=-1)
{
CString strToReplace;
CString strSign=m_strSign;
strSign.Replace("\r\n","\\r\\n");
strToReplace="\r\ntry{\r\ndocument.forms[0].userID.value='"+m_strUserName+"';\r\ndocument.forms[0].password.value='"+m_strPassword+"'\r\n}catch(e){}\r\nfunction checkinput(f)\r\n {\r\n\r\ntry{\r\n\r\n\r\nif( document.forms[0].detailstemp.value.indexOf('"+strSign+"')==-1 ){\r\ndocument.forms[0].detailstemp.value=document.forms[0].detailstemp.value+'\\r\\n\\r\\n\\r\\n"+strSign+"';\r\n}\r\n}catch(e){\r\nif( document.forms[0].details.value.indexOf('"+strSign+"')==-1 ){\r\ndocument.forms[0].details.value=document.forms[0].details.value+'\\r\\n\\r\\n\\r\\n"+strSign+"';\r\n}\r\n}\r\n\r\n";
str.Replace("function checkinput(f)\r\n {",strToReplace);
nodeScript->put_text(_bstr_t(str));
break;
}
}
}
}
}
}
CHtmlView::OnDownloadComplete();
}
BOOL CvckbaseView::GetDHtmlDocument(IHTMLDocument2 **ppDocument) const
{
if(ppDocument == NULL)
{
ASSERT(FALSE);
return FALSE;
}
*ppDocument = NULL;
//CvckbaseView *pThis = const_cast<CvckbaseView*>(this);
//CComQIPtr<IWebBrowser2> pBrowserApp = pThis->GetControlUnknown();
CComQIPtr<IWebBrowser2> pBrowserApp = this->m_pBrowserApp;
ASSERT(pBrowserApp != NULL);
if (pBrowserApp)
{
CComPtr<IDispatch> spDispDocument;
HRESULT hr = pBrowserApp->get_Document(&spDispDocument);
if (SUCCEEDED(hr) && spDispDocument)
{
return S_OK == spDispDocument->QueryInterface(ppDocument) ? TRUE : FALSE;
}
}
return FALSE;
}
HRESULT CvckbaseView::GetAddTopicFrame(IHTMLDocument2 * pDoc,IHTMLDocument2 **ppDocument)
{
if(pDoc==NULL)
return S_FALSE;
CComPtr<IHTMLFramesCollection2> pFramesCol;
pDoc->get_frames(&pFramesCol);
VARIANT frameRequested;
VARIANT frameOut;
IHTMLWindow2* pRightFrameWindow;
IHTMLDocument2* pRightDoc;
//frameRequested.vt = VT_BSTR;
//frameRequested.bstrVal = L"bottom";
HRESULT hr;
bool bfind = false;
LONG nFrames;
pFramesCol->get_length(&nFrames);
for(int i=0;i<nFrames;i++)
{
hr = pFramesCol->item(&_variant_t(i), &frameOut);
if(hr== S_OK)
{
hr = frameOut.pdispVal->QueryInterface(IID_IHTMLWindow2, (void**)&pRightFrameWindow);
if(hr== S_OK)
{
pRightDoc = NULL;
hr = pRightFrameWindow->get_document(&pRightDoc);
if(hr== S_OK)
{
BSTR p;
pRightDoc->get_URL(&p);
CString str(p);
if(str.Find("viewtopic.asp?")!=-1 || str.Find("newtopic.asp?")!=-1)
{
*ppDocument = pRightDoc;
return S_OK;
}
else
{
if(GetAddTopicFrame(pRightDoc,ppDocument)==S_OK)
return S_OK;
}
}
}
}
}
return S_FALSE;
}
void CvckbaseView::On32772()
{
// TODO: 在此添加命令处理程序代码
CSignDlg dlg(this);
dlg.m_strSign = this->m_strSign;
if(dlg.DoModal()==IDOK)
{
m_strSign=dlg.m_strSign;
CRegKey reg;
char KeyName[]="Software\\www.hotlove.cn";
reg.Open(HKEY_CURRENT_USER,KeyName);
reg.SetValue(m_strSign,NULL);
reg.Close();
}
}
int CvckbaseView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CHtmlView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码
CRegKey reg;
char KeyValue[10240];
DWORD nLen = sizeof(KeyValue);
memset(KeyValue,0,nLen);
char KeyName[]="Software\\www.hotlove.cn";
if(reg.Open(HKEY_CURRENT_USER,KeyName)!=ERROR_SUCCESS)
{
reg.Create(HKEY_CURRENT_USER,KeyName);
}
reg.QueryValue(KeyValue,NULL,&nLen);
this->m_strSign = KeyValue;
memset(KeyValue,0,sizeof(KeyValue));
reg.QueryValue(KeyValue,"User",&nLen);
this->m_strUserName = KeyValue;
memset(KeyValue,0,sizeof(KeyValue));
reg.QueryValue(KeyValue,"pwd",&nLen);
this->m_strPassword = KeyValue;
reg.Close();
return 0;
}
void CvckbaseView::OnVckbase32774()
{
// TODO: 在此添加命令处理程序代码
CUserInfo dlg(this,m_strUserName,m_strPassword);
if(dlg.DoModal()==IDOK)
{
m_strUserName = dlg.m_strUserName;
m_strPassword = dlg.m_strPassword;
CRegKey reg;
char KeyName[]="Software\\www.hotlove.cn";
reg.Open(HKEY_CURRENT_USER,KeyName);
reg.SetValue(m_strUserName,"User");
reg.SetValue(m_strPassword,"pwd");
reg.Close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -