| 发表于:2007-03-24 11:58:249楼 得分:0 |
好的: option explicit 'user defined types private type pointapi 'api point structure. x as long y as long end type private type sizerect 'size structure (uses width, height instead of bounds) left as long top as long width as long height as long end type private type rectapi 'rect structure (uses right, bottom bounds instead of width, height) left as long top as long right as long bottom as long end type 'windows api blt (bitblt, patblt, stretchblt) rop constants. private const srccopy as long = &hcc0020 private const patcopy as long = &hf00021 'setwindowpos flags. private const swp_nomove as long = 2 private const swp_nosize as long = 1 private const swp_noactivate as long = &h10 private const swp_flags as long = swp_nomove or swp_nosize or swp_noactivate private const hwnd_topmost as long = -1 private const hwnd_notopmost as long = -2 'module level variables. private mfscale as single 'scale of zoom percentage (6 = 600%) (6 x size = 600% increase) private mloldx as long 'holds last x-coord of mouse private mloldy as long 'holds last y-coord of mouse 'declare the windows api functions that are to be used. 'alphabetical order to ease lookup later. private declare function createcompatiblebitmap lib "gdi32 " (byval hdc as long, byval nwidth as long, byval nheight as long) as long private declare function createcompatibledc lib "gdi32 " (byval hdc as long) as long private declare function createpatternbrush lib "gdi32 " (byval hbitmap as long) as long private declare function deletedc lib "gdi32 " (byval hdc as long) as long private declare function deleteobject lib "gdi32 " (byval hobject as long) as long private declare function getcursorpos lib "user32 " (lppoint as pointapi) as long private declare function getdc lib "user32 " (byval hwnd as long) as long private declare function getdesktopwindow lib "user32 " () as long private declare function getsyscolor lib "user32 " (byval nindex as long) as long private declare function getwindowrect lib "user32 " (byval hwnd as long, lprect as rectapi) as long private declare function patblt lib "gdi32 " (byval hdc as long, byval x as long, byval y as long, byval nwidth as long, byval nheight as long, byval dwrop as long) as long private declare function releasedc lib "user32 " (byval hwnd as long, byval hdc as long) as long private declare function selectobject lib "gdi32 " (byval hdc as long, byval hobject as long) as long private declare function setpixelv lib "gdi32 " (byval hdc as long, byval x as long, byval y as long, byval crcolor as long) as long private declare function setwindowpos lib "user32 " (byval hwnd as long, byval hwndinsertafter as long, byval x as long, byval y as long, byval cx as long, byval cy as long, byval wflags as long) as long private declare function stretchblt lib "gdi32 " (byval hdc as long, byval x as long, byval y as long, byval nwidth as long, byval nheight as long, byval hsrcdc as long, byval xsrc as long, byval ysrc as long, byval nsrcwidth as long, byval nsrcheight as long, byval dwrop as long) as long private function createcheckeredbrush(byval hdc as long, byval lcolor1 as long, byval lcolor2 as long) as long dim x as long dim y as long dim lret as long dim hbitmapdc as long dim hbitmap as long dim holdbitmap as long 'convert system colors if needed if lcolor1 < 0 then lcolor1 = getsyscolor(lcolor1 and &hff&) end if if lcolor2 < 0 then lcolor2 = getsyscolor(lcolor2 and &hff&) end if 'create a new dc and bitmap to draw the brush hbitmapdc = createcompatibledc(hdc) hbitmap = createcompatiblebitmap(hdc, 8, 8) 'select the bitmap into the dc for drawing holdbitmap = selectobject(hbitmapdc, hbitmap) 'draw the brush 's bitmap (checkerboard) for y = 0 to 6 step 2 for x = 0 to 6 step 2 lret = setpixelv(hbitmapdc, x, y, lcolor1) lret = setpixelv(hbitmapdc, x + 1, y, lcolor2) lret = setpixelv(hbitmapdc, x, y + 1, lcolor2) lret = setpixelv(hbitmapdc, x + 1, y + 1, lcolor1) next x next y 'get the bitmap back out of the dc hbitmap = selectobject(hbitmapdc, holdbitmap) 'create the brush from the bitmap createcheckeredbrush = createpatternbrush(hbitmap) 'delete the dc and bitmap to free memory lret = deletedc(hbitmapdc) lret = deleteobject(hbitmap) end function | | |
|