Create a Window without a Form !!!
This module demonstrates how to generate a Window using the API. Why use the Visual Basic FormDesigner when you can use the API? Okay it's much easier to use the Designer, but a good VB-Developer has to see and understand a module like this ;-). I have translated the C++ - Code (MSDN\SDK) to VB.
AI
Riepilogo AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Codice sorgente
Sub Main() Dim WC As WNDCLASS Dim dwRetVal As Long Dim msgWnd As MSG WC.lpszClassName = HT_CLASSNAME WC.lpfnwndproc = GetAddressOf(AddressOf MainWndProc) WC.style = CS_OWNDC Or CS_VREDRAW Or CS_HREDRAW WC.hInstance = App.hInstance WC.hIcon = apiLoadIcon(0, IDI_APPLICATION) WC.hCursor = apiLoadCursor(0, IDC_ARROW) WC.hbrBackground = COLOR_WINDOW WC.cbClsextra = 0 WC.cbWndExtra2 = 0 dwRetVal = apiRegisterClass(WC) Debug.Print "RegisterClass returns '" & CStr(dwRetVal) & "'." hWnd = apiCreateWindowEx(0, HT_CLASSNAME, HT_WINDOWTITLE, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, 0, 0, App.hInstance, 0) Debug.Print "CreateWindowEx returns hWnd '" & CStr(hWnd) & "'." dwRetVal = apiSetWindowPos(hWnd, 0, 200, 200, 300, 300, &H40) Debug.Print "SetWindowPos returns '" & CStr(dwRetVal) & "'." Do While apiGetMessage(msgWnd, hWnd, 0&, 0&) > 0 apiDispatchMessage msgWnd ': DoEvents Loop dwRetVal = apiUnregisterClass(HT_CLASSNAME, App.hInstance) Debug.Print "UnregisterClass returns '" & CStr(dwRetVal) & "'." End Sub Private Function MainWndProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long MainWndProc = apiDefWindowProc(hWnd, wMsg, wParam, lParam) End Function Private Function GetAddressOf(ProcAddress As Long) As Long GetAddressOf = ProcAddress End Function Upload
Commenti originali (3)
Recuperato da Wayback Machine