直接上程序:
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); }