呼唤worldy
worldy ,你在12楼说textout可以往内存dc上写文字的。
原帖子:
http://bbs.csdn.net/topics/390320867
//透明背景
HDC hMemDC=CreateCompatibleDC(item->hDC);
HBITMAP hOldBitmap=(HBITMAP)SelectObject(hMemDC,(HGDIOBJ)hBitmap);
TextOut(hMemDC,0,0,"hello",strlen("hello"));//不管用,你说这里管用的! 我不会是用法出错了吧
BITMAP bitmap;
GetObject(hBitmap,sizeof(BITMAP),&bitmap);
StretchBlt(item->hDC,0,0,item->rcItem.right,item->rcItem.bottom,hMemDC,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
SelectObject(hMemDC,hOldBitmap);
DeleteObject((HGDIOBJ)hBitmap);
DeleteObject((HGDIOBJ)hMemDC);
FrameRect(item->hDC,&(item->rcItem),(HBRUSH)GetStockObject(BLACK_BRUSH));
// Set the text color to gray if the button is selected.
if( item->itemState & ODS_SELECTED )
{
SetTextColor( item->hDC, RGB( 128, 128, 128 ) );
}
else
{
SetTextColor( item->hDC, RGB( 255, 0, 0 ) );
}
// This will make the text move down and to the right when the button is
// pressed.
rect = item->rcItem;
if( item->itemState & ODS_SELECTED )
{
rect.top += 20;
rect.left += 20;
}
char title[256];
GetWindowText( item->hwndItem, title, sizeof( title ) );
DrawText( item->hDC, title, -1, &rect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE );
[解决办法]
Private Sub Command1_Click()
Dim hDC As Long
Dim s As String
Dim hMemDC As Long
Dim hBmp As Long
Dim r As Long
s = "How Do u do?"
hDC = GetDC(Text1.hwnd)
hMemDC = CreateCompatibleDC(hDC)
hBmp = CreateCompatibleBitmap(hDC, 100, 100)
r = SelectObject(hMemDC, hBmp)
BitBlt hMemDC, 0, 0, 100, 100, hDC, 0, 0, vbSrcCopy
TextOut hMemDC, 10, 10, s, Len(s)
BitBlt hDC, 0, 0, 100, 100, hMemDC, 0, 0, vbSrcCopy
' TextOut hDC, 2, 2, s, Len(s)
ReleaseDC Text1.hwnd, hDC
DeleteObject hMemDC
DeleteObject hBmp
End Sub
这个是使用VB里语法写的,但语句和过程是C的,你对照改成C,
将函数加上括号
len==>size
vbsrccopy=0xCC0020
long==>int
string==>char*
[解决办法]
虽然你写的代码看起来有点乱,但是没看出有什么错误。
你就不能都在mem dc中绘制完成后再copy到src dc中么