#include "cairo-win32.h" #ifdef _MSC_VER # pragma comment(lib, "gdi32") # pragma comment(lib, "kernel32") # pragma comment(lib, "user32") #endif HWND hWnd; LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch (message) { case WM_DESTROY: PostQuitMessage(0); break; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); OffsetViewportOrgEx(hdc, -20, -4, NULL); cairo_surface_t* surf = cairo_win32_surface_create(hdc); cairo_t* cairo = cairo_create(surf); cairo_surface_destroy(surf); cairo_font_face_t* font = cairo_toy_font_face_create("", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_face(cairo, font); cairo_font_face_destroy(font); cairo_move_to(cairo, 100, 100); cairo_show_text(cairo, "Hello World"); cairo_destroy(cairo); EndPaint(hWnd, &ps); } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wcex={ sizeof(wcex) }; wcex.lpfnWndProc = WndProc; wcex.hInstance = hInstance; wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW); wcex.lpszClassName = "Main"; if( !RegisterClassEx(&wcex)) return -1; RECT r = { 0, 0, 200, 200 }; AdjustWindowRect( &r, WS_OVERLAPPEDWINDOW, FALSE ); hWnd = CreateWindow("Main", "Main", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, r.right-r.left, r.bottom-r.top, NULL, NULL, hInstance, NULL); if( !hWnd ) return -2; ShowWindow(hWnd, nCmdShow); for(MSG msg; GetMessage(&msg, NULL, 0, 0);) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; }