void Update() { CDC dc = GetDC(m_hWnd); CDC dcMemory; dcMemory.CreateCompatibleDC(dc); CRect rect; GetClientRect(m_hWnd, &rect); // // 注意:一定要自己创建一个 32 位位图,不要 CreateCompatibleBitmap,否则远程协助下可能无法正常显示 // BITMAPINFOHEADER bmih = { sizeof(BITMAPINFOHEADER) }; bmih.biWidth = rect.Width(); bmih.biHeight = rect.Height(); bmih.biPlanes = 1; bmih.biBitCount = 32; // !注意:要 32 位 bmih.biCompression = BI_RGB; BYTE *pBits = NULL; HBITMAP hBitmap = CreateDIBSection(NULL, (BITMAPINFO *)&bmih, 0, (LPVOID *)&pBits, NULL, 0); if (hBitmap == NULL) { return; } CBitmap bmp(hBitmap); dcMemory.SelectBitmap(bmp); { Graphics g(dcMemory); g.SetInterpolationMode(InterpolationModeNearestNeighbor); g.SetPixelOffsetMode(PixelOffsetModeHalf); // Rendering... } POINT pt = { 0, 0}; BLENDFUNCTION stBlend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; SIZE szWindow = { rect.Width(), rect.Height() }; UpdateLayeredWindow(m_hWnd, dc, NULL, &szWindow, dcMemory, &pt, 0, &stBlend, ULW_ALPHA); } |