Web网页表单
来源:互联网 发布:少女前线mac-10和mp5 编辑:程序博客网 时间:2024/05/21 11:27
#include <windows.h>
#include <stdio.h>
#include <exdisp.h>
#include <mshtml.h>
#include <objbase.h>
#include <atlbase.h>
#include <oleacc.h>
//#define _WIN32_DCOM
/*class CComDispatchDriver
{
public:
IDispatch* p;
CComDispatchDriver()
{ p = NULL; }
CComDispatchDriver(IDispatch * lp)
{
if((p = lp) != NULL)
p->AddRef();
}
CComDispatchDriver(IUnknown *lp)
{//从这个函数可以看出,如果QueryInterface失败,这个类是不会发出通知的
p = NULL;
if(lp != NULL)
lp->QueryInterface(IID_IDispatch,(void**)&p);
}
};*/
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; //窗口函数声明
BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow) //WinMain函数说明
{
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ; //窗口句柄
MSG msg ; //消息结构
WNDCLASS wndclass ; //窗口类结构
//下面是窗口类的定义
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;//加载图标供程序使用
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; //加载鼠标指针供程序使用
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;//获取一个图形对象,在这个例子中,是获取绘制窗口背景的刷子
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
//下面是窗口类的注册
if (!RegisterClass (&wndclass))//为程序窗口注册窗口类
{
return 0 ;
}
//根据窗口类创建窗口
hwnd = CreateWindow (szAppName, TEXT ("一个简单的Win32程序"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
) ;
//InitCommonControls();//link comctl32.lib
CoInitialize(0);
IWebBrowser2* pWebBrowser2=NULL;
IWebBrowser2* ptst;
HWND hWnd;
HINSTANCE hInst=::LoadLibrary("OLEACC.DLL");
hWnd=FindWindow("IEFrame",NULL);
IStream* pStream=NULL;
HWND hWndChild;
::EnumChildWindows(hWnd,EnumChildProc,(LPARAM)&hWndChild);
if(hWndChild)
{
HRESULT hr;
CComPtr<IHTMLDocument2> spDoc;
/*LPFNACCESSIBLEOBJECTFROMWINDOW pfAccessibleObjectFromWindow=(LPFNACCESSIBLEOBJECTFROMWINDOW)::GetProcAddress(hInst,"AccessibleObjectFromWindow");
CComPtr<IAccessible> spAccess;
hr=pfAccessibleObjectFromWindow(hWnd,0,IID_IAccessible,(void**)&spAccess);
CComPtr<IServiceProvider> spServiceProv;
hr=spAccess->QueryInterface(IID_IServiceProvider,(void**)&spServiceProv);
CComPtr<IHTMLWindow2> spWin;
hr=spServiceProv->QueryService(IID_IHTMLWindow2,IID_IHTMLWindow2,(void**)&spWin);*/
LRESULT lRes;
UINT nMsg=::RegisterWindowMessage("WM_HTML_GETOBJECT");
::SendMessageTimeout(hWndChild,nMsg,0L,0L,SMTO_ABORTIFHUNG,1000,(DWORD*)&lRes);
LPFNOBJECTFROMLRESULT pfObjectFromLresult=(LPFNOBJECTFROMLRESULT)::GetProcAddress(hInst,"ObjectFromLresult");
hr=(*pfObjectFromLresult)(lRes,IID_IHTMLDocument2,0,(void**)&spDoc);
if(SUCCEEDED(hr))
{
CComPtr<IHTMLWindow2> spWnd2;
CComPtr<IServiceProvider> spServiceProv;
hr=spDoc->get_parentWindow((IHTMLWindow2**)&spWnd2);
if(SUCCEEDED(hr))
{
hr=spWnd2->QueryInterface(IID_IServiceProvider,(void**)&spServiceProv);
if(SUCCEEDED(hr))
{
hr=spServiceProv->QueryService(IID_IWebBrowserApp,IID_IWebBrowser2,(void**)&pWebBrowser2);
if(SUCCEEDED(hr))
{
ptst=pWebBrowser2;
USES_CONVERSION;
CComPtr<IDispatch> spDispDoc;
hr=ptst->get_Document(&spDispDoc);
CComQIPtr<IHTMLDocument2> spDocument2;
spDispDoc->QueryInterface(IID_IHTMLDocument2,(void**)&spDocument2);
CComPtr<IHTMLElementCollection> spElementCollection;
hr=spDocument2->get_forms(&spElementCollection);//get form number
long nFormCount=0;
hr=spElementCollection->get_length(&nFormCount);
for(long i=0; i<nFormCount; i++)
{
IDispatch* pDisp=NULL;
hr=spElementCollection->item(CComVariant(i),CComVariant(),&pDisp);
if(FAILED(hr))
continue;
CComQIPtr<IHTMLFormElement> spFormElement;
hr=pDisp->QueryInterface(IID_IHTMLFormElement,(void**)&spFormElement);
if(FAILED(hr))
continue;
pDisp->Release();
long nElemCount=0;
hr=spFormElement->get_length(&nElemCount);//get form area域 number
if(FAILED(hr))
continue;
CComQIPtr<IHTMLElement> pElement;
for(long j=0; j<nElemCount; j++)
{
IDispatch* spDispatch=NULL;
hr=spFormElement->item(CComVariant(j),CComVariant(),&spDispatch);
if(FAILED(hr))
continue;
pElement=spDispatch;
spDispatch->Release();
BSTR bstr;
hr=pElement->get_tagName(&bstr);
if(FAILED(hr)) continue;
VARIANT vv;
hr=pElement->getAttribute(CComBSTR("type"),0,&vv);//"text" "hidden" "submit"
if(FAILED(hr)) continue;
CComBSTR tst,tes1;
BSTR tes,tes2;
if(*vv.bstrVal==*SysAllocString(L"text"))
{
CComPtr <IHTMLInputTextElement> pInputTextElement;
hr=pElement->QueryInterface(IID_IHTMLInputTextElement,(void**)&pInputTextElement);
if(FAILED(hr))
continue;
CComBSTR sInputText;
hr=pInputTextElement->get_type(&sInputText);
if(FAILED(hr))
continue;
tes=sInputText.m_str;
tes1.Attach(SysAllocString(L"text"));
tes2=tes1.m_str;
if(*tes==*tes2)
{
BSTR myAttachBSTR = SysAllocString(L"359412094@qq.com");
tst.Attach(myAttachBSTR);
pInputTextElement->put_value(tst);
}
}
else if(*vv.bstrVal==*SysAllocString(L"password"))
{
CComPtr <IHTMLInputTextElement> pInputPassElement;
hr=pElement->QueryInterface(IID_IHTMLInputTextElement,(void**)&pInputPassElement);
if(FAILED(hr))
continue;
CComBSTR sInputPass;
hr=pInputPassElement->get_type(&sInputPass);
if(FAILED(hr))
continue;
tes=sInputPass.m_str;
tes1.Attach(SysAllocString(L"password"));
tes2=tes1.m_str;
if(*tes==*tes2)
{
tst.Attach(SysAllocString(L"112101jiefei"));
pInputPassElement->put_value(tst);
}
}
else if(*vv.bstrVal==*SysAllocString(L"submit"))
{
CComPtr <IHTMLElement> pClickElement;
hr=pElement->QueryInterface(IID_IHTMLElement,(void**)&pClickElement);
if(FAILED(hr))
continue;
hr=pClickElement->click();
}
}
}
}
}
}
}
pWebBrowser2->Release();
ptst->Release();
::FreeLibrary(hInst);
}
CoUninitialize();
//显示窗口
ShowWindow(hwnd,iCmdShow);
ShowWindow(hWnd,SW_MAXIMIZE);
UpdateWindow (hwnd) ; //指示窗口刷新自身
UpdateWindow (hWnd) ; //指示窗口刷新自身
//消息循环
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ; //转换某些键盘消息
DispatchMessage (&msg) ; //将消息发送给窗口过程
}
return msg.wParam;
}
//窗口函数
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{ HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ; //开始窗口绘制
GetClientRect (hwnd, &rect) ; //获取窗口客户区的尺寸
// DrawText (hdc, TEXT ("Hello World!"), -1, &rect,
// DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; //显示Hello World,可以修改程序你要显示的内容
//navigate("http://uasm.banzhu.com/");
EndPaint (hwnd, &ps) ; //结束窗口绘制
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ; //在消息队列中插入一条“退出”消息
return 0 ;
case WM_CHAR:
char szWang[20];
sprintf(szWang,"char is %d.",wParam);
::MessageBox(hwnd,szWang,NULL,IDOK);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);//执行默认的消息处理
}
BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
{
TCHAR buf[100];
::GetClassName( hwnd, (LPTSTR)&buf, 100 );
if ( strcmp( buf, ("Internet Explorer_Server") ) == 0 )
{
*(HWND*)lParam = hwnd; return FALSE;
}
else return TRUE;
}
- Web网页表单
- Web表单
- web表单
- web表单
- Web表单
- 《web scraping with python》笔记--穿越网页表单与登录窗口进行采集
- java web从网页表单输入数据存储到MySQL数据库
- 自动填写网页表单
- 自动填写网页表单
- 网页表单java验证
- 网页中的表单
- 网页表单序列化
- 静态网页的表单
- web网页
- Web 网页
- Flask Web 开发 web表单
- Flask web 开发--web表单
- 猫哥带你去战斗——Java Web开发——网页篇[4]——表单
- 64位RHEL6.2上安装oracle10gR2
- 思绪 冬天 雪 春天
- 给一个日期取出三个月中的星期一,星期三,星期五,星期日.
- android开发录音和播放录音的例子
- 解决 Agent admitted failure to sign using the key 问题 with ssh
- Web网页表单
- 2012.12.18 日志
- Android OpenGL ES 简明开发教程 07 <材质渲染>
- Google新算法表明SEOer需要转型升级
- 用C语言实现解析简单配置文件的小工具
- 死锁
- 评论:婚恋网站实名制何去何从
- silverlight 中的 userState 参数
- QT中使用另外的线程运行定时器