声明如下结构:
global type us_bitmap from structure
long bmtype
long bmwidth
long bmheight
long bmwidthbytes
long bmplanes
long bmbitspixel
blob bmbits
end type
声明如下API:
FUNCTION Long FindWindowEx( Long hParent, Long hChildAfter, String lpszClass, String lpszWindow ) LIBRARY "user32" ALIAS FOR "FindWindowExA"
FUNCTION ulong GetDC(ulong hwnd) LIBRARY "user32.dll"
FUNCTION ulong DeleteDC(ulong hdc) LIBRARY "gdi32.dll"
FUNCTION ulong ReleaseDC(ulong hwnd,ulong hdc) LIBRARY "user32.dll"
FUNCTION ulong CreateCompatibleDC(ulong hdc) LIBRARY "gdi32.dll"
Function Long LoadImage (Long hInst,String lpsz, Long un1, Long n1, Long n2, Long un2) Library "user32" Alias For "LoadImageA"
FUNCTION ulong GetObjectBitmap( ulong hgdiobj, int cbBuffer, ref us_bitmap bm ) library "gdi32.dll" alias for GetObjectA
FUNCTION ulong SelectObject(ulong hdc,ulong hObject) LIBRARY "gdi32.dll"
FUNCTION ulong DeleteObject(ulong hObject) LIBRARY "gdi32.dll"
FUNCTION ulong BitBlt(ulong hDestDC,ulong x_left,ulong y_top,ulong nWidth,ulong nHeight,ulong hSrcDC,ulong xSrc,ulong ySrc,ulong dwRop) LIBRARY "gdi32.dll"
写如下代码:
long ll_handle,ll_null,ll_TargetDc,ll_bitmap,ll_memdc,ll_old
long ll_cx,ll_cy
us_bitmap lus_bmp
声明API
Function Long GetDC (Long hwnd ) Library "user32.dll" Alias For "GetDC"
Function Long CreateSolidBrush (Long crColor) Library "gdi32.dll"
FUNCTION Long CreatePatternBrush(Long hBitmap) LIBRARY "gdi32.dll"
FUNCTION Long LoadImage(Long hInst, string lpsz, Long uType, Long cxDesired, Long cyDesired, Long fuLoad) LIBRARY "user32.dll" ALIAS FOR "LoadImageA"
Function Long PatBlt (Long hdc, Long x, Long y, Long nWidth, Long nHeight, Long dwRop) Library "gdi32.dll"
Function Long FillRect(Long hdc,Ref stru_RECT lpRect, Long hBrush) Library "user32.dll"
Function long SelectObject (Long hdc, Long hObject)Library "gdi32.dll"
FUNCTION Long DeleteObject(Long hObject) LIBRARY "gdi32.dll"
结构:
global type stru_rect from structure
long Left
long Top
long Right
long Bottom
end type
//LoadImage常量
CONSTANT Long LR_LOADFROMFILE = 16
CONSTANT Long IMAGE_BITMAP = 0
CONSTANT Long IMAGE_ICON = 1
CONSTANT Long IMAGE_CURSOR = 2
//函数
public function long uf_set_back_pic (long hwnd, string filename, integer width, integer height);Long ll_ret
Long ll_hdc,ll_hBrush,ll_lhbitmap,ll_ohdc
//LoadImgae 常数
//Constant long IMAGE_BITMAP = 0
Constant long PATCOPY = 15728673//&HF00021 '
stru_rect str_r
ll_hdc = Getdc(hwnd)
//Create a new brush
ll_hBrush = CreateSolidBrush(16777215)
//Set the rectangle's values
str_r.Top = 0
str_r.Left = 0
str_r.Bottom = width
str_r.Right = height
FillRect (ll_hdc, str_r, ll_hBrush)
//delete our brush
DeleteObject(ll_hBrush)
ll_ohdc = SelectObject(ll_hdc, ll_hBrush)
//Perform the Pattern Block Transfer
ll_ret = PatBlt(ll_hdc, 0, 0, Width, Height, PATCOPY)
//restore the old brush and delete our pattern brush
DeleteObject(SelectObject(ll_hdc, ll_ohdc))
RETURN ll_ret
end function