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

📄 tlpaint.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 3 页
字号:
			}

		}
		else {		// ((*item) <= pWD->iFirstRow) {
			p->selectRect.left = 0;
			p->selectRect.right = 0;
			p->selectRect.top = 0;
			p->selectRect.bottom = 0;

			p->buttonRect.left = 0;
			p->buttonRect.right = 0;
			p->buttonRect.top = 0;
			p->buttonRect.bottom = 0;

			if (p->cChildren) {
				if (p->state & TLIS_EXPANDED) {
					PaintItems (hdc, pWD, item, y, 
						indent+INCREMENTINDENT, p->childItem);
				}
			}
		}
		//  step to next tree item
		p = p->nextItem;
	}

	//	set next item to unusual value to flag end of list
	if (p) {
		p->selectRect.left = 0;
		p->selectRect.right = -1;
		p->selectRect.top = 0;
		p->selectRect.bottom = -1;

		p->buttonRect.left = 0;
		p->buttonRect.right = -1;
		p->buttonRect.top = 0;
		p->buttonRect.bottom = -1;
	}
}


//----------------------------------------------------|
//  Paint one level of list (selected items only)

void PaintItemsDragBitmap (
		HDC hdc, TLWndData* pWD, ULONG ulFlags, int *item, int* y, 
		int iLevel, TLTreeItem* p, BOOL* pbStarted) 
{
	SIZE			s;
	INT				iy;
	CHAR			sz256[256];
	RECT			rcBound;

	SetTextColor (hdc, GetSysColor (COLOR_WINDOWTEXT));
	SetBkColor (hdc, GetSysColor (COLOR_WINDOW));

	while (p) {

		//  increment item count
		(*item)++;
		//  check if items are visible in window
		if ((*item) > (pWD->iFirstRow + pWD->iMaxRows + 2)) break;
		if ((*item) > pWD->iFirstRow) {

			//  first paint the tree items  ...
			//  select colors based on state of tree item
			if (pWD->bTreeFocused && 
				(p->state & TLIS_SELECTED) &&
				((iLevel == 0) || !(ulFlags & TLRB_TOPLEVELONLY))) 
			{
				*pbStarted = TRUE;

				//  bounding rectangle for this item
				rcBound.left = iLevel * INCREMENTINDENT;
				rcBound.top = *y+1;
				rcBound.bottom = p->selectRect.top + pWD->iRowHeight;
				if (p->state & TLIS_BOLD) SelectObject (hdc, pWD->hFontBold);
				else if (p->state & TLIS_ITALICS) 
					SelectObject (hdc, pWD->hFontItalic);
				else SelectObject (hdc, pWD->hFont);
				TruncateText (hdc, p->pszText, 
								pWD->iFirstColumnWidth-
										(BUTTONWIDTH+BITMAPWIDTH+HTEXTSHIFT), 
								sz256);
				GetTextExtentPoint32 (hdc, sz256, lstrlen (sz256), &s);
				rcBound.right = rcBound.left + s.cx + HTEXTSHIFT;

				//  draw tree item text 
				iy = rcBound.top + TEXTVERTOFF;
				SetTextAlign (hdc, TA_LEFT);
				TextOut (hdc, rcBound.left+HTEXTSHIFT+BUTTONWIDTH, iy, 
							sz256, lstrlen(sz256));

				//  draw tree item bitmap, if there is space
				if (pWD->iFirstColumnWidth >= (BUTTONWIDTH+BITMAPWIDTH)) {
					ImageList_Draw (pWD->hImageList, p->iImage, hdc,
							rcBound.left, rcBound.top+pWD->iBMPos,
							ILD_TRANSPARENT);
				}

				//  paint list items based on their data type
				SelectObject (hdc, pWD->hFont);

			}

			//  increment y coordinate to next row	
			if (*pbStarted) 
				*y += pWD->iRowHeight;

			// if there are expanded children, we need to add rows
			if (p->cChildren) {
				if (p->state & TLIS_EXPANDED) {
					PaintItemsDragBitmap (hdc, pWD, ulFlags, item, y, 
						iLevel+1, p->childItem, pbStarted);
				}
			}
		}
		else {		// ((*item) <= pWD->iFirstRow) {
			if (p->cChildren) {
				if (p->state & TLIS_EXPANDED) {
					PaintItemsDragBitmap (hdc, pWD, ulFlags, item, y, 
						iLevel+1, p->childItem, pbStarted);
				}
			}
		}
		//  step to next tree item
		p = p->nextItem;
	}
}


//----------------------------------------------------|
//  Paint one level of list (selected items only)

void CalcItemsDragBitmap (
		TLWndData* pWD, ULONG ulFlags, int *item, int* y, 
		int iLevel, TLTreeItem* p, BOOL* pbStarted, RECT* prc) 
{
	while (p) {

		//  increment item count
		(*item)++;
		//  check if items are visible in window
		if ((*item) > (pWD->iFirstRow + pWD->iMaxRows + 2)) break;
		if ((*item) > pWD->iFirstRow) {

			//  first paint the tree items  ...
			//  select colors based on state of tree item
			if (pWD->bTreeFocused && 
				(p->state & TLIS_SELECTED) &&
				((iLevel == 0) || !(ulFlags & TLRB_TOPLEVELONLY))) 
			{
				if (*pbStarted) {
					prc->bottom = *y + pWD->iRowHeight;
				}
				else {
					prc->top = *y;
					prc->bottom = *y + pWD->iRowHeight;
					*pbStarted = TRUE;
				}
			}

			//  increment y coordinate to next row	
			*y += pWD->iRowHeight;

			// if there are expanded children, we need to add empty rows
			if (p->cChildren) {
				if (p->state & TLIS_EXPANDED) {
					CalcItemsDragBitmap (pWD, ulFlags, item, y, 
						iLevel+1, p->childItem, pbStarted, prc);
				}
			}
		}
		else {		// ((*item) <= pWD->iFirstRow) {
			if (p->cChildren) {
				if (p->state & TLIS_EXPANDED) {
					CalcItemsDragBitmap (pWD, ulFlags, item, y, 
						iLevel+1, p->childItem, pbStarted, prc);
				}
			}
		}
		//  step to next tree item
		p = p->nextItem;
	}
}


//----------------------------------------------------|
//  Calculations before painting -- called in response to WM_PAINT

void TLPrePaint (TLWndData* pWD) {

	SCROLLINFO si;
	INT iY;

	pWD->iBCent = (pWD->iRowHeight / 2) +2;
	pWD->iBMPos = pWD->iBCent - (BITMAPHEIGHT/2) -1; 

	pWD->tlInval = pWD->tlRect;
	pWD->tlInval.top += pWD->iRowHeight+1;

	pWD->iExpandedRows = CountRows (pWD->rootItem);
	pWD->iMaxRows = (pWD->tlInval.bottom-pWD->tlInval.top-
					(pWD->iRowHeight/2)) / pWD->iRowHeight;
	if (pWD->iMaxRows <= pWD->iExpandedRows) pWD->tlInval.right = 
		pWD->tlRect.right - GetSystemMetrics (SM_CXVSCROLL);
	else {
		pWD->iFirstRow = 0;
		pWD->tlInval.right = pWD->tlRect.right;
	}

	iY = pWD->tlInval.right - pWD->tlInval.left;
	if (pWD->iTotalWidth > iY) pWD->tlInval.bottom = 
		pWD->tlRect.bottom - GetSystemMetrics (SM_CYHSCROLL);
	else pWD->tlInval.bottom = pWD->tlRect.bottom;

	pWD->iMaxRows = (pWD->tlInval.bottom-pWD->tlInval.top-
					(pWD->iRowHeight/2)) / pWD->iRowHeight;
	si.cbSize = sizeof (SCROLLINFO);
	si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
	si.nMin = 0;
	si.nMax = pWD->iExpandedRows;
	si.nPage = pWD->iMaxRows;
	si.nPos = pWD->iFirstRow;
	SetScrollInfo (pWD->hWnd, SB_VERT, &si, TRUE);

	si.nMax = pWD->iTotalWidth;
	si.nPage = pWD->tlInval.right - pWD->tlInval.left;
	si.nPos = pWD->iHorizontalPos;
	SetScrollInfo (pWD->hWnd, SB_HORZ, &si, TRUE);
}


//----------------------------------------------------|
//  Paint a tree list -- called in response to WM_PAINT

void TLPaint (TLWndData* pWD, HDC hdc) {

	TLTreeItem*	p;
	HFONT		hOldFont;
	HBRUSH		hOldBrush;
	int			y, item;

	hOldFont = SelectObject (hdc, pWD->hFont);

	UnrealizeObject (pWD->spcbarbrush);
	SetBrushOrgEx (hdc, -1 * pWD->iHorizontalPos, 0, NULL);
	hOldBrush = SelectObject (hdc, pWD->spcbarbrush);

	p = pWD->rootItem;
	y = pWD->tlInval.top;
	item = 0;

	PaintItems (hdc, pWD, &item, &y, 0, p);

	SelectObject (hdc, hOldBrush);
	SelectObject (hdc, hOldFont);
}


//----------------------------------------------------|
//  delete the memory DC

void TLDeleteMemDC (TLWndData* pWD) {
	if (pWD->hdcMem) {
		SelectObject (pWD->hdcMem, pWD->hbmOld);
		DeleteObject (pWD->hbmMem);
		DeleteDC (pWD->hdcMem);
		pWD->hdcMem = NULL;
	}
}


//----------------------------------------------------|
//  create mem dc and pass it to routine to render treelist

void TLMemPaint (TLWndData* pWD, HDC hdc, PAINTSTRUCT* pps) {
	RECT rc;
	BOOL bUseOld = FALSE;

	GetClientRect (pWD->hWnd, &rc);

	if (!pWD->hdcMem) {
		pWD->hdcMem = CreateCompatibleDC (hdc);
		pWD->hbmMem = CreateCompatibleBitmap (hdc, rc.right-rc.left, 
												rc.bottom-rc.top);
		pWD->hbmOld = SelectObject (pWD->hdcMem, pWD->hbmMem);
		SetBkMode (pWD->hdcMem, TRANSPARENT);
	}

	if (pps) {
		if ((pps->rcPaint.top != 0) &&
			(pps->rcPaint.left != 0) &&
			(pps->rcPaint.right != pWD->tlRect.right) &&
			(pps->rcPaint.bottom != pWD->tlRect.bottom))
			bUseOld = TRUE;
	}

	if (!bUseOld) {
		FillRect (pWD->hdcMem, &rc, pWD->unselbgbrush);
		TLPaint (pWD, pWD->hdcMem);
	}
    
	BitBlt (hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
			pWD->hdcMem, 0, 0, SRCCOPY);
}
  

//----------------------------------------------------|
//  Paint a tree list -- called in response to WM_PAINT

void TLPaintDragBitmap (TLWndData* pWD, ULONG ulFlags, HDC hdc) {

	TLTreeItem* p;
	HFONT hOldFont;
	int y, item;
	BOOL bStarted;

	hOldFont = SelectObject (hdc, pWD->hFont);

	p = pWD->rootItem;
	y = 0;
	item = 0;
	bStarted = FALSE;
	PaintItemsDragBitmap (hdc, pWD, ulFlags, &item, &y, 0, p, &bStarted);

	SelectObject (hdc, hOldFont);
}


//----------------------------------------------------|
//  Paint a tree list -- called in response to WM_PAINT

void TLCalcDragBitmap (TLWndData* pWD, ULONG ulFlags, RECT* prc) {

	TLTreeItem* p;
	int y, item;
	BOOL bStarted;

	prc->left = BUTTONWIDTH;
	prc->right = prc->left + pWD->iFirstColumnWidth;

	prc->top = 0;
	prc->bottom = 0;
	p = pWD->rootItem;
	y = 0;
	item = 0;
	bStarted = FALSE;
	CalcItemsDragBitmap (pWD, ulFlags, &item, &y, 0, p, &bStarted, prc);
}


//----------------------------------------------------|
//  create bitmap and paint selected items to it

BOOL TLMemPaintDragBitmap (TLWndData* pWD, LPTL_DRAGBITMAP lpdb) {
	HBITMAP	hbmOld;
	HDC		hdcMem;
	HDC		hdcScreen;
	RECT	rc;

	if (!lpdb) return FALSE;

	// calculate bitmap size and position
	TLCalcDragBitmap (pWD, lpdb->ulFlags, &rc);
	lpdb->sizeDrag.cx = rc.right - rc.left;
	lpdb->sizeDrag.cy = rc.bottom - rc.top;

	lpdb->ptHotSpot.x = lpdb->ptCursorPos.x - rc.left;
	lpdb->ptHotSpot.y = lpdb->ptCursorPos.y - rc.top - pWD->tlInval.top;

	// contstruct bitmap
	hdcMem = CreateCompatibleDC (NULL);
	hdcScreen = GetDC (pWD->hWnd);
	lpdb->hbmDrag = CreateCompatibleBitmap (hdcScreen, lpdb->sizeDrag.cx, 
											lpdb->sizeDrag.cy);
	ReleaseDC (pWD->hWnd, hdcScreen);

	hbmOld = SelectObject (hdcMem, lpdb->hbmDrag);
	SetBkMode (hdcMem, TRANSPARENT);
	rc.left = 0;
	rc.top = 0;
	rc.right = lpdb->sizeDrag.cx;
	rc.bottom = lpdb->sizeDrag.cy;
	FillRect (hdcMem, &rc, pWD->unselbgbrush);

	TLPaintDragBitmap (pWD, lpdb->ulFlags, hdcMem);

	SelectObject (hdcMem, hbmOld);

	DeleteDC (hdcMem);

	return TRUE;
}
  

⌨️ 快捷键说明

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