Results 1 to 3 of 3

Thread: Create a listbox ,use it, then destroy it

  1. #1

    Thread Starter
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    Create a listbox ,use it, then destroy it

    Anyone have a sample of hwo to create a listbox, and then
    destroy it usint API

    I have examples of using this for other controls but I don't have
    any informatin on creating a listbox.

    CreateWindowEx
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  2. #2
    Fanatic Member Mindcrime's Avatar
    Join Date
    Jun 2001
    Location
    Peterborough, UK
    Posts
    555
    If you have a instance of a Listbox already on your form you can use the Load command.

    Load Listbox1(1)

    Listbox1(1).Move #, #, #, #

    Listbox1(1).Additem 'etc...

    Listbox1(1).Visible = True

    then when you are done, use

    Unload Listbox1(1)

    I don't know about any API call that does this?
    Mindcrime : )
    ICQ 24003332

    VB 5.0, VB 6.0 SP5, COM, DCOM, VB.NET Beta 2, Oracle 8

  3. #3

    Thread Starter
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Mindcrime...I would think there is one.
    Here is a list of the ones I have, but as I said, I don't have the constants and properties for the list box. If anyone has them I wouldn't mind a copy. It's not urgent, I found a solution to the problem I was having and now don't have to destroy the listbox.

    For anyone who wants them, here is the list I have.
    I haven't really played with this but I know it creates the objects.

    Code:
    'How to use the CreateWindowEx API to create visual basic controls at runtime 
    
    Option Explicit 
    
    Private Declare Function CreateWindowEx Lib "user32.dll" 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 
    
    Private Declare Function DestroyWindow Lib "user32" (ByVal hWnd As Long) As Long 
    
    Private Const BS_PUSHBUTTON = &H0& 
    Private Const WS_CHILD = &H40000000 
    Private Const WS_VISIBLE = &H10000000 
    Private Const WS_EX_CLIENTEDGE = &H200& 
    Private Const LVS_REPORT = &H1 
    Private Const ES_MULTILINE = &H4& 
    Private Const ES_AUTOVSCROLL = &H40& 
    Private Const WS_DLGFRAME = &H400000 
    Private Const WS_BORDER = &H800000 
    Private m_hButton As Long 
    Private m_hWndLV As Long 
    Private m_hEdit As Long 
    Private m_hLabel As Long 
    
    Private Sub Form_Load() 
    Dim lngStyle As Long 
    ' Define style 
    lngStyle = BS_PUSHBUTTON Or WS_CHILD Or WS_VISIBLE 
    ' Create the button 
    m_hButton = CreateWindowEx(0&, "BUTTON", "Click Me!", _ 
    lngStyle, 190, 10, 150, 50, Me.hWnd, 0&, App.hInstance, ByVal 0&) 
    
    ' Define style 
    lngStyle = WS_CHILD Or WS_VISIBLE Or LVS_REPORT 
    ' Create the listview 
    m_hWndLV = CreateWindowEx(WS_EX_CLIENTEDGE, "SysListView32", vbNullString, _ 
    lngStyle, 10, 10, 100, 100, Me.hWnd, 0, App.hInstance, ByVal 0&) 
    
    ' Define style 
    lngStyle = WS_DLGFRAME Or ES_AUTOVSCROLL Or ES_MULTILINE Or WS_CHILD Or WS_VISIBLE 
    ' Create the textbox 
    m_hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "TextBox", _ 
    lngStyle, 10, 120, 240, 100, Me.hWnd, 0&, App.hInstance, ByVal 0&) 
    
    ' Define style 
    lngStyle = WS_BORDER Or WS_CHILD Or WS_VISIBLE 
    ' Create the label 
    m_hLabel = CreateWindowEx(0&, "STATIC", "Label!", _ 
    lngStyle, 260, 170, 150, 30, Me.hWnd, 0&, App.hInstance, ByVal 0&) 
    End Sub 
    
    Private Sub Form_Unload(Cancel As Integer) 
    ' Cleanup 
    Call DestroyWindow(m_hButton) 
    Call DestroyWindow(m_hWndLV) 
    Call DestroyWindow(m_hEdit) 
    Call DestroyWindow(m_hLabel) 
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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