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

📄 rddraw.c

📁 pgp soucecode pgp soucecode
💻 C
📖 第 1 页 / 共 2 页
字号:

				if(pui->pru->kind==kPGPRecipientUserKind_MissingRecipient)
					SelectObject(lpDrawItem->hDC,
						ds->hStrikeOut);

				// See if we need the lock icon
				if(pui->pru->lockRefCount!=0)
				{
					RECT temprc;

					CopyRect(&temprc,&rc);
					temprc.left=temprc.right-16;

					if(temprc.left>rc.left)
					{
						// Enough space. Draw Lock
						if((BOOL)(lpDrawItem->itemState & ODS_SELECTED)&&focused)
						{
							FillRect (lpDrawItem->hDC, &temprc, ds->HighBrush);
						}
						else
						{
							FillRect (lpDrawItem->hDC, &temprc, ds->BackBrush);
						}

						ImageList_Draw(ds->hIml,IDX_CLOSEDLOCK,
							lpDrawItem->hDC,
							temprc.left+((CX_SMICON-16)/2),
							temprc.top+((CY_SMICON-16)/2),
							ILD_TRANSPARENT);

						// Make space for lock from text
						rc.right=rc.right-16;
					}
				}

				DrawItemColumn(lpDrawItem->hDC,pui->UserId,
					&rc);

				// Set rectangle back to original
				CopyRect(&rc,&origrc);

				SelectObject(lpDrawItem->hDC,oldFont);
				break;
			}

			case 1:
			{
				if(ds->DisplayMarginal)
					DrawBar(ds,lpDrawItem->hDC,&rc,pui->Validity,
						2,(BOOL)(lpDrawItem->itemState & ODS_SELECTED)&&focused);
				else
					DrawNoviceButton(ds,lpDrawItem->hDC,&rc,pui->Validity,
						2,(BOOL)(lpDrawItem->itemState & ODS_SELECTED)&&focused);
				break;
			}

/*			case 2: // we no longer display trust in rec dlg
			{
				DrawBar(ds,lpDrawItem->hDC,&rc,pui->Trust,
					2,(BOOL)(lpDrawItem->itemState & ODS_SELECTED)&&focused);
				break;
			}
*/
			case 2:
			{
				HFONT oldFont;

				oldFont=SelectObject(lpDrawItem->hDC,
						ds->hFont);

				DrawItemColumn(lpDrawItem->hDC,pui->szSize,
					&rc);

				SelectObject(lpDrawItem->hDC,oldFont);
				break;
			}
		}
		rc.left=rc.right;
	}
	lpDrawItem->rcItem.right=max;
}

//
//  DrawListViewItem
//
//  This routine, given a standard Windows LPDRAWITEMSTRUCT, draws the
//  elements of our custom listview (adapted from a routine in the Microsoft
//  Knowledge base)
//

void DrawListViewItem(LPDRAWITEMSTRUCT lpDrawItem)
{
    UINT uiFlags;
	BOOL focused;

	focused=TRUE;

	if(lpDrawItem->hwndItem!=0)
	{
		if(GetFocus()!=lpDrawItem->hwndItem)
			focused=FALSE;
	}

	uiFlags=ILD_TRANSPARENT;

    // Check to see if this item is selected
    if ((lpDrawItem->itemState & ODS_SELECTED)&&(focused))
    {
        // Set the text background and foreground colors
        SetTextColor(lpDrawItem->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
        SetBkColor(lpDrawItem->hDC, GetSysColor(COLOR_HIGHLIGHT));
    
        // Also add the ILD_BLEND50 so the images come out selected
        uiFlags |= ILD_BLEND50;
    }
    else
    {
        // Set the text background and foreground colors to the 
        // standard window colors
        SetTextColor(lpDrawItem->hDC, GetSysColor(COLOR_WINDOWTEXT));
        SetBkColor(lpDrawItem->hDC, GetSysColor(COLOR_WINDOW));
    }

	DrawStuff(lpDrawItem);

	lpDrawItem->rcItem.left=lpDrawItem->rcItem.left+CX_SMICON;

	if(!focused)
		return;

    // If we changed the colors for the selected item, undo it
    if (lpDrawItem->itemState & ODS_SELECTED)
    {
        // Set the text background and foreground colors
        SetTextColor(lpDrawItem->hDC, GetSysColor(COLOR_WINDOWTEXT));
        SetBkColor(lpDrawItem->hDC, GetSysColor(COLOR_WINDOW));
    }

    // If the item is focused, now draw a focus rect around the entire row
    if (lpDrawItem->itemState & ODS_FOCUS)
    {
        // Draw the focus rect
        DrawFocusRect(lpDrawItem->hDC, &(lpDrawItem->rcItem));
    }

    return;
}


// DrawItemColumn
//
// Given a clipping rectange and some text, see how well we can fit
// it in there, and tack on ... if we can't

void DrawItemColumn(HDC hdc, LPTSTR lpsz, LPRECT prcClip)
{
    TCHAR szString[256];

    // Check to see if the string fits in the clip rect.  If not, truncate
    // the string and add "...".
    lstrcpy(szString, lpsz);
    CalcStringEllipsis(hdc, szString, 256, prcClip->right - prcClip->left);

    // print the text

    ExtTextOut(hdc, prcClip->left + 2, prcClip->top + 1, 
               ETO_CLIPPED | ETO_OPAQUE,
               prcClip, szString, lstrlen(szString), NULL);
}


// CalcStringEllipsis
//
// Trial and error routine used to see where to put the ... in our string
// to make it fit within a clipping rectangle.

BOOL CalcStringEllipsis(HDC hdc, LPTSTR lpszString, 
                        int cchMax, UINT uColWidth)
{
    const TCHAR szEllipsis[] = TEXT("...");
    SIZE   sizeString;
    SIZE   sizeEllipsis;
    int    cbString;
    LPTSTR lpszTemp;
    BOOL   fSuccess = FALSE;
    BOOL fOnce = TRUE;
    FARPROC pGetTextExtentPoint;

    if (fOnce)
    {
        fOnce = FALSE;

        pGetTextExtentPoint = &GetTextExtentPoint;
    }

    // Adjust the column width to take into account the edges
    uColWidth -= 4;

    {
        // Allocate a string for us to work with.  This way we can mangle the
        // string and still preserve the return value
        lpszTemp = (LPTSTR) malloc(cchMax);
        lstrcpy(lpszTemp, lpszString);

        // Get the width of the string in pixels
        cbString = lstrlen(lpszTemp);
        (pGetTextExtentPoint)(hdc, lpszTemp, cbString, &sizeString);

        // If the width of the string is greater than the column width shave
        // the string and add the ellipsis
        if ((ULONG)sizeString.cx > uColWidth)
        {
            (pGetTextExtentPoint)(hdc, szEllipsis, lstrlen(szEllipsis),
                                       &sizeEllipsis);

            while (cbString > 0)
            {
                lpszTemp[--cbString] = 0;
                (pGetTextExtentPoint)(hdc, lpszTemp, cbString, &sizeString);

                if ((ULONG)(sizeString.cx + sizeEllipsis.cx) <= uColWidth)
                {
                // The string with the ellipsis finally fits, now make sure
                // there is enough room in the string for the ellipsis
                    if (cchMax >= (cbString + lstrlen(szEllipsis)))
                    {
                    // Concatenate the two strings and break out of the loop
                        lstrcat(lpszTemp, szEllipsis);
                        lstrcpy(lpszString, lpszTemp);
                        fSuccess = TRUE;
                        break;
                    }
                }
            }
        }
        else
        {
            // No need to do anything, everything fits great.
            fSuccess = TRUE;
        }
    }

    // Free the memory
    free(lpszTemp);
    return (fSuccess);
}


// Main_OnDrawItem
//
// Entry function for the message handler. Basically, we want to draw
// the whole thing no matter what.

BOOL Main_OnDrawItem(HWND hwnd, const DRAWITEMSTRUCT * lpDrawItem)
{

    // Make sure the control is the listview control
    if ((lpDrawItem->CtlType != ODT_LISTVIEW)&&
		(lpDrawItem->CtlType != ODT_LISTBOX))
        return FALSE;
 
	if(!IsWindowEnabled(lpDrawItem->hwndItem))
		return FALSE;

    switch (lpDrawItem->itemAction)
    {
        case ODA_DRAWENTIRE:
        case ODA_FOCUS:
        case ODA_SELECT:
            DrawListViewItem((LPDRAWITEMSTRUCT)lpDrawItem);
            break;
    }

    return TRUE;
}

// Main_OnMeasureItem
//
// Entry function for the message handler. We need to get the width and
// height of the font we're using.

void Main_OnMeasureItem(HWND hwnd, MEASUREITEMSTRUCT * lpMeasureItem)
{
    TEXTMETRIC tm;
    HDC hdc;
    HWND hwndLV;
    HFONT hFont;

    // Make sure the control is the listview control
    if ((lpMeasureItem->CtlType != ODT_LISTVIEW)&&
		(lpMeasureItem->CtlType != ODT_LISTBOX))
        return;

    // Get the handle of the ListView control we're using
    hwndLV = GetDlgItem(hwnd, lpMeasureItem->CtlID);

    // Get the font the control is currently using
    hFont = (HFONT)(DWORD) SendMessage(hwndLV, WM_GETFONT, 0, 0L);

    // Set the font of the DC to the same font the control is using
    hdc = GetDC(hwndLV);
    SelectObject(hdc, hFont);

    // Get the height of the font used by the control
    if (!GetTextMetrics(hdc, &tm))
        return;

    // Add a little extra space between items
    lpMeasureItem->itemHeight = tm.tmHeight + 1;

    // Make sure there is enough room for the images which are CY_SMICON high
    if (lpMeasureItem->itemHeight < (CY_SMICON + 1))
        lpMeasureItem->itemHeight = CY_SMICON + 1;

    // Clean up
    ReleaseDC(hwndLV, hdc);
}


/*__Editor_settings____

	Local Variables:
	tab-width: 4
	End:
	vi: ts=4 sw=4
	vim: si
_____________________*/

⌨️ 快捷键说明

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