|
401
|
Programación / Programación Visual Basic / Re: como cargar 100 KBs en una variable; problema con InStr
|
en: 31 Diciembre 2008, 15:20 pm
|
InStr funciona Perfecto Option Explicit
Private Sub Form_Load()
Dim s As String
'creo un archivo de mas de 100 Kb Open App.Path & "\archivo.txt" For Output As #1 Dim i As Long: For i = 1 To 12500: Print #1, i: Next i Close #1
'Agrego al archivo la subcadena "XXXXX" al final este Open App.Path & "\archivo.txt" For Append As #1: Print #1, "XXXXX": Close #1
'Abro el archivo y lo pasa a la variable "s" Open App.Path & "\archivo.txt" For Input As #1: s = Input(LOF(1), #1): Close #1
MsgBox Len(s), , "La cadena S es mayor a 100 KB"
MsgBox InStr(1, s, "XXXXX"), , "InStr de XXXXX es mayor a 22000"
End
End Sub
Saludos
|
|
|
402
|
Programación / Programación Visual Basic / Re: como hallar el Exe al que pertenece la ventana ???
|
en: 29 Diciembre 2008, 22:54 pm
|
Por coordenadas del mouse "V 2.0" Solo hay que agregar un Timer1 Option Explicit Private Declare Function SetWindowPos Lib "user32" (ByVal Hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal Hwnd As Long, lpdwprocessid As Long) As Long Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function GetModuleFileNameExA Lib "PSAPI.DLL" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFilename As String, ByVal nSize As Long) As Long Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Type POINTAPI: x As Long: y As Long: End Type
Private Sub Form_Load() Me.BackColor = vbBlack: Me.ForeColor = vbWhite: Me.FontBold = True Me.Top = 0: Me.Left = 0: Me.Width = 6450: Me.Height = 1000 Me.BorderStyle = 5: Timer1.Interval = 100 End Sub 'Private Sub Form_Load(): Timer1.Interval = 100: End Sub
Private Sub Timer1_Timer() Call SetWindowPos(Me.Hwnd, -1, 0, 0, 0, 0, &H2 Or &H1) Dim Cor As POINTAPI: Dim retorno As Long: retorno = GetCursorPos(Cor) Dim Handle As Long: Handle = WindowFromPoint(Cor.x, Cor.y) Dim idProc As Long: Call GetWindowThreadProcessId(Handle, idProc) Dim Handle_Proceso As Long: Handle_Proceso = OpenProcess(&H400 + &H10, 0, idProc) Dim Buffer As String: Buffer = Space(255) Dim ret As Long: ret = GetModuleFileNameExA(Handle_Proceso, 0, Buffer, 255) Dim Ruta As String: Ruta = Left(Buffer, ret): ret = CloseHandle(Handle_Proceso) Me.Cls: Me.Print "": Me.Print Ruta: Me.Caption = "ID PROCESO = " & idProc End Sub
Saludos
|
|
|
403
|
Programación / Programación Visual Basic / Re: como cargar 100 KBs en una variable; problema con InStr
|
en: 29 Diciembre 2008, 20:11 pm
|
No tengo ese problema con InStr , tal vez lo estes usando mal, pero tambien podes dividír la cadena en 5 subcadenas (s1 s2 s3 s4 s5) Option Explicit
Private Sub Form_Load()
Dim s As String Open App.Path & "\archivo.txt" For Input As #1 s = Input(LOF(1), #1) Close #1
MsgBox Len(s), , "Len(s)"
Dim s1 As String: s1 = Mid(s, 1, 20000) Dim s2 As String: s2 = Mid(s, 20001, 20000) Dim s3 As String: s3 = Mid(s, 40001, 20000) Dim s4 As String: s4 = Mid(s, 60001, 20000) Dim s5 As String: s5 = Mid(s, 80001, Len(s))
MsgBox Len(s1), , "s1" MsgBox Len(s2), , "s2" MsgBox Len(s3), , "s3" MsgBox Len(s4), , "s4" MsgBox Len(s5), , "s5"
' busco los ultimos 10 caracteres de s5 que son los 10 caracters finales del txt MsgBox Mid(s5, Len(s5) - 10, Len(s5)), , "Ultimos 10 bytes de s5 = Ultimos 10 bytes de archivo.txt"
' "s" sigue siendo la cadena entera MsgBox Len(s), , "la cadena s se mantiene intacta"
End
End Sub
(si no sale postea un ejemplo de como sería la búsqueda que tenes que hacer) Saludos
|
|
|
410
|
Programación / Programación Visual Basic / Re: como allar el archivo al que pertenece la ventana???
|
en: 28 Diciembre 2008, 03:57 am
|
Por coordenadas del mouse: Option Explicit Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwprocessid As Long) As Long Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long 'Obtiene el nombre del proceso a partir de un handle Private Declare Function GetModuleFileNameExA Lib "PSAPI.DLL" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFilename As String, ByVal nSize As Long) As Long Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long Private Const PROCESS_VM_READ As Long = (&H10) Private Const PROCESS_QUERY_INFORMATION As Long = (&H400)
'Obtiene el Handle de una ventana a partir de una coordenada Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long 'Recupera la coordenada del cursor Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI x As Long y As Long End Type Function ProcIDFromWnd(ByVal hwnd As Long) As Long
Dim idProc As Long GetWindowThreadProcessId hwnd, idProc 'crea ID de un proceso desde un HWnd ProcIDFromWnd = idProc 'retorno de la ID de un proceso
End Function
Private Sub Form_Load()
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Dim retorno As Long Dim Handle As Long Dim Cor As POINTAPI
'Obtiene la coordenada del Mouse retorno = GetCursorPos(Cor) 'Recuperamos el HWND de la ventana asociada a esa coordenada Handle = WindowFromPoint(Cor.x, Cor.y)
Dim Handle_Proceso As Long: Handle_Proceso = OpenProcess(&H400 + &H10, 0, ProcIDFromWnd(Handle))
If Handle_Proceso <> 0 Then Dim Buffer As String: Buffer = Space(255) ' Crea un buffer para almacenar el nombre y ruta Dim ret As Long: ret = GetModuleFileNameExA(Handle_Proceso, 0, Buffer, 255) ' pasa el Buffer al Api y el Handle Dim Ruta As String: Ruta = Left(Buffer, ret) ' Le elimina los espacios nulos a la cadena devuelta End If
ret = CloseHandle(Handle_Proceso) 'Cierra el proceso abierto
Me.Cls: Me.Print Ruta 'Muestra la ruta del proceso
End Sub
Saludos
|
|
|
|
|
|
|