c++如何截取桌面

#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <atlimage.h>

#include <iostream>
#include <ctime>
#include <string>
using namespace std;


std::string getCurrentTime() {
	time_t now = time(0);
	tm *local = localtime(&now);
	char buf[80];
	strftime(buf, sizeof(buf), "%Y%m%d%H%M%S", local);
	return std::string(buf);
}


void ScreenShot()
{
	if (!PathIsDirectory(".\\ShotImg"))
	{
		CreateDirectory(".\\ShotImg", 0);
	}

	HDC hdcSrc = GetDC(NULL);
	int nBitPerPixel = GetDeviceCaps(hdcSrc, BITSPIXEL);
	int nWidth = GetDeviceCaps(hdcSrc, HORZRES);
	int nHeight = GetDeviceCaps(hdcSrc, VERTRES);
	CImage image;
	image.Create(nWidth, nHeight, nBitPerPixel);
	BitBlt(image.GetDC(), 0, 0, nWidth, nHeight, hdcSrc, 0, 0, SRCCOPY);
	ReleaseDC(NULL, hdcSrc);
	image.ReleaseDC();
	char bufName[128] = { 0 };
	static int si = 1;
	sprintf_s(bufName, 128, ".\\ShotImg\\%s_%d.png", getCurrentTime().c_str(), si++);
	image.Save(bufName, Gdiplus::ImageFormatPNG);
}

int main()
{
	int i = 0;
	while (i<20)
	{
		ScreenShot();
		i++;

		Sleep(500);
	}
	
	return 0;
}

结果:
在这里插入图片描述

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
截取vector数组的某一区间元素,可以使用以下两种方法: 方法一:使用函数CutArrs() ```cpp vector<int> CutArrs(vector<int>& Arrs, int begin, int end){ vector<int> result; result.assign(Arrs.begin() + begin, Arrs.begin() + end); return result; } ``` 这个函数接受一个vector数组Arrs,以及区间的左边界begin和右边界end(相对于Arrs.begin()的位置)。通过使用assign()函数,将Arrs中指定区间的元素赋值给新的vector数组result。最后返回result作为截取的结果。 方法二:使用迭代器 ```cpp vector<int> Arrs {1,2,3,4,5,6,7,8,9}; vector<int>::const_iterator First = Arrs.begin() + 1; vector<int>::const_iterator Second = Arrs.begin() + 2; vector<int> Arr2(First, Second); ``` 在这个方法中,我们先使用迭代器找到要截取的区间的起始位置和结束位置,然后使用这两个迭代器作为参数,直接初始化一个新的vector数组Arr2。这样就可以得到截取的结果。 注意:以上两种方法都是截取数组的左闭右开区间,即包含左边界,但不包含右边界。 <span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [C++容器vector的数组片段截取操作](https://blog.csdn.net/qq_40250056/article/details/114681940)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

发如雪-ty

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值