mainform.bas

来自「E:StudyVBCodeStayTop.zip」· BAS 代码 · 共 64 行

BAS
64
字号
Attribute VB_Name = "mainForm"
Option Explicit

'========================================================================================
' Form 1.05
' 代码编号:000001
' 版权所有(C) 2001-2002  江建及其两位女友
'========================================================================================


Dim lpwcx As WNDCLASSEX
Dim RegClass As Long

Public Function RegWinClass(lpClassName As String)
    '注册窗口类
    With lpwcx
        .cbSize = Len(lpwcx)
        .Style = CS_HREDRAW Or CS_VREDRAW Or CS_DBLCLKS
        .lpszClassName = lpClassName
        .hInstance = App.hInstance
        .cbClsExtra = 0
        .cbWndExtra = 0
        .hCursor = LoadCursor(0, IDC_ARROW)
        .lpfnWndProc = FnPtrToLong(AddressOf MainWinProc)
        .lpszMenuName = 0
        .hbrBackground = COLOR_WINDOW
    End With
    Call RegisterClassEx(lpwcx)
End Function

Private Function MainWinProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
   Select Case uMsg
        Case WM_DESTROY
            Call PostQuitMessage(0)
    End Select
    MainWinProc = DefWindowProc(hwnd, uMsg, wParam, lParam)
End Function

Public Function FnPtrToLong(ByVal lngFnPtr As Long) As Long
    FnPtrToLong = lngFnPtr
End Function

    
Public Function CreateMainForm(title As String, nWidth As Long, nHeight As Long) As Long
    Dim hWndMain  As Long
    Dim lpMsg As MSG
    
    Call RegWinClass("Form")
    hWndMain = CreateWindowEx(0, "Form", "Windows", WS_OVERLAPPEDWINDOW, 0, 0, nWidth, nHeight, 0, 0, App.hInstance, ByVal 0&)
    
    If hWndMain <> 0 Then
        ShowWindow hWndMain, SW_NORMAL
        Do While GetMessage(lpMsg, 0, 0, 0)
            TranslateMessage lpMsg
            DispatchMessage lpMsg
        Loop
    End If
    UnregisterClass "Form", App.hInstance
End Function

Public Sub Main()
    CreateMainForm "Windows", 500, 388
End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?