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

📄 window.c

📁 在ADS环境下MiniGUI的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
                    }
                }
                else {  /* wParam == HT_OUT */
                    open_ime_window (pWin, FALSE, HWND_DESKTOP);
                }
            }
        break;
    }

    return 0;
}

// this function is CONTROL safe.
static void wndDrawNCArea (const MAINWIN* pWin, HDC hdc)
{
    // Draw window frame
    if (pWin->dwStyle & WS_BORDER) {
#if defined(_FLAT_WINDOW_STYLE) || defined(_PHONE_WINDOW_STYLE)
        int i, iBorder;

        iBorder = GetMainWinMetrics (MWM_BORDER);
        SetPenColor (hdc, GetWindowElementColorEx ((HWND)pWin, WEC_FLAT_BORDER));
        for (i = 0; i < iBorder; i++)
            Rectangle (hdc, i, i, 
                      pWin->right - pWin->left - i - 1, 
                      pWin->bottom - pWin->top - i - 1);
#else

        if (pWin->dwStyle & WS_CHILD)
            Draw3DThickFrameEx (hdc, (HWND)pWin,
                   0, 0, 
                   pWin->right - pWin->left - 1, 
                   pWin->bottom - pWin->top - 1, 
                   DF_3DBOX_PRESSED | DF_3DBOX_NOTFILL, 0);
        else
            Draw3DThickFrameEx (hdc, (HWND)pWin,
                   0, 0, 
                   pWin->right - pWin->left, 
                   pWin->bottom - pWin->top, 
                   DF_3DBOX_NORMAL | DF_3DBOX_NOTFILL, 0);
#endif
    }
    else if ((pWin->dwStyle & WS_THICKFRAME) ||
            (pWin->dwStyle & WS_THINFRAME))
    {
       SetPenColor(hdc, GetWindowElementColorEx ((HWND)pWin, WEC_FRAME_NORMAL));
       Rectangle(hdc, 0, 0, 
                      pWin->right - pWin->left - 1, 
                      pWin->bottom - pWin->top - 1);
    }

}

// this function is CONTROL safe.
static void wndDrawScrollBar (MAINWIN* pWin, HDC hdc)
{
    int start = 0;
    RECT rcHBar, rcVBar, rcSlider;
    PBITMAP bmp;
    int xo, yo, bw, bh;
    
    wndGetVScrollBarRect (pWin, &rcVBar);
    rcVBar.left -= pWin->left;
    rcVBar.top  -= pWin->top;
    rcVBar.right -= pWin->left;
    rcVBar.bottom -= pWin->top;
    wndGetHScrollBarRect (pWin, &rcHBar);
    rcHBar.left -= pWin->left;
    rcHBar.top  -= pWin->top;
    rcHBar.right -= pWin->left;
    rcHBar.bottom -= pWin->top;

    bmp = GetSystemBitmap (SYSBMP_ARROWS);
    bw = bmp->bmWidth >> 2;
    bh = bmp->bmHeight >> 1;

    if ((pWin->dwStyle & WS_HSCROLL) && (pWin->dwStyle & WS_VSCROLL)
            && !(pWin->hscroll.status & SBS_HIDE 
                && pWin->vscroll.status & SBS_HIDE)) {
        /* Always erase the bottom-right corner */
#ifdef _FLAT_WINDOW_STYLE
        SetBrushColor (hdc, PIXEL_lightwhite);
#else
        SetBrushColor (hdc, GetWindowElementColorEx ((HWND)pWin, BKC_CONTROL_DEF));
#endif
        FillBox (hdc, rcVBar.left, rcHBar.top, RECTW (rcVBar), RECTH (rcHBar));
    }

    if (pWin->dwStyle & WS_HSCROLL 
                && !(pWin->hscroll.status & SBS_HIDE) && RectVisible (hdc, &rcHBar)) {
        /* draw left and right buttons. */
        if (pWin->hscroll.status & SBS_DISABLED) {
            xo = bw << 1; yo = bh;
        }
        else {
            xo = bw << 1; yo = 0;
        }
        
        FillBoxWithBitmapPart (hdc, rcHBar.left, rcHBar.top, 
                                bw, bh, 0, 0, bmp, xo, yo);

        if (pWin->hscroll.status & SBS_DISABLED) {
            xo = (bw << 1) + bw; yo = bh;
        }
        else {
            xo = (bw << 1) + bw; yo = 0;
        }
        
        FillBoxWithBitmapPart (hdc, 
                        rcHBar.right - GetMainWinMetrics (MWM_CXHSCROLL), rcHBar.top,
                        bw, bh, 0, 0, bmp, xo, yo);

        /* draw slider. */
        start = rcHBar.left +
                    GetMainWinMetrics (MWM_CXHSCROLL) +
                    pWin->hscroll.barStart;

        if (start + pWin->hscroll.barLen > rcHBar.right)
            start = rcHBar.right - pWin->hscroll.barLen;

        rcSlider.left = start;
        rcSlider.top = rcHBar.top;
        rcSlider.right = start + pWin->hscroll.barLen;
        rcSlider.bottom = rcHBar.bottom;

#ifdef _FLAT_WINDOW_STYLE
        SetBrushColor (hdc, GetWindowElementColorEx ((HWND)pWin, BKC_CONTROL_DEF));
        FillBox (hdc, start + 1, rcHBar.top + 1, 
                pWin->hscroll.barLen - 2, RECTH (rcHBar) - 1);
        SetPenColor (hdc, PIXEL_black);
        Rectangle (hdc, rcSlider.left, rcSlider.top, rcSlider.right - 1, rcSlider.bottom);

        xo = (rcSlider.left + rcSlider.right) >> 1;
        MoveTo (hdc, xo, rcSlider.top + 2);
        LineTo (hdc, xo, rcSlider.bottom - 1);
        MoveTo (hdc, xo - 2, rcSlider.top + 3);
        LineTo (hdc, xo - 2, rcSlider.bottom - 2);
        MoveTo (hdc, xo + 2, rcSlider.top + 3);
        LineTo (hdc, xo + 2, rcSlider.bottom - 2);

        SetPenColor (hdc, PIXEL_black);
        Rectangle (hdc, rcHBar.left - 1, rcHBar.top, rcHBar.right, rcHBar.bottom);
#elif defined(_PHONE_WINDOW_STYLE)
        DrawBoxFromBitmap (hdc, &rcSlider, GetSystemBitmap (SYSBMP_SCROLLBAR_HSLIDER), TRUE, FALSE);
#else
        Draw3DThickFrameEx (hdc, (HWND)pWin, 
                            rcSlider.left, rcHBar.top,
                            rcSlider.right, rcHBar.bottom,
                            DF_3DBOX_NORMAL | DF_3DBOX_FILL, 
                            GetWindowElementColorEx ((HWND)pWin, BKC_CONTROL_DEF));
#endif

        rcHBar.left += GetMainWinMetrics (MWM_CXHSCROLL);
        rcHBar.right -= GetMainWinMetrics (MWM_CXHSCROLL);

        /* Exclude the rect of slider */
        ExcludeClipRect (hdc, &rcSlider);

        /* Draw back bar */
#ifdef _FLAT_WINDOW_STYLE
        SetBrushColor (hdc, PIXEL_lightwhite);
        FillBox (hdc, rcHBar.left + 1, rcHBar.top + 1, RECTW(rcHBar) - 1, RECTH (rcHBar) - 1);
#elif defined(_PHONE_WINDOW_STYLE)
        DrawBoxFromBitmap (hdc, &rcHBar, GetSystemBitmap (SYSBMP_SCROLLBAR_HBG), TRUE, FALSE);
#else
        SetBrushColor (hdc, GetWindowElementColorEx ((HWND)pWin, BKC_CONTROL_DEF));
        FillBox (hdc, rcHBar.left, rcHBar.top, RECTW(rcHBar), RECTH (rcHBar));
#endif
    }

    if (pWin->dwStyle & WS_VSCROLL 
                && !(pWin->vscroll.status & SBS_HIDE) && RectVisible (hdc, &rcVBar)) {

        /* draw top and bottom arrow buttons. */
        if (pWin->vscroll.status & SBS_DISABLED) {
            xo = 0; yo = bh;
        }
        else {
            xo = 0; yo = 0;
        }

        FillBoxWithBitmapPart (hdc, rcVBar.left, rcVBar.top, 
                        bw, bh, 0, 0, bmp, xo, yo);

        if (pWin->vscroll.status & SBS_DISABLED) {
            xo = bw; yo = bh;
        }
        else {
            xo = bw; yo = 0;
        }
        
        FillBoxWithBitmapPart (hdc, 
                        rcVBar.left, rcVBar.bottom - GetMainWinMetrics (MWM_CYVSCROLL),
                        bw, bh, 0, 0, bmp, xo, yo);

        /* draw slider */
        start = rcVBar.top +
                    GetMainWinMetrics (MWM_CYVSCROLL) +
                    pWin->vscroll.barStart;
                    
        if (start + pWin->vscroll.barLen > rcVBar.bottom)
            start = rcVBar.bottom - pWin->vscroll.barLen;

        rcSlider.left = rcVBar.left;
        rcSlider.top = start;
        rcSlider.right = rcVBar.right;
        rcSlider.bottom = start + pWin->vscroll.barLen;

#ifdef _FLAT_WINDOW_STYLE
        SetBrushColor (hdc, GetWindowElementColorEx ((HWND)pWin, BKC_CONTROL_DEF));
        FillBox (hdc, rcVBar.left + 1, start + 1, 
                RECTW (rcVBar) - 1, pWin->vscroll.barLen - 2);
        SetPenColor (hdc, PIXEL_black);
        Rectangle (hdc, rcSlider.left, rcSlider.top, rcSlider.right, rcSlider.bottom - 1);

        yo = (rcSlider.top + rcSlider.bottom) >> 1;
        MoveTo (hdc, rcSlider.left + 2, yo);
        LineTo (hdc, rcSlider.right - 1, yo);
        MoveTo (hdc, rcSlider.left + 3, yo - 2);
        LineTo (hdc, rcSlider.right - 2, yo - 2);
        MoveTo (hdc, rcSlider.left + 3, yo + 2);
        LineTo (hdc, rcSlider.right - 2, yo + 2);

        SetPenColor (hdc, PIXEL_black);
        Rectangle (hdc, rcVBar.left, rcVBar.top - 1, rcVBar.right, rcVBar.bottom);
#elif defined(_PHONE_WINDOW_STYLE)
        DrawBoxFromBitmap (hdc, &rcSlider, GetSystemBitmap (SYSBMP_SCROLLBAR_VSLIDER), FALSE, FALSE);
#else
        Draw3DThickFrameEx (hdc, (HWND)pWin, 
                            rcVBar.left, rcSlider.top, rcVBar.right, rcSlider.bottom,
                            DF_3DBOX_NORMAL | DF_3DBOX_FILL,
                            GetWindowElementColorEx ((HWND)pWin, BKC_CONTROL_DEF));
#endif

        rcVBar.top += GetMainWinMetrics (MWM_CYVSCROLL);
        rcVBar.bottom -= GetMainWinMetrics (MWM_CYVSCROLL);

        /* Exclude the rect of slider */
        ExcludeClipRect (hdc, &rcSlider);

        /* draw back bar */
#ifdef _FLAT_WINDOW_STYLE
        SetBrushColor (hdc, PIXEL_lightwhite);
        FillBox (hdc, rcVBar.left + 1, rcVBar.top + 1, RECTW (rcVBar) - 1, RECTH (rcVBar) - 1);
#elif defined(_PHONE_WINDOW_STYLE)
        DrawBoxFromBitmap (hdc, &rcVBar, GetSystemBitmap (SYSBMP_SCROLLBAR_VBG), FALSE, FALSE);
#else
        SetBrushColor (hdc, GetWindowElementColorEx ((HWND)pWin, BKC_CONTROL_DEF));
        FillBox (hdc, rcVBar.left, rcVBar.top, RECTW (rcVBar), RECTH (rcVBar));
#endif
    }
}

// this function is CONTROL safe.
static void wndDrawCaption(const MAINWIN* pWin, HDC hdc, BOOL bFocus)
{
    int i;
    RECT rc;
    int iBorder = 0;
    int iCaption = 0, bCaption;
    int iIconX = 0;
    int iIconY = 0;
    int x, y, w, h;
#if defined(_FLAT_WINDOW_STYLE) && defined(_GRAY_SCREEN)
    SIZE text_ext;
#endif
    PBITMAP bmp;
    int bw, bh;

    bmp = GetSystemBitmap (SYSBMP_CAPBTNS);
    bw = bmp->bmWidth >> 2;
    bh = bmp->bmHeight;

    if (pWin->dwStyle & WS_BORDER) 
        iBorder = GetMainWinMetrics(MWM_BORDER);
    else if( pWin->dwStyle & WS_THICKFRAME ) {
        iBorder = GetMainWinMetrics(MWM_THICKFRAME);
        
        SetPenColor (hdc, bFocus
                            ? GetWindowElementColorEx ((HWND)pWin, WEC_FRAME_ACTIVED)
                            : GetWindowElementColorEx ((HWND)pWin, WEC_FRAME_NORMAL));
        for (i=1; i<iBorder; i++)
            Rectangle(hdc, i, i, 
                      pWin->right - pWin->left - i - 1, 
                      pWin->bottom - pWin->top - i - 1);

    }
    else if (pWin->dwStyle & WS_THINFRAME)
        iBorder = GetMainWinMetrics (MWM_THINFRAME);

    if (!(pWin->dwStyle & WS_CAPTION))
        return;

    if (pWin->hIcon ) {
        iIconX = GetMainWinMetrics(MWM_ICONX);
        iIconY = GetMainWinMetrics(MWM_ICONY);
    }


    iCaption = GetMainWinMetrics(MWM_CAPTIONY);
    bCaption = iBorder + iCaption - 1;

    // draw Caption
    rc.left = iBorder;
    rc.top = iBorder;
    rc.right = pWin->right - pWin->left - iBorder;
    rc.bottom = iBorder + iCaption;
    ClipRectIntersect (hdc, &rc);

    SelectFont (hdc, GetSystemFont (SYSLOGFONT_CAPTION));

#ifdef _FLAT_WINDOW_STYLE
#ifdef _GRAY_SCREEN
    GetTextExtent (hdc, pWin->spCaption, -1, &text_ext);
    if (pWin->hIcon) text_ext.cx += iIconX + 2;

    SetBrushColor (hdc, bFocus
                        ? GetWindowElementColorEx ((HWND)pWin, BKC_CAPTION_ACTIVED)
                        : GetWindowElementColorEx ((HWND)pWin, BKC_CAPTION_NORMAL));
    FillBox (hdc, iBorder, iBorder, text_ext.cx + 4, bCaption);

    SetBrushColor(hdc, GetWindowElementColorEx ((HWND)pWin, FGC_CAPTION_ACTIVED));
    FillBox (hdc, iBorder + text_ext.cx + 4, iBorder,
               pWin->right - pWin->left, bCaption);

    SetPenColor(hdc, bFocus
                        ? GetWindowElementColorEx ((HWND)pWin, BKC_CAPTION_ACTIVED)
                        : GetWindowElementColorEx ((HWND)pWin, BKC_CAPTION_NORMAL));

    MoveTo (hdc, iBorder, bCaption);
    LineTo (hdc, pWin->right - pWin->left, bCaption);

    SetPenColor(hdc, GetWindowElementColorEx ((HWND)pWin, FGC_CAPTION_ACTIVED));

    MoveTo (hdc, iBorder + text_ext.cx + 4, bCaption - 3);
    LineTo (hdc, iBorder + text_ext.cx + 2, bCaption - 1);
    MoveTo (hdc, iBorder + text_ext.cx + 4, bCaption - 2);
    LineTo (hdc, iBorder + text_ext.cx + 3, bCaption - 1);

    MoveTo (hdc, iBorder + text_ext.cx + 2, iBorder);
    LineTo (hdc, iBorder + text_ext.cx + 4, iBorder + 2);
    MoveTo (hdc, iBorder + text_ext.cx + 3, iBorder);
    LineTo (hdc, iBorder + text_ext.cx + 4, iBorder + 1);
#else
    {
        unsigned char bits [256];
        BITMAP bmp;

        InitBitmap (hdc, 64, 1, 128, bits, &bmp);

        if (bFocus) {
            int i;
            Uint8 r, g, b;
            gal_pixel pixel;

            Pixel2RGB (hdc, GetWindowElementColorEx ((HWND)pWin, BKC_CAPTION_ACTIVED), &r, &g, &b);
            if (r > 191) r = 255; else r += 64;
            if (g > 191) g = 255; else g += 64;
            if (b > 191) b = 255; else b += 64;
            for (i = 0; i < 64; i++) {
                pixel = RGB2Pixel (hdc, r - i, g - i, b - i);
                SetPixelInBitmap (&bmp, 63 - i, 0, pixel);
            }
        }
        else {
            int i;
            Uint8 r, g, b;
            gal_pixel pixel;

            Pixel2RGB (hdc, GetWindowElementColorEx ((HWND)pWin, BKC_CAPTION_NORMAL), &r, &g, &b);
            if (r > 191) r = 255; else r += 64;
            if (g > 191) g = 255; else g += 64;
            if (b > 191) b = 255; else b += 64;
            for (i = 0; i < 64; i++) {
                pixel = RGB2Pixel (hdc, r - i, g - i, b - i);
                SetPixelInBitmap (&bmp, 63 - i, 0, pixel);
            }
        }

        FillBoxWithBitmap (hdc, iBorder, iBorder,
                                pWin->right - pWin->left - (iBorder << 1), 
                                bCaption + 1, &bmp);
    }
#endif
#else
    SetBrushColor (hdc, bFocus
                        ? GetWindowElementColorEx ((HWND)pWin, BKC_CAPTION_ACTIVED)
                        : GetWindowElementColorEx ((HWND)pWin, BKC_CAPTION_NORMAL));
    FillBox(hdc, iBorder, iBorder,
                       pWin->right - pWin->left - iBorder,
                       bCaption + 1);
#endif

    if (pWin->hIcon)
        DrawIcon (hdc, iBorder, iBorder + (bCaption - iIconY) / 2, 
                        iIconX, iIconY, pWin->hIcon);

    SetTextColor(hdc, bFocus
                        ? GetWindowElementColorEx ((HWND)pWin, FGC_CAPTION_ACTIVED)
  

⌨️ 快捷键说明

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