我尝试使用标准COLOR_BTNFACE
纯色和FillRect()
填充Windows上的屏幕外位图/设备上下文。但是,在葡萄酒上,我从下面的程序中得到this。 Windows 7显示this,Windows XP显示... this。我迷失了我做错的事,但我确定奇怪的模式是不对的,我知道黑色不是按钮面颜色,因为窗口看起来没有自定义颜料。
我尝试了以下所有方法;他们表现出同样的道理:
FillRect(rdc, &rrect, (HBRUSH) (COLOR_BTNFACE + 1));
FillRect(rdc, &rrect, GetSystemColorBrush(COLOR_BTNFACE));
FillRect(rdc, &rrect, GetSolidBrush(GetSysColor(COLOR_BTNFACE)));
对于GetDeviceCaps(BITSPIXEL)
和屏幕外设备上下文, BeginPaint()
返回32; COLORRES
返回24。
可能相关吗?我正在运行的实际程序中Here's the output,它会使用AlphaBlend()
向此DC添加另一张图片;这导致其他人建议我不小心使用单色DC?因此,上一段中的信息
我在这里做错了什么?感谢。
程序:
// pietro gagliardi - 11-12 april 2014
#define _UNICODE
#define UNICODE
#include <stdio.h>
#include <windows.h>
// this test program doesn't check drawing errors; I have done so in the actual program and there are none
void paintwin(HWND hwnd)
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
RECT updaterect = ps.rcPaint;
// this is the DC that will be drawn to hdc
HDC rdc = CreateCompatibleDC(hdc);
HBITMAP rbitmap = CreateCompatibleBitmap(rdc,
updaterect.right - updaterect.left,
updaterect.bottom - updaterect.top);
HBITMAP prevrbitmap = SelectObject(rdc, rbitmap);
RECT rrect = { 0, 0, updaterect.right - updaterect.left, updaterect.bottom - updaterect.top };
FillRect(rdc, &rrect, (HBRUSH) (COLOR_BTNFACE + 1));
BitBlt(hdc, updaterect.left, updaterect.top,
updaterect.right - updaterect.left,
updaterect.bottom - updaterect.top,
rdc, 0, 0, SRCCOPY);
SelectObject(rdc, prevrbitmap);
DeleteObject(rbitmap);
DeleteDC(rdc);
EndPaint(hwnd, &ps);
}
LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch (msg) {
case WM_PAINT:
paintwin(hwnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wparam, lparam);
}
int getnCmdShow()
{
STARTUPINFO si;
GetStartupInfo(&si);
if ((si.dwFlags & STARTF_USESHOWWINDOW) != 0)
return si.wShowWindow;
return SW_SHOWDEFAULT;
}
int main(int argc, char *argv[])
{
WNDCLASS cls;
MSG msg;
HWND mainwin;
HINSTANCE hInstance = GetModuleHandle(NULL);
int nCmdShow = getnCmdShow();
ZeroMemory(&cls, sizeof (WNDCLASS));
cls.lpszClassName = L"mainwin";
cls.lpfnWndProc = wndproc;
cls.hInstance = hInstance;
cls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
cls.hCursor = LoadCursor(NULL, IDC_ARROW);
cls.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
if (RegisterClass(&cls) == 0) {
fprintf(stderr, "registering window class failed: %lu\n", GetLastError());
return 1;
}
mainwin = CreateWindowEx(0,
L"mainwin", L"mainwin",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if (mainwin == NULL) {
fprintf(stderr, "opening main window failed: %lu", GetLastError());
return 1;
}
ShowWindow(mainwin, nCmdShow);
UpdateWindow(mainwin);
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
答案 0 :(得分:-1)
错误确实是您正在使用单色位图。
CreateCompatibleBitmap(rdc, ...);
问题是rdc
选择了默认的1x1单色位图。相反,你需要
CreateCompatibleBitmap(hdc, ...);