sp;Call ShowWindow(gEditHwnd&, SW_SHOWNORMAL)
记下按钮处理过错的当前所在地址
gButOldProc& = GetWindowLong(gButtonHwnd&, GWL_WNDPROC)
''''Set default window procedure of button to ButtonWndProc. Different
''''settings of windows is listed in the MSDN Library. We are using GWL_WNDPROC
''''to set the address of the window procedure.
指向新的处理过程地址
Call SetWindowLong(gButtonHwnd&, GWL_WNDPROC, GetAddress(AddressOf ButtonWndProc))
CreateWindows = (gHwnd& <> 0)
End Function
''窗体运行的主函数,在注册这个窗体时已经指定的
Public Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim strTemp As String
处理消息,这里指处理了WM_DESTROY消息
Select Case uMsg&
Case WM_DESTROY:
''''Since DefWindowProc doesn''t automatically call
''''PostQuitMessage (WM_QUIT). We need to do it ourselves.
''''You can use DestroyWindow to get rid of the window manually.
Call PostQuitMessage(0&)
End Select
''''Let windows call the default window procedure since we''re done.
WndProc = DefWindowProc(hwnd&, uMsg&, wParam&, lParam&)
End Function
又添加了一个Button的处理过程
Public Function ButtonWndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case uMsg&
Case WM_LBUTTONUP:
Call MessageBox(gHwnd&, "You clicked the button!", App.Title, MB_OK Or MB_ICONEXCLAMATION)
End Select
ButtonWndProc = CallWindowProc(gButOldProc&, hwnd&, uMsg&, wParam&, lParam&)
End Function
Public Function GetAddress(ByVal lngAddr As Long) As Long
GetAddress = lngAddr&
End Function
以上一个完整的简单的应用程序就产生了。我们不需要IDE环境也可以创建我们想要的风格的窗体。通过这个例子对于VB
程序员是不是对系统的机制有了一些了解。
虽然这个例子实际意义并不大,但是我们认为很有用,让我们能了解一些封装背后隐藏的事实,使我们的思路很自由。
最后要声明这个想法并不是我一人想出来的,我参考一段代码(具体出处不祥)说想到,想与VB
程序员共同分享一下,其实只要用活VB并没有我们所说的那么多限制,关键在使用者能否跳出这个范畴。