首页 > 开发 > 综合 > 正文

VB指针,VB API编程

2024-07-21 02:20:42
字体:
来源:转载
供稿:网友
rem 简单的vb api编程,只显示出一个白色的窗口,然后写出hello
rem 天津财经大学 企管系 工商管理 0202
rem (c)邓德荣 2005-3-4
rem 注:如需修改程序,请联系作者
rem e-mail :[email protected]


public declare function loadcursor lib "user32" alias "loadcursora" (byval hinstance as long, byval lpcursorname as long) as long
public declare function loadicon lib "user32" alias "loadicona" (byval hinstance as long, byval lpiconname as long) as long
public declare function registerclass lib "user32" alias "registerclassa" (class as long) as long
public declare function createwindowex lib "user32" alias "createwindowexa" (byval dwexstyle as long, byval lpclassname as long, byval lpwindowname as long, byval dwstyle as long, byval x as long, byval y as long, byval nwidth as long, byval nheight as long, byval hwndparent as long, byval hmenu as long, byval hinstance as long, lpparam as any) as long
public declare function showwindow lib "user32" (byval hwnd as long, byval ncmdshow as long) as long
public declare function updatewindow lib "user32" (byval hwnd as long) as long
public declare function getmessage lib "user32" alias "getmessagea" (lpmsg as long, byval hwnd as long, byval wmsgfiltermin as long, byval wmsgfiltermax as long) as long
public declare function translatemessage lib "user32" (lpmsg as long) as long
public declare function dispatchmessage lib "user32" alias "dispatchmessagea" (lpmsg as long) as long
public declare function defwindowproc lib "user32" alias "defwindowproca" (byval hwnd as long, byval wmsg as long, byval wparam as long, byval lparam as long) as long
public declare function getstockobject lib "gdi32" (byval nindex as long) as long
public declare sub postquitmessage lib "user32" (byval nexitcode as long)
public declare function beginpaint lib "user32" (byval hwnd as long, lppaint as long) as long
public declare function endpaint lib "user32" (byval hwnd as long, lppaint as long) as long
public declare function textout lib "gdi32" alias "textouta" (byval hdc as long, byval x as long, byval y as long, byval lpstring as string, byval ncount as long) as long

public const wm_size = &h5
public const wm_paint = &hf
public const wm_destroy = &h2
public const idc_arrow = 32512&
public const idi_application = 32512&
public const cw_usedefault = &h80000000
public const ws_ex_appwindow = &h40000
public const ws_overlapped = &h0&
public const white_brush = 0
public const cs_hredraw = &h2
public const cs_vredraw = &h1
public const ws_caption = &hc00000 ' ws_border or ws_dlgframe
public const ws_sysmenu = &h80000
public const ws_thickframe = &h40000
public const ws_maximizebox = &h10000
public const ws_minimizebox = &h20000
public const ws_overlappedwindow = (ws_overlapped or ws_caption or ws_sysmenu or ws_thickframe or ws_minimizebox or ws_maximizebox)

public type rect
left as long
top as long
right as long
bottom as long
end type

public type paintstruct
hdc as long
ferase as long
rcpaint as rect
frestore as long
fincupdate as long
rgbreserved(32) as byte
end type

public type wndclass
style as long
lpfnwndproc as long
cbclsextra as long
cbwndextra2 as long
hinstance as long
hicon as long
hcursor as long
hbrbackground as long
lpszmenuname as long
lpszclassname as long
end type

public type pointapi
x as long
y as long
end type

public const color_window = 5

public type msg
hwnd as long
message as long
wparam as long
lparam as long
time as long
pt as pointapi
end type

public function wndproc(byval hwnd as long, byval message as long, byval wparam as long, byval lparam as long) as long
dim ps as paintstruct
dim hdc as long
dim szbuffer as string
static cxclient as long
static cyclient as long

szbuffer = "hello, vb api"

select case message
case wm_size
cxclient = lparam mod 65536
cyclient = lparam / 65536
wndproc = 0
exit function

case wm_paint
hdc = beginpaint(hwnd, byval varptr(ps))
textout hdc, cxclient / 2, cyclient / 2, szbuffer, len(szbuffer)
endpaint hwnd, byval varptr(ps)
wndproc = 0
exit function

case wm_destroy
postquitmessage 0
wndproc = 0
exit function

end select
wndproc = defwindowproc(hwnd, message, wparam, lparam)

end function

private sub setwndproc(byref wc as wndclass, byval wndproc as long)

wc.lpfnwndproc = wndproc
end sub

sub main()
dim szappname(10) as byte
dim pmsg as msg
dim hwnd as long
dim wc as wndclass

szappname(0) = 97
szappname(1) = 112
szappname(2) = 112
szappname(3) = 0

wc.cbclsextra = 0
wc.cbwndextra2 = 0
wc.hbrbackground = getstockobject(white_brush)
wc.hcursor = loadcursor(0, idc_arrow)
wc.hicon = loadicon(0, idi_application)
wc.hinstance = app.hinstance
setwndproc wc, addressof wndproc
wc.lpszclassname = varptr(szappname(0))
wc.lpszmenuname = 0
wc.style = cs_hredraw or cs_vredraw

if registerclass(byval varptr(wc)) = 0 then msgbox ("error")

hwnd = createwindowex(0, byval varptr(szappname(0)), byval varptr(szappname(0)), ws_overlappedwindow, cw_usedefault, cw_usedefault, cw_usedefault, cw_usedefault, 0, 0, app.hinstance, 0)
showwindow hwnd, 1
updatewindow hwnd

do while getmessage(byval varptr(pmsg), 0, 0, 0) <> 0
translatemessage byval varptr(pmsg)
dispatchmessage byval varptr(pmsg)
loop

end sub




发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表