/* http://wvware.sourceforge.net/caolan/Polyline.html */ static GpStatus Polyline (MetafilePlayContext *context, BYTE *data) { GpStatus status; int p; /* variable number of parameters */ SHORT num = GETS(WP1); #ifdef DEBUG_WMF printf ("Polyline %d points", num); #endif SHORT x1 = GETS(WP2); SHORT y1 = GETS(WP3); int n = 4; for (p = 1; p < num; p++) { SHORT x2 = GETS(WP(n)); n++; SHORT y2 = GETS(WP(n)); n++; #ifdef DEBUG_WMF_2 printf ("\n\tdraw from %d,%d to %d,%d", x1, y1, x2, y2); #endif GpPen *pen = gdip_metafile_GetSelectedPen (context); status = GdipDrawLine (context->graphics, pen, x1, y1, x2, y2); if (status != Ok) return status; x1 = x2; y1 = y2; } return Ok; }
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; switch (uMsg) { case WM_PAINT: hdc = BeginPaint(hwnd, &ps); int graphics; GdipCreateFromHDC(hdc, &graphics);//创建Graphics对象 GdipCreatePen1(0x60FF2015, 1, 2, &pen);//创建画笔 GdipDrawRectangle(graphics, pen, 20, 20, 120, 120);//画矩形 GdipDrawLine(graphics, pen, 50, 60, 170, 340);//画直线 GdipDeletePen(pen);//销毁画笔 GdipDeleteGraphics(graphics);//销毁Graphics对象 EndPaint(hwnd, &ps); return 0;//告诉系统,WM_PAINT消息我已经处理了,你那儿凉快哪儿玩去吧。 case WM_CREATE: break; case WM_DESTROY://窗口已经销毁 PostQuitMessage(0);//退出消息循环,结束应用程序 return 0; break; case WM_LBUTTONDOWN://鼠标左键按下 //让无边框窗口能够拖动(在窗口客户区拖动) PostMessage(hwnd, WM_SYSCOMMAND, 61458, 0); break; /*case WM_MOUSEMOVE://鼠标移动 int xPos, yPos; xPos = GET_X_LPARAM(lParam);//鼠标位置X坐标 yPos = GET_Y_LPARAM(lParam);//鼠标位置Y坐标 //不要用LOWORD和HIWORD获取坐标,因为坐标有可能是负的 break;*/ default: break; } return DefWindowProc(hwnd, uMsg, wParam, lParam);//其他消息交给系统处理 }
static void win_draw(win_t *win) { GpGraphics *gp; GpStatus st; GpImage *img; gunichar2 *unis; XClearWindow(win->dpy, win->win); GdipCreateFromXDrawable_linux (win->win, win->dpy, &gp); { GpPen *pen; GpSolidFill *brush; int a = 255; int r = 255; int g = 0; int b = 0; GdipCreatePen1 (a << 24 | r << 16 | g << 8 | b, 10, UnitPixel, &pen); GdipDrawRectangle (gp, pen, 10, 10, 60, 60); GdipDrawLine (gp, pen, 0, 0, 100, 100); GdipCreateSolidFill (a << 24 | r << 16 | g << 8 | b, &brush); printf ("%d\n",GdipFillEllipse (gp, (GpBrush*)brush, 40, 40, 50, 75)); // return; } unis = g_utf8_to_utf16 ("test.jpg", -1, NULL, NULL, NULL); st = GdipLoadImageFromFile (unis, &img); CHECK_GDIP_ST(st); st = GdipDrawImage (gp, img, 0, 0); CHECK_GDIP_ST(st); g_free (unis); GdipDisposeImage (img); img = NULL; printf("jpg drawn \n"); unis = g_utf8_to_utf16 ("test.tif", -1, NULL, NULL, NULL); st = GdipLoadImageFromFile (unis, &img); CHECK_GDIP_ST(st); st = GdipDrawImage (gp, img, 100, 0); CHECK_GDIP_ST(st); g_free (unis); GdipDisposeImage (img); img = NULL; printf("tif drawn \n"); unis = g_utf8_to_utf16 ("test.gif", -1, NULL, NULL, NULL); st = GdipLoadImageFromFile (unis, &img); CHECK_GDIP_ST(st); st = GdipDrawImage (gp, img, 200, 0); CHECK_GDIP_ST(st); g_free (unis); GdipDisposeImage (img); img = NULL; printf("gif drawn \n"); unis = g_utf8_to_utf16 ("test.png", -1, NULL, NULL, NULL); st = GdipLoadImageFromFile (unis, &img); CHECK_GDIP_ST(st); st = GdipDrawImage (gp, img, 0, 100); CHECK_GDIP_ST(st); g_free (unis); GdipDisposeImage (img); img = NULL; printf("png drawn \n"); unis = g_utf8_to_utf16 ("test.bmp", -1, NULL, NULL, NULL); st = GdipLoadImageFromFile (unis, &img); CHECK_GDIP_ST(st); st = GdipDrawImage (gp, img, 200, 100); CHECK_GDIP_ST(st); g_free (unis); GdipDisposeImage (img); img = NULL; printf("bmp drawn \n"); }