Exemplo n.º 1
0
LRESULT CALLBACK
MenuWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    int id, cnt, mnu;
    PAINTSTRUCT ps;
    CHAR    szString[256], *pszString;
    HDC	hDC;
    RECT rc;
    POINT pt;
    HFONT hFont, hFontOld;
    HBRUSH hBrush, hBrushOld;
    LPMEASUREITEMSTRUCT lpMI = NULL;
    LPDRAWITEMSTRUCT lpDI = NULL;
    SIZE size;
    MENUITEMINFO mii = { sizeof(MENUITEMINFO),MIIM_CHECKMARKS|MIIM_TYPE|MIIM_SUBMENU };
    NONCLIENTMETRICS nm;
    HMENU hMenu, hMenuTop;
    BOOL isMenuBar;
    static BOOL bFirst = TRUE;

    if (pOldWndProc == NULL)
        return DefWindowProc(hWnd, uMsg, wParam, lParam);

    hMenu = GetMenu(hWnd);

    if (bFirst == TRUE)
    {
        SetOwnerDraw(hMenu, TRUE);
        bFirst = FALSE;
    }

    switch(uMsg)
    {
    case WM_INITMENUPOPUP:
        if (HIWORD(lParam) == 0)
            SetOwnerDraw((HMENU)wParam, TRUE);
        break;
    case WM_MEASUREITEM:
        lpMI = (LPMEASUREITEMSTRUCT)lParam;
        GetMenuItemInfo((HMENU)hMenu, lpMI->itemID, FALSE, &mii);
        GetMenuString(hMenu, lpMI->itemID, szString, sizeof(szString), MF_BYCOMMAND);
        if (strlen(szString) == 0 && lpMI->itemData)
            strcpy(szString, (char*)lpMI->itemData);

        if ((mii.fType & MF_SEPARATOR) != 0 ||
                ((mii.fType & MF_BITMAP) == 0 && strlen(szString) == 0))
        {
            lpMI->itemHeight = GetSystemMetrics(SM_CYMENU) >> 1;
            lpMI->itemWidth = 0;
        }
        else if (mii.fType & MF_BITMAP)
Exemplo n.º 2
0
void CSkinBtn::PreSubclassWindow()
{
	// TODO: 在此添加专用代码和/或调用基类
	SetOwnerDraw(true);

//	CButton::PreSubclassWindow();
}
Exemplo n.º 3
0
void SetOwnerDraw(HMENU hMenu, BOOL bMode)
{
    int	id, mnu;
    MENUITEMINFO mii = { sizeof(MENUITEMINFO),MIIM_CHECKMARKS|MIIM_TYPE|MIIM_DATA };
    CHAR    szString[256];
    HMENU hSubMenu;

    if (hMenu == NULL)
        return;
    for(mnu = 0; mnu < GetMenuItemCount(hMenu); mnu++)
    {
        GetMenuItemInfo((HMENU)hMenu, mnu, TRUE, &mii);
        if (bMode)
        {
            mii.fType |= MFT_OWNERDRAW;
            if (mii.hSubMenu == NULL && (mii.fType & MF_SEPARATOR) == 0
                    && mii.dwItemData == 0)
            {
                LPSTR	pCopy;
                GetMenuString(hMenu, mnu, szString, sizeof(szString), MF_BYPOSITION);
                pCopy = strdup(szString);
                if (pCopy)
                {
                    mii.fMask |= MIIM_DATA;
                    mii.dwItemData = (DWORD)pCopy;
                }
            }
        }
        else
        {
            mii.fType &= ~MFT_OWNERDRAW;
            if (mii.hSubMenu == NULL && (mii.fType & MF_SEPARATOR) == 0)
            {
                mii.fMask &= ~MIIM_DATA;
                if (mii.dwItemData)
                {
                    free((LPSTR)mii.dwItemData);
                    mii.dwItemData = 0;
                }
            }
        }

        SetMenuItemInfo(hMenu, mnu, TRUE, &mii);

        hSubMenu = GetSubMenu(hMenu, mnu);
        if (hSubMenu)
            SetOwnerDraw(hSubMenu, bMode);
    }
}