怎样将一个已知HBITMAP的图象画到DC上?(100分)

  • 主题发起人 主题发起人 wenx
  • 开始时间 开始时间
W

wenx

Unregistered / Unconfirmed
GUEST, unregistred user!
我用LOADBITMAP一个图象资源,得到了HBITMAP,却不知道怎样画到窗体的DC上,请教,请完全用API来说明,谢谢。
 
BitBlt(DC, 0, 0, 100, 100, HBITMAP, 0, 0, Bitmap.Width, Bitmap.Height);
 
这样写不行,我试过了,HBITMAP不能当HDC用。
 
HRESULT Draw(<br><br>&nbsp; &nbsp; DWORD dwAspect, //Specifies how the object is to be represented<br>&nbsp; &nbsp; LONG lindex, //Specifies the part of the object to draw<br>&nbsp; &nbsp; void * pvAspect, //Always NULL<br>&nbsp; &nbsp; DVTARGETDEVICE * ptd, //Specifies the target device in a structure<br>&nbsp; &nbsp; HDC hicTargetDev, //Specifies the information context for the target device ptd<br>&nbsp; &nbsp; HDC hdcDraw, //Identifies the device context on which to draw<br>&nbsp; &nbsp; const LPRECTL lprcBounds, //Specifies the rectangle in which the object is drawn<br>&nbsp; &nbsp; const LPRECTL lprcWBounds, //Specifies the window extent and window origin when drawing a metafile<br>&nbsp; &nbsp; BOOL (*) (DWORD) pfnContinue, //Callback function for canceling or continuing the drawing<br>&nbsp; &nbsp; DWORD dwContinue //Parameter to pass to the callback function pfnContinue <br>&nbsp; &nbsp;);
 
大哥,给给DELPHI的例子好吗?<br>这个函数里我怎么没看见在哪赋HBITMAP这个参数?
 
TBitmap类的Handle就是<br>HDC我一直就这么用
 
你可以这样:<br>1、创建一个Tbitmap;<br>2、设置Bitmap.handle:=HBITMAP<br>3、不用我说了吧?有多种方法绘制bitmap,比如用BitBlt(bitmap.canvas.handle)
 
你们还是没懂我的意思,我是完全用API编制的程序,根本就没用到DELPHI的类,更不用说TBITMAP了,前面我已经指明是HBITMAP了。
 
能否将代码帖出来看看?<br>
 
var Bmp: hBitmap;<br>begin<br>&nbsp; Bmp:=LoadBitmap(hInstance, 'WENX');<br>&nbsp; 然后从这里开始画...,用什么函数?<br>end;
 
在VC++中有个函数:<br>BOOL WINAPI DrawState(<br>&nbsp; HDC hdc, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // handle to device context<br>&nbsp; HBRUSH hbr, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// handle to brush<br>&nbsp; DRAWSTATEPROC lpOutputFunc, &nbsp;// pointer to callback function<br>&nbsp; LPARAM lData, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// image information<br>&nbsp; WPARAM wData, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// more image information<br>&nbsp; int x, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // horizontal location of image<br>&nbsp; int y, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // vertical location of image<br>&nbsp; int cx, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// width of image<br>&nbsp; int cy, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// height of image<br>&nbsp; UINT fuFlags &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // image type and state<br>);<br><br>可以完成这个功能,但是我在DELPHI中使用时总是报错。<br>我在VC中的一条语句:<br>DrawState(hdc,null,null,(LPARAM)bitmap1,0,32,32,0,0,DST_BITMAP);
 
procedure TForm1.FormPaint(Sender: TObject);<br>var<br>&nbsp; DC : HDC;<br>&nbsp; HBMP : HBITMAP;<br>&nbsp; BITDC : HDC;<br>&nbsp; Pal: tagLOGPALETTE;<br>&nbsp; Palette : HPALETTE;<br>begin<br>&nbsp; DC := Form1.Canvas.Handle ;<br>&nbsp; HBMP := LoadBitmap(0,PChar(OBM_CHECKBOXES));<br>&nbsp; BITDC := CreateCompatibleDC(0);<br>&nbsp; SelectObject(BITDC,HBMP);<br>&nbsp; BitBlt(DC, 10, 10, 100, 100, BITDC, 0, 0, SRCCOPY);<br>&nbsp; DeleteObject(HBMP);<br>&nbsp; DeleteDC(BITDC);<br>end;
 
同意楼上,同样用DRAW,StretchBLT也可.[:D]
 
谢谢realLearning,也谢谢大家,请多指教了。
 
后退
顶部