Buenas, estoy con esa duda. Tengo una aplicación a la que tengo que agregarle unos datos mas al combo (tengo que agregarle años, ya que se quedo corto y es una app vieja) y quisiera saber como agregarle un item. El buscar el Combo no me preocupa, me preocupa mas como agregar el item. Se hace con sendmessage no?
Dejo algunas funciones que voy a usar, quisas a alguien mas le sirven.
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowByClass( _
ByVal lpClassName As String, _
ByVal zero As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowByCaption( _
ByVal zero As IntPtr, _
ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
ByVal childAfter As IntPtr, _
ByVal lclassName As String, _
ByVal windowTitle As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
Gracias
Mariano
Edit:
Me tope con un problema. Al usar la funcion GetChildWindows de una ventana, no me devuelve el valor de los ComboBox, justamente los que necesito y del resto de los controles si.
Usando el WinID puedo sacar el handle del control, pero esa no es la idea.
Estoy atento a cualquier sugerencia.
Hola, si se hace con SendMessage y con el mensaje CB_ADDSTRING.
Private Const CB_ADDSTRING = &H143
y para agregar seria:
SendMessage handleDelCombo, CB_ADDSTRING, 0, ByVal "Hola"
saludos.
Seba123neo podrias pasarme la declaracion correcta a usar de SendMessage si la tenes por ahi?
Porque me da "La conversion especificada no es valida"
Las saque de:
http://www.pinvoke.net/default.aspx/user32.SendMessage
Saludos!
Edito:
Si lo pruebo en un combo dentro de mi formulario(para verificar que al menos funcione) me salta un error de "Intento de leer o escribir en la memoria protegida. A menudo, esto indica que hay otra memoria dañada"
:S
claro, te explico, el tema es que hay 2 tipos de declaraciones de SendMessage, una para mandar Stringsy la otra Long(integers en .NET).
en visual basic 6 cuando querias usar las 2 debias delarar las api's con diferentes nombres y cambiando el tipo de dato del ultimo parametro de la api. por eso veras por ahi nombres como SendMessageSTRING o SendMessageLONG.
visual basic 6 en el ultimo parametro se usaba AS Any, aca en .NET cuando queres mandar un mensaje con valor String debes poner en el ultimo parametro As String, y cuando quieras mandar un valor Integer, pones As Integer, podes declarar las 2 api's al mismo tiempo, total el .NET hace automaticamente sobrecarga de funciones, y entonces cuando mandes un string automaticamente va a usar la api que tenga como ultimo parametro String, igual para la de Integer...
Para Integer:
<System.Runtime.InteropServices.DllImport("user32.DLL")> _
Private Shared Function SendMessage( _
ByVal hWnd As System.IntPtr, ByVal wMsg As Integer, _
ByVal wParam As Integer, ByVal lParam As Integer _
) As Integer
End Sub
Para String:
<System.Runtime.InteropServices.DllImport("user32.DLL")> _
Private Shared Function SendMessage( _
ByVal hWnd As System.IntPtr, ByVal wMsg As Integer, _
ByVal wParam As Integer, ByVal lParam As String _
) As Integer
End Sub
saludos.
Gracias!! Acabo de probarlo con en una aplicacion mia y funciono! Mañana la pruebo en la app que necesito y comento.
El problema estaba en el tipo de dato, mira vos. Habia visto una con StringBuilder y me daba un error raro. En fin, gracias!
Atte.
Mariano Malomo
Edit:
Y ya que estamos en el tema, de donde puedo sacar los valores de las constantes para otras acciones para este control y otros? Seria de gran utilidad
de internet jeje ;D, aca todas los mensajes para combobox:
Public Const CB_GETEDITSEL As Integer = &H140
Public Const CB_LIMITTEXT As Integer = &H141
Public Const CB_SETEDITSEL As Integer = &H142
Public Const CB_ADDSTRING As Integer = &H143
Public Const CB_DELETESTRING As Integer = &H144
Public Const CB_DIR As Integer = &H145
Public Const CB_GETCOUNT As Integer = &H146
Public Const CB_GETCURSEL As Integer = &H147
Public Const CB_GETLBTEXT As Integer = &H148
Public Const CB_GETLBTEXTLEN As Integer = &H149
Public Const CB_INSERTSTRING As Integer = &H14A
Public Const CB_RESETCONTENT As Integer = &H14B
Public Const CB_FINDSTRING As Integer = &H14C
Public Const CB_SELECTSTRING As Integer = &H14D
Public Const CB_SETCURSEL As Integer = &H14E
Public Const CB_SHOWDROPDOWN As Integer = &H14F
Public Const CB_GETITEMDATA As Integer = &H150
Public Const CB_SETITEMDATA As Integer = &H151
Public Const CB_GETDROPPEDCONTROLRECT As Integer = &H152
Public Const CB_SETITEMHEIGHT As Integer = &H153
Public Const CB_GETITEMHEIGHT As Integer = &H154
Public Const CB_SETEXTENDEDUI As Integer = &H155
Public Const CB_GETEXTENDEDUI As Integer = &H156
Public Const CB_GETDROPPEDSTATE As Integer = &H157
Public Const CB_FINDSTRINGEXACT As Integer = &H158
Public Const CB_SETLOCALE As Integer = 345
Public Const CB_GETLOCALE As Integer = 346
Public Const CB_GETTOPINDEX As Integer = 347
Public Const CB_SETTOPINDEX As Integer = 348
Public Const CB_GETHORIZONTALEXTENT As Integer = 349
Public Const CB_SETHORIZONTALEXTENT As Integer = 350
Public Const CB_GETDROPPEDWIDTH As Integer = 351
Public Const CB_SETDROPPEDWIDTH As Integer = 352
Public Const CB_INITSTORAGE As Integer = 353
Public Const CB_MSGMAX As Integer = 354
esta pagina es buena:
Mensaje CB_ADDSTRING (http://winapi.conclase.net/curso/?winmsg=CB_ADDSTRING)
y esta tambien:
CB_ (Constants) (http://www.pinvoke.net/default.aspx/Constants/CB_.html)
saludos.
Funciono de maravillas en donde quería.
Gracias por las constantes
Saludos