scetix
scetix

Reputation: 813

GDI+ problems on windows XP

I am using GDI+ to render login window. It all works fine on windows 7, but on windows XP (SP3 with all updates) there's absolutely no output.

Code in WM_PAINT

PAINTSTRUCT ps;
HDC         hdc = BeginPaint( hwnd, &ps );
Graphics    *graphics= new Graphics( hdc );

if ( graphics->Clear( BACKGROUND_COLOR ) != Ok )
{
    LOGGER << "LoginWindow::Error clearing surface" << endl;
    goto clean;
}

if ( graphics->DrawImage( dialogHeader, 0, 0, dialogHeaderSize.cx, dialogHeaderSize.cy ) != Ok )
{
    LOGGER << "LoginWindow::Error drawing image" << endl;
    goto clean;
}

if ( graphics->DrawRectangle( dialogBorderPen, 0, 0, LOGIN_WINDOW_WIDTH - 1, LOGIN_WINDOW_HEIGHT - 1 ) != Ok )
{
    LOGGER << "LoginWindow::Error drawing rectangle" << endl;
    goto clean;
}

clean:
delete graphics;
EndPaint( hwnd, &ps );

dialogHeader is a .png image loded with following code:

dialogHeader = Bitmap::FromFile( imagePath );

GDI+ is initialized like this:

GdiplusStartupInput gdiplusStartupInput;
Status              gdiplusStatus;
ULONG_PTR           gdiplusToken;

gdiplusStatus = GdiplusStartup( &gdiplusToken, &gdiplusStartupInput, NULL );

if ( gdiplusStatus != Ok )
{
    LOGGER << "Main::Failed to initialize GDI+. ErrorCode=" << gdiplusStatus << endl;
    return 1;
}

Some known facts:

http://imageshack.us/photo/my-images/851/winxp2.png/

Output on windows 7

http://imageshack.us/photo/my-images/824/win7p.png/

Output on windows XP

http://imageshack.us/photo/my-images/839/winxpu.png/

I hope someone can help. Thanks.

Upvotes: 2

Views: 2339

Answers (1)

scetix
scetix

Reputation: 813

Turns out it was a combination of WS_EX_COMPOSITED style and GDI+ custom painting. If i enable this flag, nothing is initially drawn on windows XP. Only after resizing, things start appearing.

After some research i found out its probably a bug. There is a workaround however:

  1. Create a DIB section HBITMAP (or you could try a standard HBITMAP) in memory and select it into an HDC (Look at CreateCompatibleBitmap and CreateCompatibleDC and also SelectObject).
  2. Make sure to create the HBITMAP the size of the client window.
  3. Now, use this "memory" HDC when calling:

    Graphics graphics (m_hDC); 
    
  4. When GDI+ is finished drawing to the memory HDC, then call BitBlt to draw the image on the pDC.

Upvotes: 3

Related Questions