最近数字和金山吵的热火朝天的,群里有人说网友的投票可能有工具刷出来的,觉得应该很有意思,就想自己试一下,玩了半天终于可以操作页面进行投票了,但这个投票做了IP限制,所以工具也无用武之地啊!典型的需求没做好,反正也是自己玩,把过程记下来下给自己备忘一下:

   1:  
   2: #include "stdafx.h"
   3: #include <windows.h>
   4: #include <string>
   5: #include "gtest/gtest.h"
   6: #include "BrwHelperTest.h"
   7: //#include <wstring>
   8:  
   9:  
  10:  
  11: #include "EnumFormVal.h"
  12:  
  13: #include <atlbase.h>
  14:  
  15: CComModule _Module;        // 由于要使用 CComDispatchDriver ATL的智能指针,
  16:                         // 所以声明它是必须的
  17:  
  18: #include <mshtml.h>        // 所有 IHTMLxxxx 的接口声明
  19: #include <atlcom.h>
  20:  
  21: #ifdef _DEBUG
  22: #define new DEBUG_NEW
  23: #undef THIS_FILE
  24: static char THIS_FILE[] = __FILE__;
  25: #endif
  26:  
  27: /
  28: // The one and only application object
  29:  
  30: using namespace std;
  31:  
  32: void EnumIE( void );                                //枚举浏览器函数
  33: void EnumFrame( IHTMLDocument2 * pIHTMLDocument2 );    //枚举子框架函数
  34: void EnumForm ( IHTMLDocument2 * pIHTMLDocument2 );    //枚举表单函数
  35:  
  36: bool bTrue = false;
  37:  
  38: int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
  39: {
  40:     
  41:     // ShellExecute(NULL,L"open", L"http://tech.qq.com/zt2010/360pkduba",L"",L"", SW_SHOW );
  42:  
  43:  
  44:     ::CoInitialize(NULL);    //初始化 COM 公寓
  45:  
  46:     int count = 0;
  47:     for(;;)
  48:     {
  49:         EnumIE();                //枚举浏览器
  50:         printf("tou piao : %d \n", count++);
  51:         printf("========================================================================\n");
  52:     }
  53:     
  54:  
  55:     ::CoUninitialize();        //释放 COM 公寓
  56:  
  57:     cout << _T("======完成======") << endl;
  58:  
  59:  
  60:     return 0;
  61: }
  62:  
  63: void EnumIE( void )
  64: {
  65:     cout << _T("开始扫描系统中正在运行的浏览器实例") << endl;
  66:  
  67:     CComPtr< IShellWindows > spShellWin;
  68:     HRESULT hr = spShellWin.CoCreateInstance( CLSID_ShellWindows );
  69:     if ( FAILED ( hr ) )
  70:     {
  71:         cout << _T("获取 IShellWindows 接口错误") << endl;
  72:         return;
  73:     }
  74:  
  75:     long nCount = 0;        // 取得浏览器实例个数(Explorer 和 IExplorer)
  76:     spShellWin->get_Count( &nCount );
  77:     if( 0 == nCount )
  78:     {
  79:         cout << _T("没有在运行着的浏览器") << endl;
  80:         return;
  81:     }
  82:  
  83:     for(int i=0; i<nCount; i++)
  84:     {
  85:         CComPtr< IDispatch > spDispIE;
  86:         hr=spShellWin->Item(CComVariant( (long)i ), &spDispIE );
  87:         if ( FAILED ( hr ) )    continue;
  88:  
  89:         CComQIPtr< IWebBrowser2 > spBrowser = spDispIE;
  90:         if ( !spBrowser )        continue;
  91:  
  92:         CComPtr < IDispatch > spDispDoc;
  93:         hr = spBrowser->get_Document( &spDispDoc );
  94:         if ( FAILED ( hr ) )    continue;
  95:  
  96:         CComQIPtr< IHTMLDocument2 > spDocument2 = spDispDoc;
  97:         if ( !spDocument2 )        continue;
  98:  
  99:         // 程序运行到此,已经找到了 IHTMLDocument2 的接口指针
 100:  
 101:         // 删除下行语句的注释,把浏览器的背景改变看看
 102:         // spDocument2->put_bgColor( CComVariant( "green" ) );
 103:         
 104:         EnumForm( spDocument2 );        //枚举所有的表单
 105:         if( bTrue )
 106:         {
 107:             return;
 108:         }
 109:     }
 110: }
 111:  
 112: void EnumFrame( IHTMLDocument2 * pIHTMLDocument2 )
 113: {
 114:     if ( !pIHTMLDocument2 )    return;
 115:  
 116:     HRESULT hr;
 117:  
 118:     CComPtr< IHTMLFramesCollection2 > spFramesCollection2;
 119:     pIHTMLDocument2->get_frames( &spFramesCollection2 );    //取得框架frame的集合
 120:  
 121:     long nFrameCount=0;                //取得子框架个数
 122:     hr = spFramesCollection2->get_length( &nFrameCount );
 123:     if ( FAILED ( hr ) || 0 == nFrameCount )    return;
 124:  
 125:     for(long i=0; i<nFrameCount; i++)
 126:     {
 127:         CComVariant vDispWin2;        //取得子框架的自动化接口
 128:         hr = spFramesCollection2->item( &CComVariant(i), &vDispWin2 );
 129:         if ( FAILED ( hr ) )    continue;
 130:  
 131:         CComQIPtr< IHTMLWindow2 > spWin2 = vDispWin2.pdispVal;
 132:         if( !spWin2 )    continue;    //取得子框架的 IHTMLWindow2 接口
 133:  
 134:         CComPtr < IHTMLDocument2 > spDoc2;
 135:         spWin2->get_document( &spDoc2 );    //取得字框架的 IHTMLDocument2 接口
 136:  
 137:         EnumForm( spDoc2 );            //递归枚举当前子框架 IHTMLDocument2 上的表单form
 138:  
 139:         if( bTrue )
 140:         {
 141:             return;
 142:         }
 143:     }
 144: }
 145:  
 146: void EnumForm( IHTMLDocument2 * pIHTMLDocument2 )
 147: {
 148:     if( !pIHTMLDocument2 )    return;
 149:  
 150:     EnumFrame( pIHTMLDocument2 );    //递归枚举当前 IHTMLDocument2 上的子框架fram
 151:  
 152:     HRESULT hr;
 153:     CComBSTR bstrTitle;
 154:     pIHTMLDocument2->get_title( &bstrTitle );    //取得文档标题
 155:  
 156:     USES_CONVERSION;
 157:     cout << _T("开始枚举“") << OLE2CT( bstrTitle ) << _T("”的表单") << endl;
 158:     CComQIPtr< IHTMLElementCollection > spElementCollection;
 159:     hr = pIHTMLDocument2->get_forms( &spElementCollection );    //取得表单集合
 160:     if ( FAILED( hr ) )
 161:     {
 162:         wcout << L"获取表单的集合 IHTMLElementCollection 错误" << endl;
 163:         return;
 164:     }
 165:  
 166:     long nFormCount=0;                //取得表单数目
 167:     hr = spElementCollection->get_length( &nFormCount );
 168:     if ( FAILED( hr ) )
 169:     {
 170:         wcout << L"获取表单数目错误" << endl;
 171:         return;
 172:     }
 173:     
 174:     for(long i=0; i<nFormCount; i++)
 175:     {
 176:         IDispatch *pDisp = NULL;    //取得第 i 项表单
 177:         hr = spElementCollection->item( CComVariant( i ), CComVariant(), &pDisp );
 178:         if ( FAILED( hr ) )        continue;
 179:  
 180:         CComQIPtr< IHTMLFormElement > spFormElement = pDisp;
 181:         pDisp->Release();
 182:  
 183:         long nElemCount=0;            //取得表单中 域 的数目
 184:         hr = spFormElement->get_length( &nElemCount );
 185:         if ( FAILED( hr ) )        continue;
 186:  
 187:         int count = 0;
 188:         for(long j=0; j<nElemCount; j++)
 189:         {
 190:             CComDispatchDriver spInputElement;    //取得第 j 项表单域
 191:             hr = spFormElement->item( CComVariant( j ), CComVariant(), &spInputElement );
 192:             if ( FAILED( hr ) )    continue;
 193:  
 194:             CComVariant vName,vVal,vType;        //取得表单域的 名,值,类型
 195:             hr = spInputElement.GetPropertyByName( L"name", &vName );
 196:             if( FAILED( hr ) )    continue;
 197:             hr = spInputElement.GetPropertyByName( L"value", &vVal );
 198:             if( FAILED( hr ) )    continue;
 199:             hr = spInputElement.GetPropertyByName( L"type", &vType );
 200:             if( FAILED( hr ) )    continue;
 201:  
 202:             LPCTSTR lpName = vName.bstrVal?
 203:                     OLE2CT( vName.bstrVal ) : L"NULL";    //未知域名
 204:             LPCTSTR lpVal  = vVal.bstrVal?
 205:                     OLE2CT( vVal.bstrVal  ) :L"NULL";    //空值,未输入
 206:             LPCTSTR lpType = vType.bstrVal?
 207:                     OLE2CT( vType.bstrVal ) : L"NULL";    //未知类型
 208:  
 209:             wcout << L"[" << lpType << L"] ";
 210:             wcout << lpName << L" = " << lpVal << endl;
 211:             wstring typeradio = L"radio";
 212:             if ( typeradio.compare(lpType) == 0)
 213:             {
 214:                 count++;
 215:                 if(count == 2 ||
 216:                     count == 5 ||
 217:                     count == 7 ||
 218:                     count == 10)
 219:                 {
 220:                     spInputElement.PutPropertyByName(OLESTR("checked"), &CComVariant(true));
 221:                 }
 222:             }
 223:  
 224:             typeradio = L"submit";
 225:             if ( typeradio.compare(lpType) == 0)
 226:             {
 227:                 CComQIPtr< IHTMLElement > spSingleElement;
 228:                 hr = spInputElement->QueryInterface( IID_IHTMLElement , (void**)&spSingleElement); 
 229:                 if( FAILED( hr ) )
 230:                     continue; 
 231:                 hr = spSingleElement->click(); 
 232:                 bTrue = true;
 233:                 return;
 234:  
 235:             }
 236:         }
 237:     }
 238: }

转载于:https://www.cnblogs.com/GnagWang/archive/2010/06/05/1752174.html

试玩C++ 操作页面控件相关推荐

  1. Silverlight实用窍门系列:51.Silverlight页面控件的放大缩小、Silverlight和Html控件的互相操作...

    本节将讲述三个Silverlight中应用的小技巧:Silverlight页面的放大缩小.Silverlight操作Html.Html操作Silverlight控件. 一.Silverlight页面的 ...

  2. C#多线程操作界面控件的解决方案

    C#中利用委托实现多线程跨线程操作 - 张小鱼 2010-10-22 08:38 在使用VS2005的时候,如果你从非创建这个控件的线程中访问这个控件或者操作这个控件的话就会抛出这个异常.这是微软为了 ...

  3. 股票量化分析工具QTYX使用攻略——页面控件功能导览v2.5.1

    搭建自己的量化系统 如果要长期在市场中立于不败之地!必须要形成一套自己的交易系统.否则,赚钱或者亏钱我们很难归纳总结,往往是凭借运气赚钱,而不是合理的系统模型,一时凭借运气赚的钱长期来看会因为实力还回 ...

  4. webdriver高级应用- 操作日期控件

    1. 通过点击的方式操作日期控件 #encoding=utf-8 from selenium import webdriver import unittest, time, traceback fro ...

  5. C#线程操作UI控件

    在写winform程序时候,如果时间长的操作不用线程操作.那么会卡死UI,点击界面就体现为未响应.为此需要对耗时操作用线程处理,比如检验的监听程序就是一个死循环,不停检查文件夹或数据库又没有数据,然后 ...

  6. Xamarin iOS教程之页面控件

    Xamarin iOS教程之页面控件 Xamarin iOS 页面控件 在iPhone手机的主界面中,经常会看到一排小白点,那就是页面控件,如图2.44所示.它是由小白点和滚动视图组成,可以用来控制翻 ...

  7. C# 采用系统委托的方式处理线程内操作窗体控件(转载)

    C# 采用系统委托的方式处理线程内操作窗体控件 C# / asp.net / j 2009-12-25 10:04:47 阅读138 评论0   字号:大中小 订阅 一.System.Windows. ...

  8. 一个.net的系统的AOP设计思路二——页面控件校验映射

    3)写页面控件校验映射.我们的基础是建立在验证控件的基础上的.配置文件如下: <?xml version="1.0" encoding="utf-8" ? ...

  9. JS判断页面控件是否可用

    JS判断页面控件是否可用[原创] 2009-12-08 16:27 如果你看到这篇文章,甚至目前正愁于该问题的困扰,希望你把这篇文章看完.至少下次不会在这个问题上浪费时间. 近期做的项目中涉及到页面控 ...

最新文章

  1. Vue:echarts的柱状图为什么X轴上的文字不显示?
  2. 缓冲流、转换流、序列化流代码练习
  3. python hashlib模块(提供常见摘要算法)
  4. python设计_设计和历史常见问题
  5. Exchange企业实战技巧(15)启用向外部联系人发送邮件时的提醒
  6. Python数据结构学习笔记——链表:无序链表和有序链表
  7. vc6.0添加注释快捷键
  8. 有mysql文件怎么运行不了_MySQL安装常见问题(找不到文件,系统服务无法启动...)...
  9. 以太坊中的GHOST协议
  10. 几何视角下的线性代数(3)---基与特征
  11. 基本医疗保险如何看门诊
  12. scratch实现弹跳小球2
  13. MinIO异常the region is wrong; expecting ‘us-east-1‘
  14. [渗透]缓慢的HTTP拒绝服务攻击原理、利用和防范
  15. linux安装系统d,matebookD安装linux系统总结
  16. 追加贷显示服务器出错,小蜜蜂财务软件常见问题汇总
  17. Carla在Windows上的安装与运行
  18. Unity实用功能之读写Excel表格
  19. 轻松查询多个韵达快运最后物流中含有某个地方的单号
  20. 迈向更小的.NET 4-有关客户端配置文件和下载.NET的详细信息

热门文章

  1. LeetCode MySQL 1581. 进店却未进行过交易的顾客
  2. LintCode 434. 岛屿的个数II(并查集)
  3. 天池 在线编程 LR String
  4. 05.序列模型 W2.自然语言处理与词嵌入
  5. LeetCode 1533. Find the Index of the Large Integer(二分查找)
  6. LeetCode 937. 重新排列日志文件(自定义排序)
  7. java impala_Java实现impala操作kudu
  8. fileinputstream_Java I/O 流之 FileInputStream
  9. os、os.path、shutil操作文件和文件路径的常用方法总结
  10. php mqtt qos,Mqtt Qos 深度解读