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

📄 gdiopt.c

📁 这是ARM嵌入式系统的实验教程中的MINIGUI的实验源代码!
💻 C
📖 第 1 页 / 共 3 页
字号:
    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, 20);    SetPenColor (hdc, PIXEL_red);    SetPenCapStyle (hdc, PT_CAP_ROUND);    LineEx (hdc, 80, 80, 400, 300);    SetPenColor (hdc, PIXEL_blue);    ArcEx (hdc, 100, 100, 200, 300, 180*64, 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, (const unsigned char*)"\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);#endif}#endif#endif#define TEXT_WIDTH      630#define TEXT_HEIGHT     120#define LOGO_WIDTH      179#define LOGO_HEIGHT     194#define IDT_ANIMATION   100#define FRAME_SPEED     10      /* 10 frames per second */static BOOL anim_inited = FALSE;static HDC shadow;static HDC logo_layer;static HDC text_layer;static int text_line;static const char* text[] = {    "MiniGUI Version 1.5.x.",    "Copyright (C) 1998 ~ 2002 Feynman Software and others.",    "MiniGUI is free software, covered by the GNU General Public License, ",    "and you are welcome to change it and/or distribute copies of it under certain conditions. ",    "Please visit\nhttp://www.minigui.org and http://www.minigui.com\nto know the details.",    "MiniGUI版本1.5.x。",    "版权所有,一九九八至二零零二年,北京飞漫软件技术有限公司。",    "该软件是自由软件,遵循GNU通用公共许可证发布,",    "您可以在特定条件下修改或者发布该软件。",    "相关信息,敬请参阅\nhttp://www.minigui.org\nhttp://www.minigui.com.",};static PLOGFONT logfonttimes;static RECT text_rc;static int x, y = 20, oldx = -100, oldy, xdir = 1, ydir = 1, count;static int xspeed = 4, yspeed = 4;void GDIDemo_Animated (HWND hwnd, HDC hdc){    //unsigned int start_tick, end_tick;   if (!anim_inited) {       BITMAP *logo = bmp_sample;       logo_layer = CreateCompatibleDCEx (hdc,                        LOGO_WIDTH, LOGO_HEIGHT);       FillBoxWithBitmap (logo_layer, 0, 0, 0, 0, logo);       shadow = CreateCompatibleDC (hdc);       text_layer = CreateMemDC (TEXT_WIDTH, TEXT_HEIGHT, 24,                        MEMDC_FLAG_HWSURFACE |                        MEMDC_FLAG_SRCALPHA |                        MEMDC_FLAG_SRCCOLORKEY,                       0x00FF0000, 0x0000FF00,                        0x000000FF, 0x0000000);       SetMemDCColorKey (text_layer, MEMDC_FLAG_SRCCOLORKEY, 0);       logfonttimes = CreateLogFont (NULL, "Times", "GB2312",            FONT_WEIGHT_REGULAR, FONT_SLANT_ROMAN,            FONT_SETWIDTH_NORMAL, FONT_SPACING_CHARCELL,            FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE,            24, 0);       SelectFont (text_layer, logfonttimes);       SetBrushColor (hdc, PIXEL_lightwhite);       FillBox (hdc, 0, 0, -1, -1);       text_rc.left = 0; text_rc.top = 0;       text_rc.right = TEXT_WIDTH; text_rc.bottom = TEXT_HEIGHT;       anim_inited = TRUE;   }   text_line = 0;   //SetTimer (hWnd, IDT_ANIMATION, FRAME_SPEED);   ReleaseDC (hdc);}void GDIDemo_Animated_Timer (HWND hwnd){    unsigned int start_tick, end_tick;    HDC hdc;    if (!anim_inited)        return;     start_tick = GetTickCount ();    /* prepaer the text layer */    if (count == 0) {        SetBrushColor (text_layer,                         RGB2Pixel (text_layer, 0x00, 0x00, 0x00));        FillBox (text_layer, 0, 0, -1, -1);        SetBkColor (text_layer,                         RGB2Pixel (text_layer, 0x00, 0x00, 0xFF));        SetTextColor (text_layer,                         RGB2Pixel (text_layer, 0xFF, 0xFF, 0xFF));        SetBkMode (text_layer, BM_OPAQUE);        DrawText (text_layer, text [text_line], -1, &text_rc,                         DT_CENTER | DT_WORDBREAK);        text_line ++;        if (text_line == 10) text_line = 0;    }     SetBrushColor (shadow, PIXEL_lightwhite);    FillBox (shadow, 0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT);     x += xspeed * xdir;    y += yspeed * ydir;    if (x < 0) {        xdir = 1;        xspeed = rand() % 4 + 2;    }    if (x >= DEFAULT_WIDTH) {        xdir = -1;        xspeed = rand() % 4 + 2;    }    if (y < 0) {        ydir = 1;        yspeed = rand() % 4 + 2;    }    if (y >= DEFAULT_HEIGHT) {        ydir = -1;        yspeed = rand() % 4 + 2;    }     BitBlt (logo_layer, 0, 0, 0, 0, shadow, x, y, 0);     SetMemDCAlpha (text_layer, MEMDC_FLAG_SRCALPHA, 255 - count * 4);    BitBlt (text_layer, 0, 0, 0, 0, shadow,                     0, (DEFAULT_HEIGHT - TEXT_HEIGHT)/2, 0);     hdc = GetClientDC (hwnd);    if (oldx > -100) {        BitBlt (shadow, oldx, oldy,                         LOGO_WIDTH, LOGO_HEIGHT, hdc, oldx, oldy, 0);    }    oldx = x;    oldy = y;    BitBlt (shadow, x, y, LOGO_WIDTH, LOGO_HEIGHT, hdc, x, y, 0);    BitBlt (shadow, 0, (DEFAULT_HEIGHT - TEXT_HEIGHT)/2,                     DEFAULT_WIDTH, TEXT_HEIGHT,                     hdc,                     0, (DEFAULT_HEIGHT - TEXT_HEIGHT)/2, 0);    SetTextColor (shadow,                     RGB2Pixel (hdc, (int)(255 * sin(count * M_PI / 63)),                               0x00, 0x00));    SetBkColor (shadow, PIXEL_lightwhite);    SetBkMode (shadow, BM_TRANSPARENT);    //TextOut (shadow, 0, 0, "Type 'S' to stop animation.");    BitBlt (shadow, 0, 0, 200, 20, hdc, 0, 0, 0);    ReleaseDC (hdc);    end_tick = GetTickCount ();     // printf ("Ticks per frame: %u\n", end_tick - start_tick);     count++;    if (count == 64)        count = 0;}#endifint GDIDemoWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){    unsigned int start_tick, end_tick;    HDC hdc;    switch (message) {#ifdef _USE_NEWGAL        case MSG_TIMER:            if (!anim_inited || wParam != IDT_ANIMATION)                return 0;            start_tick = GetTickCount ();            /* prepaer the text layer */            if (count == 0) {                SetBrushColor (text_layer,                                 RGB2Pixel (text_layer, 0x00, 0x00, 0x00));                FillBox (text_layer, 0, 0, -1, -1);                SetBkColor (text_layer,                                 RGB2Pixel (text_layer, 0x00, 0x00, 0xFF));                SetTextColor (text_layer,                                 RGB2Pixel (text_layer, 0xFF, 0xFF, 0xFF));                SetBkMode (text_layer, BM_OPAQUE);                DrawText (text_layer, text [text_line], -1, &text_rc,                                 DT_CENTER | DT_WORDBREAK);                text_line ++;                if (text_line == 10) text_line = 0;            }            SetBrushColor (shadow, PIXEL_lightwhite);            FillBox (shadow, 0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT);            x += xspeed * xdir;            y += yspeed * ydir;            if (x < 0) {                xdir = 1;                xspeed = rand() % 4 + 2;            }            if (x >= DEFAULT_WIDTH) {                xdir = -1;                xspeed = rand() % 4 + 2;            }            if (y < 0) {                ydir = 1;                yspeed = rand() % 4 + 2;            }            if (y >= DEFAULT_HEIGHT) {                ydir = -1;                yspeed = rand() % 4 + 2;            }            BitBlt (logo_layer, 0, 0, 0, 0, shadow, x, y, 0);            SetMemDCAlpha (text_layer, MEMDC_FLAG_SRCALPHA, 255 - count * 4);            BitBlt (text_layer, 0, 0, 0, 0, shadow,                             0, (DEFAULT_HEIGHT - TEXT_HEIGHT)/2, 0);            hdc = GetClientDC (hWnd);#if 1            if (oldx > -100) {                BitBlt (shadow, oldx, oldy,                                 LOGO_WIDTH, LOGO_HEIGHT, hdc, oldx, oldy, 0);            }            oldx = x;            oldy = y;            BitBlt (shadow, x, y, LOGO_WIDTH, LOGO_HEIGHT, hdc, x, y, 0);            BitBlt (shadow, 0, (DEFAULT_HEIGHT - TEXT_HEIGHT)/2,                             DEFAULT_WIDTH, TEXT_HEIGHT,                             hdc,                             0, (DEFAULT_HEIGHT - TEXT_HEIGHT)/2, 0);            SetTextColor (shadow,                             RGB2Pixel (hdc, (int)(255 * sin(count * M_PI / 63)),                                       0x00, 0x00));            SetBkColor (shadow, PIXEL_lightwhite);            SetBkMode (shadow, BM_TRANSPARENT);            //TextOut (shadow, 0, 0, "Type 'S' to stop animation.");            BitBlt (shadow, 0, 0, 200, 20, hdc, 0, 0, 0);#else            TextOut (shadow, 0, 0, "Type 'S' to stop animation.");            BitBlt (shadow, 0, 0, 0, 0, hdc, 0, 0, 0);#endif            ReleaseDC (hdc);            end_tick = GetTickCount ();            // printf ("Ticks per frame: %u\n", end_tick - start_tick);            count++;            if (count == 64)                count = 0;            break;#endif        case MSG_CHAR:#ifdef _USE_NEWGAL            if (anim_inited && wParam != 's' && wParam != 'S')                break;#endif            srand (time (NULL));            hdc = GetClientDC (hWnd);            switch (wParam) {            case '1':                GDIDemo_NormalLines (hWnd, hdc);                break;            case '2':                GDIDemo_XoredLines (hWnd, hdc);                break;            case '3':                GDIDemo_Filling (hWnd, hdc);                break;            case '4':                GDIDemo_NormalBitmaps (hWnd, hdc);                break;            case '5':                GDIDemo_TransparentBitmaps (hWnd, hdc);                break;            case '6':                GDIDemo_AlphaBlendedBitmaps (hWnd, hdc);                break;            case '7':                GDIDemo_MemDC (hWnd, hdc);                break;#ifdef _USE_NEWGAL            case '8':                if (!anim_inited) {                    BITMAP logo;                    if (LoadBitmap (hdc, &logo, "res/logo.bmp")) {                        break;                    }                    logo_layer = CreateCompatibleDCEx (hdc,                                     LOGO_WIDTH, LOGO_HEIGHT);                    FillBoxWithBitmap (logo_layer, 0, 0, 0, 0, &logo);                    UnloadBitmap (&logo);                    shadow = CreateCompatibleDC (hdc);                    text_layer = CreateMemDC (TEXT_WIDTH, TEXT_HEIGHT, 24,                                     MEMDC_FLAG_HWSURFACE |                                     MEMDC_FLAG_SRCALPHA |                                     MEMDC_FLAG_SRCCOLORKEY,                                    0x00FF0000, 0x0000FF00,                                     0x000000FF, 0x0000000);                    SetMemDCColorKey (text_layer, MEMDC_FLAG_SRCCOLORKEY, 0);                    logfonttimes = CreateLogFont (NULL, "Times", "GB2312",                         FONT_WEIGHT_REGULAR, FONT_SLANT_ROMAN,                         FONT_SETWIDTH_NORMAL, FONT_SPACING_CHARCELL,                         FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE,                         24, 0);                    SelectFont (text_layer, logfonttimes);                    SetBrushColor (hdc, PIXEL_lightwhite);                    FillBox (hdc, 0, 0, -1, -1);                    text_rc.left = 0; text_rc.top = 0;                    text_rc.right = TEXT_WIDTH; text_rc.bottom = TEXT_HEIGHT;                    anim_inited = TRUE;                }                text_line = 0;                SetTimer (hWnd, IDT_ANIMATION, FRAME_SPEED);                ReleaseDC (hdc);                return 0;            case '-':                if (anim_inited) {                    DeleteMemDC (shadow);                    DeleteMemDC (logo_layer);                    DeleteMemDC (text_layer);                    if (logfonttimes)                        DestroyLogFont (logfonttimes);                    anim_inited = FALSE;                    KillTimer (hWnd, IDT_ANIMATION);                    break;                }                break;            case '9':                //GDIDemo_Region (hWnd, hdc);                ReleaseDC (hdc);                return 0;#ifdef _USE_NEWGAL            case '0':                //test_yuv(hWnd, hdc);                ReleaseDC (hdc);                return 0;#ifdef _ADV_2DAPI            case '+':                GDIDemo_Adv2DAPI (hWnd, hdc);                ReleaseDC (hdc);                return 0;#endif#endif#endif            case '*':                PostMessage (hWnd, MSG_CLOSE, 0, 0);                break;            }            ReleaseDC (hdc);            InvalidateRect (hWnd, NULL, TRUE);        break;        case MSG_PAINT:            hdc = BeginPaint (hWnd);            SetTextColor (hdc, PIXEL_black);            SetBkColor (hdc, PIXEL_lightwhite);            SetBkMode (hdc, BM_TRANSPARENT);            TabbedTextOut (hdc, 10, 10,                                  "Press '1': Drawing normal lines and curves.\n"                                 "Press '2': Drawing xored lines and curves.\n"                                 "Press '3': Drawing filled areas.\n"                                 "Press '4': Drawing normal bitmaps.\n"                                 "Press '5': Drawing transparent bitmaps.\n"                                 "Press '6': Drawing alpha blending bitmaps.\n"                                 "Press '7': Memory DC and blitting.\n"                                 "Press '8': Animation.\n"                                 "Press '9': Complex region.\n"                                 "Press '0': YUV overlay display.\n"                                 "Press '+': Advanced 2D functions.\n"                                 "\nType '*' to quit.");            EndPaint (hWnd, hdc);            return 0;        case MSG_CLOSE:#ifdef _USE_NEWGAL            if (anim_inited) {                DeleteMemDC (shadow);                DeleteMemDC (logo_layer);                DeleteMemDC (text_layer);                DestroyLogFont (logfonttimes);                anim_inited = FALSE;                KillTimer (hWnd, IDT_ANIMATION);            }#endif            DestroyMainWindow (hWnd);            PostQuitMessage (hWnd);        return 0;    }    return DefaultMainWinProc(hWnd, message, wParam, lParam);}

⌨️ 快捷键说明

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