2014-04-12 9 views
1

FillRect()과 함께 COLOR_BTNFACE 표준 색상의 Windows에서 화면 비트 맵/장치 컨텍스트를 채우려고합니다. 그러나 와인에서는 아래 프로그램에서 this이 나옵니다. Windows 7은 this이고 Windows XP는 ... this입니다. 내가 뭘 잘못했는지는 모르겠지만 이상한 패턴이 맞는지는 확실하다. 그리고 검정색이 버튼의 얼굴 색이 아니라는 것을 안다. 창은 사용자 정의 페인트없이 바로 보인다. .winapi/gdi : FillRect (COLOR_BTNFACE)는 Windows 7 및 와인에서 이상한 격자 모양의 브러시로 채 웁니다. Windows XP에서 단색 검정색

나는 다음을 시도했다. 모두 BeginPaint()과 오프 스크린 디바이스 컨텍스트에 대한

FillRect(rdc, &rrect, (HBRUSH) (COLOR_BTNFACE + 1)); 
FillRect(rdc, &rrect, GetSystemColorBrush(COLOR_BTNFACE)); 
FillRect(rdc, &rrect, GetSolidBrush(GetSysColor(COLOR_BTNFACE))); 

GetDeviceCaps(BITSPIXEL) (32)을 반환 : 그들은 같은 일을 보여 COLORRES는 24를 반환합니다.

아마도 관련이 있습니까? Here's the output 나는 실행중인 실제 프로그램에서이 DC에 다른 그림을 추가합니다. AlphaBlend(); 이로 인해 다른 사람이 실수로 단발 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; 
} 

답변

-1

오류는 단색 비트 맵을 사용하고 있다는 사실이다.

CreateCompatibleBitmap(rdc, ...); 

문제는 rdc 그것으로 선택한 기본 × 1 흑백 비트 맵을 가지고 있다는 것입니다. 대신에 당신이 필요합니다

CreateCompatibleBitmap(hdc, ...); 
+0

'CreateSolidBrush()'와'GetSysColorBrush()'도 솔리드 브러시를 만들지 않습니까? 또한'FillRect()'(http://msdn.microsoft.com/en-us/library/windows/desktop/dd162719%28v=vs.85%29.aspx)에 대한 MSDN 문서는 내가 캐스팅 할 수 있다고 제안합니다. (이것은 WNDCLASS.hbrBackground와 같다); 그것은 실제로 부정확 한가? – andlabs

+0

음, 원래 질문에서 나는 그 기능을했고 결과는 같다고 말했습니다 ... – andlabs

+0

나는 브러쉬에 관한 쓰레기를 말하고있었습니다. 죄송합니다. 너는 나에게 뭔가 가르쳐 줬어. –