绘制背景后,使用DrawText绘制文字出错
procedure TForm1.FormPaint(Sender: TObject);
var
DC,Memory_DC:HDC;
oldbitmap:HBITMAP;
bmp:BITMAP;
Title:string;
hmapBack:HBITMAP;
nWidth,nHeight:Integer;
clientRect:TRect;
begin
DC :=GetDC(Handle);
Memory_DC :=CreateCompatibleDC(DC);
hmapBack :=LoadImage(0,'1.bmp',IMAGE_BITMAP,0,0,LR_LOADFROMFILE or LR_DEFAULTSIZE or LR_CREATEDIBSECTION);
oldbitmap :=SelectObject(Memory_DC,hmapBack);
GetObject(hmapBack,SizeOf(bmp),@bmp);
//BitBlt(DC,0,0,bmp.bmWidth,bmp.bmHeight,Memory_DC,0,0,SRCCOPY);
clientRect :=GetClientRect;
nWidth :=clientRect.Right - clientRect.Left;
nHeight :=clientRect.Bottom - clientRect.Top;
StretchBlt(DC,0,0,nWidth,nHeight,Memory_DC,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
SelectObject(Memory_DC,oldbitmap);
DeleteDC(Memory_DC);
///
/// 绘制文本
///
///
Title :='测试图片上绘制文本';
DrawText(DC,PWideChar(Title),length(Title),@clientRect,DT_CENTER or DT_TOP or DT_SINGLELINE);
//TextOut(DC,100,0,PWideChar(Title),Length(Title));
ReleaseDC(Handle,DC);
end;