Visual C++ .NET - Convertir a Visual Basic

 
Vista:

Convertir a Visual Basic

Publicado por Korben (1 intervención) el 22/02/2007 19:32:31
Compañeros, uds que conocen el idioma en C++, para la comunidad forera podrían traducir el siguietne codigo a VIsual basic. Utilizo visual studio 2005 y me funka perfecto el programa, pero lo necesito en visual para poder acoplarlo en un programa que tengo.
Por favor!! dense el tiempo, estoy seguro que es de utilidad para todos.
El codigo es: http://www.codeproject.com/combobox/xtipcombobox.asp

PD: Si no pueden traducirlo, saben alguna manera de hacer eso mismo en vb???

GRACIAS!!!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro

Implementación de ComboBox con sugestiones de autocompletado

Publicado por Alejandro (265 intervenciones) el 30/01/2024 20:03:34
Korben, aquí tienes una adaptación del código en el enlace proporcionado para su uso en Visual Basic 2005. Ten en cuenta que algunas estructuras y conceptos de C++ no tienen una traducción directa a Visual Basic, por lo que he tratado de hacer la conversión de manera cercana y funcional:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Imports System.Runtime.InteropServices
 
Public Class XTipComboBox
    Inherits ComboBox
 
    Private Const CB_FINDSTRING As Integer = &H14C
    Private Const CB_ERR As Integer = -1
 
    <DllImport("user32.dll", CharSet:=CharSet.Auto)>
    Private Shared Function SendMessage(hWnd As IntPtr, msg As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr
    End Function
 
    Protected Overrides Sub OnTextChanged(e As EventArgs)
        MyBase.OnTextChanged(e)
 
        AutoCompleteItems()
    End Sub
 
    Private Sub AutoCompleteItems()
        Dim textToMatch As String = Me.Text
        Dim index As Integer = FindString(textToMatch)
 
        If index <> CB_ERR Then
            Me.SelectedIndex = index
            Me.SelectionStart = textToMatch.Length
            Me.SelectionLength = Me.Text.Length - Me.SelectionStart
        End If
    End Sub
 
    Private Function FindString(textToMatch As String) As Integer
        Dim findStruct As New NativeMethods.EDITBALLOONTIP()
        findStruct.cbStruct = Marshal.SizeOf(findStruct)
        findStruct.pszTitle = textToMatch
        findStruct.pszText = String.Empty
        findStruct.ttiIcon = NativeMethods.TTI_NONE
 
        Dim findInfo As New NativeMethods.COMBOBOXINFO()
        findInfo.cbSize = Marshal.SizeOf(findInfo)
 
        If NativeMethods.GetComboBoxInfo(Me.Handle, findInfo) Then
            Dim comboBoxHandle As IntPtr = findInfo.hwndCombo
 
            Return CInt(SendMessage(comboBoxHandle, CB_FINDSTRING, IntPtr.Zero, Marshal.UnsafeAddrOfPinnedArrayElement(New Byte() {0, 0, 0, 0}, 0)))
        End If
 
        Return CB_ERR
    End Function
End Class
 
Friend Class NativeMethods
    Friend Const TTI_NONE As Integer = 0
    Friend Const CBEM_INSERTITEM As Integer = &H14D
    Friend Const CBEM_SETITEM As Integer = &H14E
    Friend Const CBEM_GETITEM As Integer = &H14F
    Friend Const CBEM_SETEXTENDEDSTYLE As Integer = &H156
    Friend Const CBES_EX_NOEDITIMAGE As Integer = &H1
 
    <StructLayout(LayoutKind.Sequential)>
    Friend Structure EDITBALLOONTIP
        Friend cbStruct As Integer
        <MarshalAs(UnmanagedType.LPTStr)>
        Friend pszTitle As String
        <MarshalAs(UnmanagedType.LPTStr)>
        Friend pszText As String
        Friend ttiIcon As Integer
    End Structure
 
    <StructLayout(LayoutKind.Sequential)>
    Friend Structure COMBOBOXINFO
        Friend cbSize As Integer
        Friend rcItem As RECT
        Friend rcButton As RECT
        Friend stateButton As Integer
        Friend hwndCombo As IntPtr
        Friend hwndEdit As IntPtr
        Friend hwndList As IntPtr
    End Structure
 
    <StructLayout(LayoutKind.Sequential)>
    Friend Structure RECT
        Friend left As Integer
        Friend top As Integer
        Friend right As Integer
        Friend bottom As Integer
    End Structure
 
    <DllImport("user32.dll")>
    Friend Shared Function GetComboBoxInfo(hWnd As IntPtr, ByRef pcbi As COMBOBOXINFO) As Boolean
    End Function
End Class

Este código traduce el ejemplo del enlace proporcionado a Visual Basic 2005, permitiendo la funcionalidad de autocompletado en un ComboBox. Ten en cuenta que algunas adaptaciones se han realizado para que sea compatible con la sintaxis y las características de Visual Basic. Asegúrate de probarlo y ajustarlo según sea necesario para tu aplicación.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar