博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++桌面显示恶搞
阅读量:3785 次
发布时间:2019-05-22

本文共 1943 字,大约阅读时间需要 6 分钟。

整理篇

今日整理了一下自己的电脑,翻出了一些开始学习时觉得有意思的代码。我一直觉得编程始于兴趣,也强于兴趣,兴趣是我们学习最好的老师。虽然这里给出的代码没什么难度,获取可以说很简单,但这还是我好多年前学C++时学习的一个Windows编程的程序,希望能帮助正在初学的小伙伴们。

展示

先看看效果图吧

在这里插入图片描述

正如图片所示,这只是一个让桌面错乱的一个程序。通过windows API很容易的实现。

注意 这里是windows程序,所以需要你是用vs的时候创建windows新项目(空白项就可以了)。

#include 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){ HWND hwnd; const int NUM = 500; /// 锁定指定窗口,禁止它更新 /// GetDesktopWindow() 用于返回桌面窗口的句柄 if (LockWindowUpdate(hwnd = GetDesktopWindow())) { HDC hdcScr = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_LOCKWINDOWUPDATE); ///创建兼容DC HDC hdcMem = CreateCompatibleDC(hdcScr); /// 获取系统当前的分辨率,宽像素 和 高像素 int cxClient = GetSystemMetrics(SM_CXSCREEN) / 10; int cyClient = GetSystemMetrics(SM_CYSCREEN) / 10; /// 创建兼容位图 HBITMAP hBitmap = CreateCompatibleBitmap(hdcScr, cxClient, cyClient); SelectObject(hdcMem, hBitmap); srand((int)GetCurrentTime()); int iKeep[NUM][4]; int x1, x2, y1, y2; for (int i = 0; i < 2; ++i) { for (int j = 0; j < NUM; ++j) { if (0 == i) { iKeep[j][0] = x1 = cxClient * (rand() % 10); iKeep[j][1] = y1 = cyClient * (rand() % 10); iKeep[j][2] = x2 = cxClient * (rand() % 10); iKeep[j][3] = y2 = cyClient * (rand() % 10); } else { x1 = iKeep[NUM - 1 - j][0]; y1 = iKeep[NUM - 1 - j][1]; x2 = iKeep[NUM - 1 - j][2]; y2 = iKeep[NUM - 1 - j][3]; } /// 对指定的源设备环境区域中的像素进行位块(bit_block)转换,以传送到目标设备环境 BitBlt(hdcMem, 0, 0, cxClient, cyClient, hdcScr, x1, y1, SRCCOPY); BitBlt(hdcScr, x1, y1, cxClient, cyClient, hdcScr, x2, y2, SRCCOPY); BitBlt(hdcScr, x2, y2, cxClient, cyClient, hdcMem, 0, 0, SRCCOPY); Sleep(10); } } DeleteDC(hdcMem); ReleaseDC(hwnd, hdcScr); DeleteObject(hBitmap); LockWindowUpdate(NULL); } return FALSE;}

代码就这么点,运行就行了,现在看来这些东西挺无趣,但想想当初还很兴奋的发给朋友,还特意改了图标名字。

在这里插入图片描述 这东西对于不了解的朋友以为我发了啥,当初也挺有意思的。

转载地址:http://kcktn.baihongyu.com/

你可能感兴趣的文章
机器学习实战第四章——朴素贝叶斯分类(源码解析)
查看>>
图像积分图的计算
查看>>
LBP特征原理及代码实现
查看>>
Robust Object Tracking via Sparsity-based Collaborative Model
查看>>
Visual Tracking via Adaptive Structural Local Sparse Appearance Model
查看>>
error LNK2001: 无法解析的外部符号 "__declspec(dllimport) void __cdecl google::InstallFailureSignalHandle
查看>>
无法解析的外部符号 "__int64 google::protobuf::internal::empty_string_once_init_"
查看>>
windows下无GPU的caffe的配置
查看>>
用caffe训练minist数据集
查看>>
lmdb编译过程中出现无法解析的外部符号 NtCreateSection
查看>>
opencv关于imread读不到图像的问题
查看>>
用caffe将自己的图像数据转换成lmdb
查看>>
caffe中计算图像的均值
查看>>
使用caffe训练自己的图像数据
查看>>
VS2013出现应用程序无法正常启动
查看>>
高斯模糊
查看>>
Online Object Tracking: A Benchmark
查看>>
Robust Object Tracking via Sparsity-based Collaborative Model
查看>>
Visual Tracking via Adaptive Structural Local Sparse Appearance Model
查看>>
Git多用户配置
查看>>