📄 gdidemo.c
字号:
SetPenWidth (hdc, 20); SetPenCapStyle (hdc, PT_CAP_ROUND); LineEx (hdc, 10, 10, 50, 50); 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, 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, "\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);}#endif#endif#define TEXT_WIDTH 630#define TEXT_HEIGHT 120#define LOGO_WIDTH 220#define LOGO_HEIGHT 68#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.6.x.", "Copyright (C) 1998 ~ 2005 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;#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 'a': case 'A': GDIDemo_NormalLines (hWnd, hdc); break; case 'b': case 'B': GDIDemo_XoredLines (hWnd, hdc); break; case 'c': case 'C': GDIDemo_Filling (hWnd, hdc); break; case 'd': case 'D': GDIDemo_NormalBitmaps (hWnd, hdc); break; case 'e': case 'E': GDIDemo_TransparentBitmaps (hWnd, hdc); break; case 'f': case 'F': GDIDemo_AlphaBlendedBitmaps (hWnd, hdc); break; case 'g': case 'G': GDIDemo_MemDC (hWnd, hdc); break;#ifdef _USE_NEWGAL case 'h': case 'H': 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 's': case 'S': 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 'i': case 'I': GDIDemo_Region (hWnd, hdc); ReleaseDC (hdc); return 0;#ifdef _USE_NEWGAL case 'j': case 'J': test_yuv(hWnd, hdc); ReleaseDC (hdc); return 0;#ifdef _ADV_2DAPI case 'k': case 'K': GDIDemo_Adv2DAPI (hWnd, hdc); ReleaseDC (hdc); return 0;#endif#endif#endif case 'q': case 'Q': 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, 100, 100, "Type 'A': Drawing normal lines and curves.\n" "Type 'B': Drawing xored lines and curves.\n" "Type 'C': Drawing filled areas.\n" "Type 'D': Drawing normal bitmaps.\n" "Type 'E': Drawing transparent bitmaps.\n" "Type 'F': Drawing alpha blending bitmaps.\n" "Type 'G': Memory DC and blitting.\n" "Type 'H': Animation.\n" "Type 'I': Complex region.\n" "Type 'J': YUV overlay display.\n" "Type 'K': Advanced 2D functions.\n" "\nType 'Q' 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);}static void InitCreateInfo (PMAINWINCREATE pCreateInfo){ pCreateInfo->dwStyle = WS_CAPTION | WS_VISIBLE; pCreateInfo->dwExStyle = 0; pCreateInfo->spCaption = "GDI Demo" ; pCreateInfo->hMenu = 0; pCreateInfo->hCursor = GetSystemCursor (0); pCreateInfo->hIcon = 0; pCreateInfo->MainWindowProc = GDIDemoWinProc; pCreateInfo->lx = 0; pCreateInfo->ty = 0; pCreateInfo->rx = pCreateInfo->lx + DEFAULT_WIDTH; pCreateInfo->by = pCreateInfo->ty + DEFAULT_HEIGHT; pCreateInfo->iBkColor = PIXEL_lightwhite; pCreateInfo->dwAddData = 0; pCreateInfo->hHosting = HWND_DESKTOP;}int MiniGUIMain (int args, const char* arg[]){ MSG Msg; MAINWINCREATE CreateInfo; HWND hMainWnd;#if defined(_LITE_VERSION) && !(_STAND_ALONE) int i; const char* layer = NULL; RECT max_rect = {0, 0, 0, 0}; for (i = 1; i < args; i++) { if (strcmp (arg[i], "-layer") == 0) { layer = arg[i + 1]; break; } } GetLayerInfo (layer, &max_rect, NULL, NULL, NULL); if (JoinLayer (layer, arg[0], max_rect.left, max_rect.top, max_rect.left + DEFAULT_WIDTH, max_rect.top + DEFAULT_HEIGHT) == INV_LAYER_HANDLE) { printf ("JoinLayer: invalid layer handle.\n"); exit (1); }#endif InitCreateInfo (&CreateInfo); hMainWnd = CreateMainWindow (&CreateInfo); if (hMainWnd == HWND_INVALID) return -1; while (GetMessage (&Msg, hMainWnd)) { TranslateMessage (&Msg); DispatchMessage (&Msg); } MainWindowThreadCleanup (hMainWnd); return 0;}#ifndef _LITE_VERSION#include <minigui/dti.c>#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -