GDI+ 双缓存 和 刷新桌面(F5)

GDI+双缓存

    POINT currentPoint;
    GetCursorPos(&currentPoint);
    HWND hWnd = ::GetDesktopWindow();
    int nWidth = GetSystemMetrics(SM_CXSCREEN);
    int nHeight = GetSystemMetrics(SM_CYSCREEN);
    RECT r;
    GetWindowRect(hWnd, &r);
    Bitmap bmp(nWidth, nHeight);
    Graphics mem_graphic(&bmp);
    mem_graphic.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
    static bool bChange = false;
    Pen p(bChange ? Color(0, 255, 0) : Color(255, 0, 0));
    bChange = !bChange;
    Rect rt(currentPoint.x - 10, currentPoint.y - 10, 20, 20);
    mem_graphic.DrawEllipse(&p, rt);
    mem_graphic.DrawLine(&p,rt.X, currentPoint.y, rt.X + rt.Width, currentPoint.y);
    mem_graphic.DrawLine(&p,currentPoint.x, rt.Y, currentPoint.x , rt.Y + rt.Height);
    Rect rt_small(currentPoint.x - 5, currentPoint.y - 5, 10, 10);
    mem_graphic.DrawEllipse(&p, rt_small);

    HDC hDC= ::GetDC(hWnd);
    Graphics graphics(hDC);
    CachedBitmap cachedBmp(&bmp,&graphics);   //important
    graphics.DrawCachedBitmap(&cachedBmp,0,0);

刷新桌面(F5)

        ::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSH, 0, 0);

 

posted @ 2016-11-23 18:14  程序员大叔  阅读(934)  评论(0编辑  收藏  举报