您的位置:首页 > 编程语言 > C语言/C++

小程序:VC++修改Windows桌面背景为黑白灰色(WinXP、Win7 64位)

2015-02-07 20:49 453 查看
直接上程序:

void CTestDlg::DoIt()
{
// TODO: Add your control notification handler code here

LARGE_INTEGER litmp;
LONGLONG qt1,qt2;
double dft,dff,dfm;

//获得时钟频率
QueryPerformanceFrequency(&litmp);//获得时钟频率
dff=(double)litmp.QuadPart;

//获得初始值
QueryPerformanceCounter(&litmp);
qt1=litmp.QuadPart;

HDC   hScrDC, hScreen;
HBITMAP   hBitmap;
hScreen = ::CreateDC("DISPLAY", NULL, NULL, NULL);
hScrDC   =::CreateCompatibleDC(hScreen);

int w = GetDeviceCaps(hScreen, HORZRES);
int h = GetDeviceCaps(hScreen, VERTRES);

hBitmap = CreateCompatibleBitmap(hScreen, w,h);

if (hBitmap == 0)
{
AfxMessageBox("hbmScreen");
}

if (!SelectObject(hScrDC, hBitmap))
{
AfxMessageBox("Compatible Bitmap Selection");
}

if (!BitBlt(hScrDC,0,0, w, h, hScreen, 0,0, SRCCOPY))
{
AfxMessageBox("BitBlt");
}

COLORREF rgb = 0;

for (int i=0; i<w; i++)
{
for (int j=0; j<h; j++)
{
rgb = ::GetPixel(hScrDC, i, j);
//int r = GetBValue(rgb);
int g = GetGValue(rgb);
//int b = GetRValue(rgb);
rgb = RGB(g, g, g);
::SetPixel(hScrDC, i, j, rgb);
}
}

if (!BitBlt(hScreen,0,0, w, h, hScrDC, 0,0, SRCCOPY))
{
AfxMessageBox("BitBlt");
}

//获得终止值
QueryPerformanceCounter(&litmp);
qt2=litmp.QuadPart;

//获得对应的时间值,转到毫秒单位上
dfm=(double)(qt2-qt1);
dft=dfm/dff;
CString str;
str.Format("修改完成,耗时: %.3f秒", dft);
SetWindowText(str);

DeleteObject(hBitmap);
DeleteDC(hScrDC);
DeleteDC(hScreen);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: