⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdidemo.c

📁 MINI GUI1.6X源码
💻 C
📖 第 1 页 / 共 3 页
字号:
        toy = rand() % DEFAULT_WIDTH;        bitmap.bmAlpha = rand() % 256;        FillBoxWithBitmap (hdc, tox, toy, 0, 0, &bitmap);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Alpha Blended Bitmap", 1000);    bitmap.bmType = BMP_TYPE_ALPHACHANNEL | BMP_TYPE_COLORKEY;    bitmap.bmColorKey = GetPixelInBitmap (&bitmap, 0, 0);    /* alpha blending and transparent */    start_tick = GetTickCount ();    count = 1000;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        bitmap.bmAlpha = rand() % 256;        FillBoxWithBitmap (hdc, tox, toy, 0, 0, &bitmap);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Alpha Blended Transparent Bitmap", 1000);    UnloadBitmap (&bitmap);#else    TellNotImplemented (hwnd, "Alpha Blended Bitmap");#endif}static void GDIDemo_MemDC (HWND hwnd, HDC hdc){    HDC mem_dc;    int tox = DEFAULT_WIDTH, toy = DEFAULT_WIDTH;    int count;    unsigned int start_tick, end_tick;    unsigned int nr_colors = GetGDCapability (hdc, GDCAP_COLORNUM);        /* Compatible DC */    mem_dc = CreateCompatibleDC (hdc);    SetBrushColor (mem_dc, 0);    FillBox (mem_dc, 0, 0, 65535, 65535);    start_tick = GetTickCount ();    count = 200;    while (count--) {        tox = rand() % DEFAULT_WIDTH; toy = rand() % DEFAULT_WIDTH;        MoveTo (mem_dc, tox, toy);        SetPenColor (mem_dc, rand() % nr_colors);        tox = rand() % DEFAULT_WIDTH; toy = rand() % DEFAULT_WIDTH;        LineTo (mem_dc, tox, toy);        Circle (mem_dc, tox, toy, rand() % DEFAULT_X);        BitBlt (mem_dc, 0, 0, rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, hdc,                         rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, 0);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Blit", 200);#ifdef _USE_NEWGAL    SetBrushColor (mem_dc, 0);    FillBox (mem_dc, 0, 0, 65535, 65535);    SetMemDCColorKey (mem_dc, MEMDC_FLAG_SRCCOLORKEY, 0);    start_tick = GetTickCount ();    count = 200;    while (count--) {        tox = rand() % DEFAULT_WIDTH; toy = rand() % DEFAULT_WIDTH;        MoveTo (mem_dc, tox, toy);        SetPenColor (mem_dc, rand() % nr_colors);        tox = rand() % DEFAULT_WIDTH; toy = rand() % DEFAULT_WIDTH;        LineTo (mem_dc, tox, toy);        Circle (mem_dc, tox, toy, rand() % DEFAULT_X);        BitBlt (mem_dc, 0, 0, rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, hdc,                         rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, 0);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Transparent Blit", 200);#endif    DeleteCompatibleDC (mem_dc);#ifdef _USE_NEWGAL    /* Memory DC with alpha */    mem_dc = CreateMemDC (400, 100, 16, MEMDC_FLAG_HWSURFACE | MEMDC_FLAG_SRCALPHA,                    0x0000F000, 0x00000F00, 0x000000F0, 0x0000000F);    SetBrushColor (mem_dc, RGBA2Pixel (mem_dc, 0xFF, 0xFF, 0x00, 0x80));    FillBox (mem_dc, 0, 0, 200, 50);    SetBrushColor (mem_dc, RGBA2Pixel (mem_dc, 0xFF, 0x00, 0xFF, 0x80));    FillBox (mem_dc, 200, 0, 200, 50);    SetBrushColor (mem_dc, RGBA2Pixel (mem_dc, 0x00, 0xFF, 0xFF, 0x80));    FillBox (mem_dc, 0, 50, 200, 50);    SetBrushColor (mem_dc, RGBA2Pixel (mem_dc, 0xFF, 0xFF, 0xFF, 0x80));    FillBox (mem_dc, 200, 50, 200, 50);    SetTextColor (mem_dc, RGBA2Pixel (mem_dc, 0x00, 0x00, 0x00, 0x80));    SetBkColor (mem_dc, RGBA2Pixel (mem_dc, 0xFF, 0xFF, 0xFF, 0x80));    SetBkMode (mem_dc, BM_TRANSPARENT);    TabbedTextOut (mem_dc, 0, 0, "Memory DC with alpha.\n"                                 "The source DC have alpha per-pixel.");    start_tick = GetTickCount ();    count = 200;    while (count--) {        BitBlt (mem_dc, 0, 0, 400, 100, hdc, rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, 0);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Per-Pixel Alpha Blit", 200);    DeleteMemDC (mem_dc);    /* Memory DC with alpha*/    mem_dc = CreateMemDC (400, 100, 32, MEMDC_FLAG_HWSURFACE | MEMDC_FLAG_SRCALPHA | MEMDC_FLAG_SRCCOLORKEY,                    0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000);    SetBrushColor (mem_dc, RGB2Pixel (mem_dc, 0xFF, 0xFF, 0x00));    FillBox (mem_dc, 0, 0, 400, 100);    SetTextColor (mem_dc, RGB2Pixel (mem_dc, 0x00, 0x00, 0xFF));    SetBkColor (mem_dc, RGB2Pixel (mem_dc, 0x00, 0x00, 0x00));    SetBkMode (mem_dc, BM_TRANSPARENT);    TabbedTextOut (mem_dc, 0, 0, "Memory DC with alpha.\n"                                 "The source DC have alpha per-surface.");    start_tick = GetTickCount ();    count = 200;    while (count--) {        SetMemDCAlpha (mem_dc, MEMDC_FLAG_SRCALPHA | MEMDC_FLAG_RLEACCEL, rand () % 256);        BitBlt (mem_dc, 0, 0, 400, 100, hdc, rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, 0);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Per-Surface Alpha Blit", 200);    FillBox (mem_dc, 0, 0, 400, 100);    SetBrushColor (mem_dc, RGB2Pixel (mem_dc, 0xFF, 0x00, 0xFF));    FillBox (mem_dc, 200, 0, 400, 100);    TabbedTextOut (mem_dc, 0, 0, "Memory DC with alpha and colorkey.\n"                                 "The source DC have alpha per-surface.\n"                                 "And the source DC have a colorkey, \n"                                 "and RLE accelerated.");    SetMemDCColorKey (mem_dc, MEMDC_FLAG_SRCCOLORKEY | MEMDC_FLAG_RLEACCEL,                     RGB2Pixel (mem_dc, 0xFF, 0xFF, 0x00));    start_tick = GetTickCount ();    count = 200;    while (count--) {        SetMemDCAlpha (mem_dc, MEMDC_FLAG_SRCALPHA | MEMDC_FLAG_RLEACCEL, rand () % 256);        BitBlt (mem_dc, 0, 0, 400, 100, hdc, rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, 0);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Alpha and colorkey Blit", 200);    DeleteMemDC (mem_dc);#else    TellNotImplemented (hwnd, "Alpha Blit");#endif}#ifdef _USE_NEWGALstatic BLOCKHEAP my_cliprc_heap;static BOOL ch_inited = FALSE;static void GDIDemo_Region (HWND hWnd, HDC hdc){    CLIPRGN my_cliprgn1;    CLIPRGN my_cliprgn2;    CLIPRGN my_cliprgn3;    if (!ch_inited) {        InitFreeClipRectList (&my_cliprc_heap, 100);        ch_inited = TRUE;    }    InitClipRgn (&my_cliprgn1, &my_cliprc_heap);    InitClipRgn (&my_cliprgn2, &my_cliprc_heap);    InitClipRgn (&my_cliprgn3, &my_cliprc_heap);    InitCircleRegion (&my_cliprgn1, 100, 100, 60);    InitEllipseRegion (&my_cliprgn2, 100, 100, 50, 70);    SetBrushColor (hdc, PIXEL_blue);    FillBox (hdc, 0, 0, DEFAULT_WIDTH, 200);    SubtractRegion (&my_cliprgn1, &my_cliprgn1, &my_cliprgn2);    SelectClipRegion (hdc, &my_cliprgn1);    SetBrushColor (hdc, PIXEL_red);    FillBox (hdc, 0, 0, 180, 200);    InitCircleRegion (&my_cliprgn1, 300, 100, 60);    OffsetRegion (&my_cliprgn2, 200, 0);    XorRegion (&my_cliprgn1, &my_cliprgn1, &my_cliprgn2);    SelectClipRegion (hdc, &my_cliprgn1);    FillBox (hdc, 200, 0, 180, 200);    InitCircleRegion (&my_cliprgn1, 500, 100, 60);    OffsetRegion (&my_cliprgn2, 200, 0);    IntersectRegion (&my_cliprgn1, &my_cliprgn1, &my_cliprgn2);    SelectClipRegion (hdc, &my_cliprgn1);    FillBox (hdc, 400, 0, 180, 200);#if 0    {    static POINT pts [] = {        {400, 500},        {200, 200},        {500, 100},        {100, 50},    };    InitPolygonRegion (&my_cliprgn3, pts, 4);    SelectClipRegion (hdc, &my_cliprgn3);    SetBrushColor (hdc, PIXEL_green);    FillBox (hdc, 0, 0, DEFAULT_WIDTH, 200);        EmptyClipRgn (&my_cliprgn1);    EmptyClipRgn (&my_cliprgn2);    EmptyClipRgn (&my_cliprgn3);    }#endif    /* You should not forget to destroy the FreeClipRectList in your applications */}#ifdef _ADV_2DAPIconst unsigned char stipple_bits [] = "\x81\x42\x24\x18\x18\x24\x42\x81";static STIPPLE my_stipple ={    8, 8, 1, 8,    stipple_bits};#if 1void GDIDemo_Adv2DAPI (HWND hWnd, HDC hdc){    POINT pt [10];    BITMAP bitmap;    if (LoadBitmap (hdc, &bitmap, "res/sample.bmp"))        return;    SetPenType (hdc, PT_SOLID);    SetPenDashes (hdc, 0, "\1\1", 2);    SetPenWidth (hdc, 5);    SetPenCapStyle (hdc, PT_CAP_ROUND);    SetPenWidth (hdc, 5);    LineEx (hdc, 102, 12, 117, 0);    SetPenJoinStyle (hdc, PT_JOIN_BEVEL);    pt [0].x = 20;    pt [0].y = 20;    pt [1].x = 80;    pt [1].y = 20;    pt [2].x = 80;    pt [2].y = 80;    pt [3].x = 20;    pt [3].y = 80;    pt [4].x = 20;    pt [4].y = 20;    PolyLineEx (hdc, pt, 5);    SetPenWidth (hdc, 3);    SetPenColor (hdc, PIXEL_red);    SetPenCapStyle (hdc, PT_CAP_ROUND);    LineEx (hdc, 80, 80, 400, 300);    SetPenColor (hdc, PIXEL_blue);    ArcEx (hdc, 5, 5, 640, 150, 0, 180*64);    SetBrushType (hdc, BT_SOLID);    SetBrushColor (hdc, PIXEL_green);    FillArcEx (hdc, 100, 0, 200, 100, 0, 120*64);    SetBrushType (hdc, BT_TILED);    SetBrushInfo (hdc, &bitmap, &my_stipple);    SetBrushOrigin (hdc, 100, 100);    FillArcEx (hdc, 100, 100, 200, 100, 0, 270*64);    SetBrushType (hdc, BT_STIPPLED);    FillArcEx (hdc, 100, 300, 200, 100, 0, 360*64);    SetPenType (hdc, PT_DOUBLE_DASH);    SetPenDashes (hdc, 0, "\20\40", 2);    SetPenCapStyle (hdc, PT_CAP_BUTT);    SetPenWidth (hdc, 20);    LineEx (hdc, 500, 0, 20, 100);    SetBrushType (hdc, BT_OPAQUE_STIPPLED);    ArcEx (hdc, 400, 100, 200, 300, 180*64, 180*64);    UnloadBitmap (&bitmap);}#elsevoid GDIDemo_Adv2DAPI (HWND hWnd, HDC hdc){    POINT pt [10];    BITMAP bitmap;    pt[0].x = 80;    pt[0].y = 80;    pt[1].x = 70;    pt[1].y = 90;    pt[2].x = 90;    pt[2].y = 90;    pt[3].x = 80;    pt[3].y = 80;    SetPenType (hdc, PT_SOLID);    PolyLineEx (hdc, pt, 4);    return;    if (LoadBitmap (hdc, &bitmap, "res/sample.bmp"))        return;    SetPenType (hdc, PT_SOLID);    SetPenWidth (hdc, 5);    LineEx (hdc, 10, 10, 210, 10);    SetPenDashes (hdc, 0, "\5\5", 2);    SetPenType (hdc, PT_ON_OFF_DASH);    LineEx (hdc, 10, 20, 210, 20);    SetPenDashes (hdc, 0, "\x8\x8", 2);    SetPenType (hdc, PT_DOUBLE_DASH);    SetBrushType (hdc, BT_SOLID);    SetBrushColor (hdc, PIXEL_green);    SetBkColor (hdc, PIXEL_lightwhite);    LineEx (hdc, 10, 30, 210, 30);    SetPenDashes (hdc, 0, "\x10\x10", 2);    SetBrushType (hdc, BT_STIPPLED);    SetBrushInfo (hdc, &bitmap, &my_stipple);    SetPenWidth (hdc, 10);    LineEx (hdc, 10, 50, 210, 50);    MoveTo (hdc, 10, 60);    LineTo (hdc, 10, 120);    MoveTo (hdc, 210, 60);    LineTo (hdc, 210, 120);    SetPenType (hdc, PT_SOLID);    SetPenWidth (hdc, 10);    SetPenCapStyle (hdc, PT_CAP_BUTT);    LineEx (hdc, 10, 70, 210, 70);    SetPenCapStyle (hdc, PT_CAP_ROUND);    LineEx (hdc, 10, 90, 210, 90);    SetPenCapStyle (hdc, PT_CAP_PROJECTING);    LineEx (hdc, 10, 110, 210, 110);    SetPenJoinStyle (hdc, PT_JOIN_MITER);    pt [0].x = 10; pt [0].y = 150;    pt [1].x = 100; pt [1].y = 150;    pt [2].x = 10; pt [2].y = 190;    PolyLineEx (hdc, pt, 3);    SetPenJoinStyle (hdc, PT_JOIN_ROUND);    pt [0].x = 210; pt [0].y = 150;    pt [1].x = 300; pt [1].y = 150;    pt [2].x = 210; pt [2].y = 190;    PolyLineEx (hdc, pt, 3);    SetPenJoinStyle (hdc, PT_JOIN_BEVEL);    pt [0].x = 410; pt [0].y = 150;    pt [1].x = 500; pt [1].y = 150;    pt [2].x = 410; pt [2].y = 190;    PolyLineEx (hdc, pt, 3);    SetPenWidth (hdc, 1);    SetPenType (hdc, PT_ON_OFF_DASH);    SetPenCapStyle (hdc, PT_CAP_BUTT);    SetPenDashes (hdc, 0, "\x1\x1", 2);    LineEx (hdc, 300, 20, 510, 20);    SetPenDashes (hdc, 0, "\x4\x1", 2);    LineEx (hdc, 300, 30, 510, 30);    SetPenDashes (hdc, 0, "\x4\x1\x1\x1", 4);    LineEx (hdc, 300, 40, 510, 40);    SetPenDashes (hdc, 0, "\x4\x1\x1\x1\x1\x1", 6);    LineEx (hdc, 300, 50, 510, 50);    SetPenCapStyle (hdc, PT_CAP_BUTT);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -