我通过让 GDI+ 绘制到内存设备上下文中解决了这个问题,然后我将它粘贴到屏幕上。对于 blitting,我使用标准的 GDI 函数,这给了我从右到左的权利。
作为一个例子,我在这里提交了用于创建渐变填充区域的代码。代码现在在 LTR 和 RTL 环境中运行,这意味着我们没有两个代码库来区分方向。
long srvDrawGradientFilledRect(HDC hdc,LPRECT lpFillingRect,
unsigned long startcolor, unsigned long endcolor, UINT uFlags)
{
BYTE red_end, red_start;
BYTE green_end, green_start;
BYTE blue_end, blue_start;
RECT FillingRect = *lpFillingRect;
int xSize;
int ySize;
int xPos;
int yPos;
xSize = (FillingRect.right - FillingRect.left);
ySize = (FillingRect.bottom - FillingRect.top);
xPos = FillingRect.left;
yPos = FillingRect.top;
// Create compatible device context.
HDC hdcMem = CreateCompatibleDC(hdc);
// Create compatible bitmap.
HBITMAP hbmMem = CreateCompatibleBitmap(hdc, xSize, ySize);
// Select bitmap into device context. (Bitmap holds all changes drawn in its DC.)
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hbmMem);
// endcolor in bytes
blue_end = (BYTE)(endcolor >> 16);
green_end = (BYTE)(endcolor >> 8);
red_end = (BYTE)(0x000000FF & endcolor);
// startcolor in bytes
blue_start = (BYTE)(startcolor >> 16);
green_start = (BYTE)(startcolor >> 8);
red_start = (BYTE)(0x000000FF & startcolor);
LinearGradientBrush linGrBrush(Point(0, 0), // starting point of the gradient
Point(0, ySize), // ending point of the gradient
Color(255, red_start, green_start, blue_start), // White starting color
Color(255, red_end, green_end, blue_end)); // End color
Graphics graphics(hdcMem);
graphics.SetCompositingMode(CompositingModeSourceCopy);
graphics.FillRectangle(&linGrBrush,0,0,xSize,ySize);
// a box is painted arround the gradient in the end color.
if (uFlags & ODRW_GRADIENT_OUTLINE) {
Pen pen(Color(255, red_end, green_end, blue_end), 1.0f);
graphics.DrawRectangle(&pen, 0, 0, xSize - 1, ySize);
}
BitBlt(hdc, FillingRect.left, FillingRect.top, xSize, ySize, hdcMem, 0, 0, SRCCOPY);
/* Cleanup*/
SelectObject(hdcMem, hbmOld);
DeleteObject(hbmMem);
DeleteDC(hdcMem);
return 1;
}
希望这有助于结合 GDI+ 解决 RTL 问题。
如果有更好的方法来解决这个问题,请告诉我。
碧玉