[cairo] Cairo + Win32 GDI + wxWidgets?

Sean Dunn seanedunn at yahoo.com
Sat Jan 26 12:32:52 PST 2008

Hi all,

I just started using wxWidgets with Cairo. My target platform right now is Win32. I'm pretty new to wxWidgets, Cairo, and GDI, and I'm madly trying to grok it all.

I'm having trouble getting the following code to show anything, and I'm not sure what's wrong. It's supposed to create a Cairo surface based on the win32 surface, draw to it, and then bitblt it back to my window (a combination of gradients that cover the surface). Nothing shows up, though. This sample is based on the Docview wxWidgets sample, and the Gradient Cairo sample.

I'm looking for pointers and perhaps any online resources that discuss using Cairo/Win32GDI/wxWidgets all at once (it doesn't seem to be a popular combination, most seem to be using GTK/Cairo). Also, what is the most efficient manner for drawing to GDI surfaces? In this case, I'm doing a bitblt of a buffer.. But is there a way to draw directly with double buffering?

void MyView::OnDraw(wxDC *dc)
     // wxFrame* m_frame
     HWND hWnd = (HWND)m_frame->GetHWND();
     HDC hDc = BeginPaint(hWnd, &ps);
     RECT rc;
     BOOL succ = GetClientRect(hWnd, &rc);
     long width = rc.right - rc.left;
     long height = rc.bottom - rc.top;
     long x = rc.left;
     long y = rc.top;
     HDC hBuffer = CreateCompatibleDC(hDc);
     HBITMAP hBitmap = CreateCompatibleBitmap(hDc,width,height);
     HGDIOBJ hOldBitmap = SelectObject(hBuffer, hBitmap);

     cairo_surface_t* surf = cairo_win32_surface_create(hBuffer);
     cairo_t* ctx = cairo_create(surf);
     cairo_pattern_t *pat;
     pat = cairo_pattern_create_linear (0.0, 0.0,  0.0, (double)height);
     cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
     cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
     cairo_rectangle (ctx, 0, 0, (double)width, (double)height);
     cairo_set_source (ctx, pat);
     cairo_fill (ctx);
     cairo_pattern_destroy (pat);
     pat = cairo_pattern_create_radial (115.2, 102.4, 25.6,
                102.4,  102.4, 128.0);
     cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
     cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
     cairo_set_source (ctx, pat);
     cairo_arc (ctx, 128.0, 128.0, 76.8, 0, 2 * M_PI);
     cairo_fill (ctx);
     cairo_pattern_destroy (pat);

     BitBlt(hDc, 0, 0, width,  height, hBuffer, x, y, SRCCOPY);
     SelectObject( hBuffer, hOldBitmap );
     DeleteObject( hBitmap );
     DeleteDC( hBuffer );
     EndPaint(hWnd, &ps);        

Any help is appreciated..!

Thank you,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20080126/99906862/attachment.html 

More information about the cairo mailing list