Results 1 to 9 of 9

Thread: Make a FORM

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    honolulu, HI USA
    Posts
    37

    Talking

    I am still wondering how to make a form in API...... I looked at VB API and looked at "CreateWindowEx" but still, all I can find are controls such as BUTTON and EDIT, i couldn't find FORM..... is there anyone out there interested to show me how.... or give me an example perhaps? a little help would be much appreciated... BTW, is there any tutorials that I can use for references..... I know basics of API but I need to expand my knowledge.....
    Dim VB as MyLife
    if VB = True then
    Load MyLife
    Else
    Unload MyLife
    End
    End If

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Here you go. This example will create 2 labels Command Button and a TextBox:
    Code:
    Option Explicit
    
    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 String
        lpszClassName As String
    End Type
    Type POINTAPI
        x As Long
        y As Long
    End Type
    Type Msg
        hWnd As Long
        message As Long
        wParam As Long
        lParam As Long
        time As Long
        pt As POINTAPI
    End Type
    
    Declare Function RegisterClass Lib "user32" Alias "RegisterClassA" (Class As WNDCLASS) As Long
    Declare Function UnregisterClass Lib "user32" Alias "UnregisterClassA" (ByVal lpClassName As String, ByVal hInstance As Long) As Long
    Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, 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
    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
    Declare Sub PostQuitMessage Lib "user32" (ByVal nExitCode As Long)
    Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
    Declare Function TranslateMessage Lib "user32" (lpMsg As Msg) As Long
    Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Msg) As Long
    Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
    Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Any) As Long
    
    
    Public Const COLOR_WINDOW = 5
    Public Const BM_CLICK = 245
    Public Const CS_VREDRAW = &H1
    Public Const CS_HREDRAW = &H2
    Public Const CS_KEYCVTWINDOW = &H4
    Public Const WS_OVERLAPPED = &H0&
    Public Const WS_POPUP = &H80000000
    Public Const WS_CHILD = &H40000000
    Public Const WS_MINIMIZE = &H20000000
    Public Const WS_VISIBLE = &H10000000
    Public Const WS_DISABLED = &H8000000
    Public Const WS_CLIPSIBLINGS = &H4000000
    Public Const WS_CLIPCHILDREN = &H2000000
    Public Const WS_MAXIMIZE = &H1000000
    Public Const WS_CAPTION = &HC00000 ' WS_BORDER Or WS_DLGFRAME
    Public Const WS_BORDER = &H800000
    Public Const WS_DLGFRAME = &H400000
    Public Const WS_VSCROLL = &H200000
    Public Const WS_HSCROLL = &H100000
    Public Const WS_SYSMENU = &H80000
    Public Const WS_THICKFRAME = &H40000
    Public Const WS_GROUP = &H20000
    Public Const WS_TABSTOP = &H10000
    Public Const WS_MINIMIZEBOX = &H20000
    Public Const WS_MAXIMIZEBOX = &H10000
    Public Const WS_TILED = WS_OVERLAPPED
    Public Const WS_ICONIC = WS_MINIMIZE
    Public Const WS_SIZEBOX = WS_THICKFRAME
    Public Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
    Public Const WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW
    Public Const WS_POPUPWINDOW = (WS_POPUP Or WS_BORDER Or WS_SYSMENU)
    Public Const WS_CHILDWINDOW = (WS_CHILD)
    Public Const WS_EX_CLIENTEDGE = 512
    Public Const WM_DESTROY = &H2
    Public Const WM_MOVE = &H3
    Public Const WM_SIZE = &H5
    Public Const SW_HIDE = 0
    Public Const SW_SHOWNORMAL = 1
    Public Const SW_NORMAL = 1
    Public Const SW_SHOW = 5
    Public Const SW_MINIMIZE = 6
    Public Const IDC_ARROW = 32512&
    Public Const GWL_WNDPROC = -4
    
    Public lngHwndButton As Long
    Public lngHwndLabel2 As Long
    Public lngHwndLabel1 As Long
    Public lngHwndTextbox As Long
    Public hWndForm As Long
    
    Public Sub Main()
        Dim lngStyle As Long
    
        'Register Class
        Call RegisterClassProc
        'Create a FORM
        lngStyle = WS_OVERLAPPED Or WS_SYSMENU Or WS_CLIPCHILDREN Or WS_CLIPSIBLINGS
        hWndForm = CreateWindowEx(0, "MyCoolClass", "Dynamic Form using CreateEx API from Serge", lngStyle, 0, 0, 400, 300, 0, 0, App.hInstance, ByVal 0&)
        'Create controls on the form
        lngHwndLabel1 = CreateWindowEx(0, "Static", "New Label1", WS_CHILD, 50, 25, 100, 25, hWndForm, 0, App.hInstance, ByVal 0&)
        lngHwndLabel2 = CreateWindowEx(0, "Static", "New Label2", WS_CHILD, 50, 55, 100, 25, hWndForm, 0, App.hInstance, ByVal 0&)
        lngHwndButton = CreateWindowEx(0, "Button", "New Button", WS_CHILD, 50, 90, 100, 25, hWndForm, 0, App.hInstance, ByVal 0&)
        lngHwndTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", "Sample Text", WS_CHILD, 50, 125, 100, 25, hWndForm, 0, App.hInstance, ByVal 0&)
        If hWndForm <> 0 Then ShowWindow hWndForm, SW_SHOWNORMAL
        'Show controls on the new form
        ShowWindow lngHwndTextbox, SW_SHOWNORMAL
        ShowWindow lngHwndButton, SW_SHOWNORMAL
        ShowWindow lngHwndLabel1, SW_SHOWNORMAL
        ShowWindow lngHwndLabel2, SW_SHOWNORMAL
        MessageProc
        
    End Sub
    Private Sub MessageProc()
        Dim ms As Msg
        
        Do While GetMessage(ms, 0, 0, 0)
            TranslateMessage ms
            DispatchMessage ms
        Loop
    End Sub
    
    Function ProcessWndProc(ByVal lWndProc As Long) As Long
        ProcessWndProc = lWndProc
    End Function
    
    Public Sub RegisterClassProc()
        Dim ws As WNDCLASS
        
        'Prepare Class to be registered
        ws.style = CS_HREDRAW + CS_VREDRAW
        ws.lpfnwndproc = ProcessWndProc(AddressOf WindowProc)
        ws.cbClsextra = 0
        ws.cbWndExtra2 = 0
        ws.hInstance = App.hInstance
        ws.hIcon = 0
        ws.hCursor = LoadCursor(0, IDC_ARROW)
        ws.hbrBackground = COLOR_WINDOW
        ws.lpszMenuName = 0
        ws.lpszClassName = "MyCoolClass"
        'Register Class
        RegisterClass ws
    End Sub
    
    Private Function WindowProc(ByVal hWnd As Long, ByVal message As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        Select Case message
            Case WM_DESTROY
                PostQuitMessage (0)
                UnregisterClass "MyCoolClass", App.hInstance
        End Select
        WindowProc = DefWindowProc(hWnd, message, wParam, lParam)
    End Function

  3. #3
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    For reference and tutorials you can try www.vbapi.com and www.allapi.net

  4. #4
    Lively Member FirstKnight's Avatar
    Join Date
    Jul 1999
    Location
    Johannesburg, South Africa
    Posts
    95

    Question Why?

    I thought the whole purpose of VISUAL Basic was to make it as easy as possible creating the visual aspect of a program eg forms. Why would anyone want to use the API to create one. Or maybe I'm just lazy.
    Today is yesterday's tomorrow

  5. #5
    Guest
    People have their reasons. Maybe they want to save resources, or possibly just for informational purposes.

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Maybe he/she wants to make an MDI and have a new instance of each form. In that case, masterpfu, you should use the load command to create a new form.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    honolulu, HI USA
    Posts
    37

    Talking

    Actually.... I wanted this frm just for reference.... to learn API..... heh from the tutorials and stuff you guyz gave me.... Hmmm..... actually, i know id rather have a form created by vb.... that's how vb work...... but this may be useful in some time..... thanx again al you people...
    Ohh yeah, by any chance, if you create a program with pure API in vb, will you still need a runtime to run it?
    Dim VB as MyLife
    if VB = True then
    Load MyLife
    Else
    Unload MyLife
    End
    End If

  8. #8
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    You will need runtimes regardless...

  9. #9
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    That code woks great but the tabstops dont work. Wow to you tab between controls using your api code?
    Always looking for a better and faster way!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width