定时自动打开网页并截图
2017-01-09 10:53
267 查看
由于工作原因,需要定时获取某个网站的信息,该程序可以提供无人监管的自动截图
1、主程序
2、头文件sc.h与stdafx.h
sc.h
void Screen(char filename[]);
stdafx.h
3、sc.cpp
1、主程序
#include <windows.h> #include<iostream> #include "stdafx.h" #include "sc.h" #include <string> using namespace std; int main() { while(1) { SYSTEMTIME ct; GetLocalTime(&ct);//local time cout<<ct.wYear<<"年"<<ct.wMonth<<"月"<< ct.wDay<<"日"<<ct.wHour<<"时"<< ct.wMinute<<"分"<<ct.wSecond<<"秒"<< " (整点第10分钟截图)"<<endl; char ch_time[64]; sprintf(ch_time,"%d.%d.%d_%d-%d-%d",ct.wYear,ct.wMonth,ct.wDay,ct.wHour,ct.wMinute,ct.wSecond); Sleep(1000); if(ct.wMinute==10 && ct.wSecond==0) { ShellExecute(NULL, L"open", L"IEXPLORE", L"https://www.aqistudy.cn/", NULL,SW_SHOWMAXIMIZED); Sleep(10000); string str_time_now; str_time_now.append(ch_time).append(".jpg"); char pic_name[64] = {0}; strcat(pic_name,str_time_now.c_str()); Screen(pic_name); } } return 0; }
2、头文件sc.h与stdafx.h
sc.h
void Screen(char filename[]);
stdafx.h
#pragma once #define WIN32_LEAN_AND_MEAN // 从 Windows 头中排除极少使用的资料 #include <tchar.h>
3、sc.cpp
#include "stdafx.h" #include <afxwin.h> void Screen(char filename[]) { CDC *pDC;//屏幕DC pDC = CDC::FromHandle(GetDC(NULL));//获取当前整个屏幕DC int BitPerPixel = pDC->GetDeviceCaps(BITSPIXEL);//获得颜色模式 int Width = pDC->GetDeviceCaps(HORZRES); int Height = pDC->GetDeviceCaps(VERTRES); printf("当前截屏时间: ", BitPerPixel); CDC memDC;//内存DC memDC.CreateCompatibleDC(pDC); CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap memBitmap.CreateCompatibleBitmap(pDC, Width, Height); oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC memDC.BitBlt(0, 0, Width, Height, pDC, 0, 0, SRCCOPY);//复制屏幕图像到内存DC //以下代码保存memDC中的位图到文件 BITMAP bmp; memBitmap.GetBitmap(&bmp);//获得位图信息 FILE *fp = fopen(filename, "w+b"); BITMAPINFOHEADER bih = {0};//位图信息头 bih.biBitCount = bmp.bmBitsPixel;//每个像素字节大小 bih.biCompression = BI_RGB; bih.biHeight = bmp.bmHeight;//高度 bih.biPlanes = 1; bih.biSize = sizeof(BITMAPINFOHEADER); bih.biSizeImage = bmp.bmWidthBytes * bmp.bmHeight;//图像数据大小 bih.biWidth = bmp.bmWidth;//宽度 BITMAPFILEHEADER bfh = {0};//位图文件头 bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);//到位图数据的偏移量 bfh.bfSize = bfh.bfOffBits + bmp.bmWidthBytes * bmp.bmHeight;//文件总的大小 bfh.bfType = (WORD)0x4d42; fwrite(&bfh, 1, sizeof(BITMAPFILEHEADER), fp);//写入位图文件头 fwrite(&bih, 1, sizeof(BITMAPINFOHEADER), fp);//写入位图信息头 byte * p = new byte[bmp.bmWidthBytes * bmp.bmHeight];//申请内存保存位图数据 GetDIBits(memDC.m_hDC, (HBITMAP) memBitmap.m_hObject, 0, Height, p, (LPBITMAPINFO) &bih, DIB_RGB_COLORS);//获取位图数据 fwrite(p, 1, bmp.bmWidthBytes * bmp.bmHeight, fp);//写入位图数据 delete [] p; fclose(fp); memDC.SelectObject(oldmemBitmap); }
相关文章推荐
- 定时自动关闭程序、打开网页和隐藏任务计划
- windows下定时自动打开某网页并在访问结束后自动关闭浏览器
- 网页打开后自动执行木马
- 解决修改系统时间的病毒 & 自动打开某些网页并修改了默认登陆页面
- 手动修改注册表来解决开机自动打开网页的问题
- 设置计划任务定时打开网页
- 在登陆脚本中设置自动打开某个网页
- 讨论windows7下 IE8.0不能打开网页,但是能够上QQ问题。Windows 无法自动检测此网络的代理设置。
- JavaScript打开网页自动最大化(兼容IE,FF)
- Inno 4000 Setup安装、卸载时判断是否程序正在运行,安装完成时自动打开网页的脚本
- 打开一个窗体后自动关闭当前网页可行办法
- 解决修改系统时间的病毒 & 自动打开某些网页并修改了默认登陆页面
- javascript--打开网页自动最大化(兼容IE,ff)
- 网页打开后自动最大化
- 每天第一次打开网页自动跳转【问题研究】
- 网页打开时自动窗口最大化JS代码
- 定时打开网页
- 网页自动刷新 或者定时跳转的简单写法
- 搜索框输入内容回车后如何触发搜索按钮,自动打开网页
- 网页自动定时刷新的代码-html定时刷新代码-asp时刷新代码