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

📄 uihelper.cpp.svn-base

📁 wince c++ 下 开发的 rss 阅读器源代码
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
    DeleteObject(hbmImage);
    return piml;
}

int HIDPI_ImageList_ReplaceIcon(HIMAGELIST himl, int i, HICON hicon)
{
    int iRet;
    int cxIcon, cyIcon;
    HICON hiconStretched;

    ImageList_GetIconSize(himl, &cxIcon, &cyIcon);
    HIDPI_StretchIcon_Internal(hicon, &hiconStretched, cxIcon, cyIcon);
    if (hiconStretched != NULL)
    {
        iRet = ImageList_ReplaceIcon(himl, i, hiconStretched);
        DestroyIcon(hiconStretched);
    }
    else
    {
        iRet = ImageList_ReplaceIcon(himl, i, hicon);
    }

    return iRet;
}

BOOL HIDPI_RectangleInternal(HDC hdc, int nLeft, int nTop, int nRight, int nBottom, int nThickness)
{
    int nOff = nThickness/2;

    nLeft   += nOff;
    nTop    += nOff;
    nRight  -= nOff;
    nBottom -= nOff;

    return Rectangle(hdc, nLeft, nTop, nRight, nBottom);
}

#define BORDERX_PEN 32

BOOL HIDPI_BorderRectangle(HDC hdc, int nLeft, int nTop, int nRight, int nBottom)
{
    HPEN hpenOld;
    BOOL bRet;

    hpenOld = (HPEN)SelectObject(hdc, (HPEN) GetStockObject(BORDERX_PEN));
    bRet = HIDPI_RectangleInternal(hdc, nLeft, nTop, nRight, nBottom, GetSystemMetrics(SM_CXBORDER));
    SelectObject(hdc, hpenOld);

    return bRet;
}

BOOL HIDPI_Rectangle(HDC hdc, int nLeft, int nTop, int nRight, int nBottom)
{
    LOGPEN lpenSel;
    HPEN hpenSel;

    // Obtain current pen thickness
    hpenSel = (HPEN)GetCurrentObject(hdc, OBJ_PEN);
    GetObject(hpenSel, sizeof(lpenSel), &lpenSel);

    return HIDPI_RectangleInternal(hdc, nLeft, nTop, nRight, nBottom, lpenSel.lopnWidth.x);
}


BOOL HIDPI_PolylineInternal(HDC hdc, const POINT *lppt, int cPoints, int nStyle, int nThickness)
{
    int i;
    int nHOff = 0, nVOff = 0;
    BOOL bRet = TRUE;
    POINT pts[2];

    if (! (nStyle & PS_BIAS_MASK))
    {
        // No drawing bias. Draw normally
        return Polyline(hdc, lppt, cPoints);
    }

    // Make sure caller didn't try to get both a left and a right bias or both a down and an up bias
    ASSERT(!(nStyle & PS_LEFTBIAS) || !(nStyle & PS_RIGHTBIAS));
    ASSERT(!(nStyle & PS_UPBIAS) || !(nStyle & PS_DOWNBIAS));

    if (nStyle & PS_LEFTBIAS)
    {
        nHOff = -((nThickness-1)/2);
    }

    if (nStyle & PS_RIGHTBIAS)
    {
        nHOff = nThickness/2;
    }

    if (nStyle & PS_UPBIAS)
    {
        nVOff = -((nThickness-1)/2);
    }

    if (nStyle & PS_DOWNBIAS)
    {
        nVOff = nThickness/2;
    }

    for (i = 1; i < cPoints; i++)
    {
        // Use the two points that specify current line segment
        memcpy(pts, &lppt[i-1], 2*sizeof(POINT));
        if (abs(lppt[i].x - lppt[i-1].x) <= abs(lppt[i].y - lppt[i-1].y))
        {
            // Shift current line segment horizontally if abs(slope) >= 1
            pts[0].x += nHOff;
            pts[1].x += nHOff;
        }
        else
        {
            // Shift current line segment vertically if abs(slope) < 1
            pts[0].y += nVOff;
            pts[1].y += nVOff;
        }
        bRet = bRet && Polyline(hdc, pts, 2);
        if (!bRet)
        {
            goto Error;
        }
    }

Error:
    return bRet;
}

BOOL HIDPI_BorderPolyline(HDC hdc, const POINT *lppt, int cPoints, int nStyle)
{
    HPEN hpenOld;
    BOOL bRet;

    hpenOld = (HPEN)SelectObject(hdc, (HPEN) GetStockObject(BORDERX_PEN));
    bRet = HIDPI_PolylineInternal(hdc, lppt, cPoints, nStyle,  GetSystemMetrics(SM_CXBORDER));
    SelectObject(hdc, hpenOld);

    return bRet;
}

BOOL HIDPI_Polyline(HDC hdc, const POINT *lppt, int cPoints, int nStyle)
{
    LOGPEN lpenSel;
    HPEN hpenSel;

    // Obtain current pen thickness
    hpenSel = (HPEN)GetCurrentObject(hdc, OBJ_PEN);
    GetObject(hpenSel, sizeof(lpenSel), &lpenSel);

    return HIDPI_PolylineInternal(hdc, lppt, cPoints, nStyle, lpenSel.lopnWidth.x);
}

//
// Called by RelayoutDialog to advance to the next item in the dialog template.
//
static LPBYTE WalkDialogData(LPBYTE lpData)
{
    LPWORD lpWord = (LPWORD)lpData;
    if (*lpWord == 0xFFFF)
    {
        return (LPBYTE)(lpWord + 2);
    }
    while (*lpWord != 0x0000)
    {
        lpWord++;
    }
    return (LPBYTE)(lpWord + 1);
}

//
// Post-processing step for each dialog item.
//    Static controls and buttons: change text and bitmaps.
//    Listboxes and combo boxes: ensures that the selected item is visible.
//
static void FixupDialogItem(
    HINSTANCE hInst,
    HWND hDlg,
    LPDLGITEMTEMPLATE lpDlgItem,
    LPWORD lpClass,
    LPWORD lpData)
{
    if (lpClass[0] == 0xFFFF)
    {
        switch (lpClass[1])
        {
            case 0x0080: // button
            case 0x0082: // static
            {
                if (lpData[0] == 0xFFFF)
                {
                    if (lpDlgItem->style & SS_ICON)
                    {
                        HICON hOld = (HICON)SendDlgItemMessageW(hDlg, lpDlgItem->id, STM_GETIMAGE, IMAGE_ICON, 0);
                        HICON hNew = LoadIcon(hInst, MAKEINTRESOURCE(lpData[1]));
                        SendDlgItemMessageW(hDlg, lpDlgItem->id, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hNew);
                        DestroyIcon(hOld);
                    }
                    else if (lpDlgItem->style & SS_BITMAP)
                    {
                        HBITMAP hOld = (HBITMAP)SendDlgItemMessageW(hDlg, lpDlgItem->id, STM_GETIMAGE, IMAGE_BITMAP, 0);
                        HBITMAP hNew = LoadBitmap(hInst, MAKEINTRESOURCE(lpData[1]));
                        SendDlgItemMessageW(hDlg, lpDlgItem->id, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hNew);
                        DeleteObject(hOld);
                    }
                }
                else // lpData[0] is not 0xFFFF (it's text).
                {
                    SetDlgItemTextW(hDlg, lpDlgItem->id, (LPCTSTR)lpData);
                }
            }
            break;

            case 0x0083: // list box
            {
                INT nSel = SendDlgItemMessageW(hDlg, lpDlgItem->id, LB_GETCURSEL, 0, 0);
                if (nSel != LB_ERR)
                {
                    SendDlgItemMessageW(hDlg, lpDlgItem->id, LB_SETCURSEL, nSel, 0);
                }
            }
            break;

            case 0x0085: // combo box
            {
                INT nSel = SendDlgItemMessageW(hDlg, lpDlgItem->id, CB_GETCURSEL, 0, 0);
                if (nSel != CB_ERR)
                {
                    SendDlgItemMessageW(hDlg, lpDlgItem->id, CB_SETCURSEL, nSel, 0);
                }
            }
            break;
        }
    }
}

BOOL RelayoutDialog(HINSTANCE hInst, HWND hDlg, LPCWSTR iddTemplate)
{
    HRSRC hRsrc = FindResource((HMODULE)hInst, iddTemplate, RT_DIALOG);
    if (hRsrc == NULL)
    {
        return FALSE;
    }

    HGLOBAL hGlobal = LoadResource((HMODULE)hInst, hRsrc);
    if (hGlobal == NULL)
    {
        return FALSE;
    }

    INT nStatics = 0;
    LPBYTE lpData = (LPBYTE)LockResource(hGlobal);
    LPDLGTEMPLATE lpTemplate = (LPDLGTEMPLATE)lpData;
    HDWP hDWP = BeginDeferWindowPos(lpTemplate->cdit);

    //
    // For more information about the data structures that we are walking,
    // consult the DLGTEMPLATE and DLGITEMTEMPLATE documentation on MSDN.
    //
    lpData += sizeof(DLGTEMPLATE);
    lpData = WalkDialogData(lpData);     // menu
    lpData = WalkDialogData(lpData);     // class
    lpData = WalkDialogData(lpData);     // title

    if (lpTemplate->style & DS_SETFONT)
    {
        lpData += sizeof(WORD);          // font size.
        lpData = WalkDialogData(lpData); // font face.
    }

    for (int i = 0; i < lpTemplate->cdit; i++)
    {
        lpData = (LPBYTE) (((INT)lpData + 3) & ~3);  // force to DWORD boundary.
        LPDLGITEMTEMPLATE lpDlgItem = (LPDLGITEMTEMPLATE)lpData;
        HWND hwndCtl = GetDlgItem(hDlg, lpDlgItem->id);

        if (lpDlgItem->id == 0xFFFF)
        {
            nStatics++;
        }

        //
        // Move the item around.
        //
        {
            RECT r;
            r.left   = lpDlgItem->x;
            r.top    = lpDlgItem->y;
            r.right  = lpDlgItem->x + lpDlgItem->cx;
            r.bottom = lpDlgItem->y + lpDlgItem->cy;
            MapDialogRect(hDlg, &r);
            DeferWindowPos(hDWP, hwndCtl, NULL,
                r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOZORDER);
        }

        lpData += sizeof(DLGITEMTEMPLATE);
        LPWORD lpClass = (LPWORD)lpData;
        lpData = WalkDialogData(lpData);  // class

        //
        // Do some special handling for each dialog item (changing text,
        // bitmaps, ensuring visible, etc.
        //
        FixupDialogItem(hInst, hDlg, lpDlgItem, lpClass, (LPWORD)lpData);

        lpData = WalkDialogData(lpData);  // title
        WORD cbExtra = *((LPWORD)lpData); // extra class data.
        lpData += (cbExtra ? cbExtra : sizeof(WORD));
    }

    EndDeferWindowPos(hDWP);
    return nStatics < 2 ? TRUE : FALSE;
}

⌨️ 快捷键说明

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