• minigui中使用ttf字体库流程


    1. 在资源文件中添加字体库资源

    2. 配置MiniguiCfg文件

    3. 添加字体

    4. 打开字体文件

     5. 输出文字

    6. 使用完毕,回收资源

    命名规则参见《MINIGUI-USER-MANUAL-V3.0》3.1.5 小节

     参考:

    https://blog.csdn.net/10km/article/details/81106793

    https://blog.csdn.net/10km/article/details/81114067

    附:

    #include "list_function_view.h"
    
    static ListFunctionView *listFunctionData = NULL;
    
    static PLOGFONT mFont_SimSun20;
    static PLOGFONT mFont_SimSun30;
    
    static const char *kaiti[] = 
    {
        "背包",
            "浴巾",
            "雪纺",
            "童装",
            "衬衫"
    };
    
    
    #define __ID_TIMER_SLIDER 100
    static int ListFunctionViewProc(HWND hwnd, int message, WPARAM wParam,
            LPARAM lParam) {
            
        //HDC hdc;
    
    
        switch (message) {
        case MSG_CREATE:
            mFont_SimSun20 = CreateLogFont("ttf", "simkai", "UTF-8",
            FONT_WEIGHT_BOOK, FONT_SLANT_ROMAN,
            FONT_FLIP_NIL, FONT_OTHER_AUTOSCALE,
            FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE, 50, 2700);
            mFont_SimSun30 = CreateLogFont("ttf", "simkai", "UTF-8",
            FONT_WEIGHT_BOOK, FONT_SLANT_ROMAN,
            FONT_FLIP_NIL, FONT_OTHER_AUTOSCALE,
            FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE, 60, 2700);
    
            return 0;
        case MSG_PAINT: {
            HDC hdc = BeginPaint(hwnd);
            RECT rect;
            GetClientRect(hwnd, &rect);
    
            SetBkMode(hdc, BM_TRANSPARENT);
            SetTextColor(hdc, RGB2Pixel(HDC_SCREEN, 255, 255, 255));
            SelectFont(hdc, mFont_SimSun20);
            /* Zoom out on other items */
            if (listFunctionData->currentIndex - 1 >= 0 &&
                    listFunctionData->listFunctionImg[listFunctionData->currentIndex - 1].bmBits) 
            {
                FillBoxWithBitmap(hdc, 0, 30, 45, 120,
                        &listFunctionData->listFunctionImg[listFunctionData->currentIndex
                                - 1]);
                TextOut(hdc, 50,  80, kaiti[listFunctionData->currentIndex - 1]);
            }
    
            /* Zoom out on other items */
            if (listFunctionData->currentIndex + 1 <= 4
                    && listFunctionData->listFunctionImg[listFunctionData->currentIndex
                            + 1].bmBits) {
                FillBoxWithBitmap(hdc, 195, 30, 45, 120,
                        &listFunctionData->listFunctionImg[listFunctionData->currentIndex
                                + 1]);
                TextOut(hdc, 240,  80, kaiti[listFunctionData->currentIndex
                                + 1]);
            }
    
            if (listFunctionData->currentIndex >= 0
                    && listFunctionData->listFunctionImg[listFunctionData->currentIndex].bmBits) {
                FillBoxWithBitmap(hdc, 90, 10, 0, 0,
                        &listFunctionData->listFunctionImg[listFunctionData->currentIndex]);
                SelectFont(hdc, mFont_SimSun30);
                TextOut(hdc, 150, 65, kaiti[listFunctionData->currentIndex]);
            }
    
            /* Draw yellow line */
            SetBrushColor(hdc, RGB2Pixel(HDC_SCREEN, 255, 179, 9));
            FillBox(hdc, 0, 0, rect.right, 2);
    
            /* Draw gray line */
            int selectWidth = rect.right / (listFunctionData->listSize - 1)
                    * listFunctionData->currentIndex;
            SetBrushColor(hdc, PIXEL_darkgray);
            FillBox(hdc, rect.right - selectWidth, 0, selectWidth, 2);
    
            EndPaint(hwnd, hdc);
            return 0;
        }
        case MSG_LIST_FUNCTION_SELECT_UPDATE: {
            sm_debug("%d
    ", wParam);
            switch (wParam) {
            case CVR_KEY_MODE:
                if (listFunctionData->currentIndex < 4) {
                    listFunctionData->currentIndex++;
                    //UpdateWindow(hwnd, TRUE);
                    BroadcastMessage(MSG_LIST_FUNCTION_SELECT_CHANGE,
                            GetDlgCtrlID(hwnd),
                            (LPARAM) listFunctionData->currentIndex);
                }
                break;
            case CVR_KEY_MENU:
                if (listFunctionData->currentIndex > 0) {
                    listFunctionData->currentIndex--;
                    //UpdateWindow(hwnd, TRUE);
                    BroadcastMessage(MSG_LIST_FUNCTION_SELECT_CHANGE,
                            GetDlgCtrlID(hwnd),
                            (LPARAM) listFunctionData->currentIndex);
                }
                break;
            }
            break;
        }
        case MSG_DESTROY: {
            if (listFunctionData != NULL) {
                int i;
                for (i = 0; i < listFunctionData->listSize; i++) {
                    unloadBitMap(&listFunctionData->listFunctionImg[i]);
                }
                free(listFunctionData);
                listFunctionData = NULL;
            }
            DestroyLogFont(mFont_SimSun20);
            DestroyLogFont(mFont_SimSun30);
            return 0;
        }
        }
        return DefaultControlProc(hwnd, message, wParam, lParam);
    }
    
    static ListFunctionView* ListFunctionDataInit(
            ListFunctionView *listFunctionData) {
        listFunctionData = (ListFunctionView*) malloc(sizeof(ListFunctionView));
        if (NULL == listFunctionData) {
            sm_error("malloc ListFunctionView data error
    ");
        }
        memset((void *) listFunctionData, 0, sizeof(ListFunctionView));
        listFunctionData->listSize = 6;
    
        int i = 0;
        for (i = 0; i < listFunctionData->listSize; i++) {
            setCurrentIconValue(ID_LIST_FUNCTION_IMG, i);
            getResBmp(ID_LIST_FUNCTION_IMG, BMPTYPE_BASE,
                    &listFunctionData->listFunctionImg[i]);
        }
    
        return listFunctionData;
    }
    
    HWND ListFunctionViewInit(HWND hParent) {
        HWND mHwnd;
        smRect rect;
        getResRect(ID_LIST_FUNCTION_AREA, &rect);
        listFunctionData = ListFunctionDataInit(listFunctionData);
        mHwnd = CreateWindowEx(LIST_FUNCTION_VIEW, "",
        WS_CHILD | WS_VISIBLE, WS_EX_TRANSPARENT, 0, rect.x, rect.y, rect.w, rect.h,
                hParent, 0);
    
        if (mHwnd == HWND_INVALID) {
            return HWND_INVALID;
        }
    
        return mHwnd;
    }
    
    BOOL RegisterListFunctionView() {
        WNDCLASS MyClass;
        MyClass.spClassName = LIST_FUNCTION_VIEW;
        MyClass.dwStyle = WS_NONE;
        MyClass.dwExStyle = WS_EX_NONE;
        MyClass.hCursor = GetSystemCursor(0);
        MyClass.iBkColor = PIXEL_black;
        MyClass.WinProc = ListFunctionViewProc;
    
        return RegisterWindowClass(&MyClass);
    }
    
    void UnregisterListFunctionView(void) {
        UnregisterWindowClass(LIST_FUNCTION_VIEW);
    }
    

      

  • 相关阅读:
    小程序 ----- 使用less框架
    小程序 ------ 选择器(十)
    小程序 ------ 样式(九)
    小程序 --- 事件绑定(八)
    记一次接口数据获取最大最小值
    flutter——命名路由跳转传值
    Dart——库
    Dart——基础
    人口普查小结
    人口普查-运行截图
  • 原文地址:https://www.cnblogs.com/hanrp/p/11649690.html
Copyright © 2020-2023  润新知