分享
 
 
 

VB指针,VB API编程

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

Rem 简单的VB API编程,只显示出一个白色的窗口,然后写出HELLO

Rem 天津财经大学 企管系 工商管理 0202

Rem (c)邓德荣 2005-3-4

Rem 注:如需修改程序,请联系作者

Rem E-Mail :louisdeng@monternet.com

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有