Hola, me gustaria crear un .ahk en el que importes un bloc de notas y al darle a un boton si detecta alguna palabra que este se ponga en rojo y si no hay ninguna en verde.
Ejemplos: https://gyazo.com/8764d191f4ff6ebbd9dab0124c63d23e
https://gyazo.com/628f795a6a4498f7827b670d0b3aa61d.
Necesito referencias porfavor.
Scanner de texto
Moderator: Flipeador
Re: Scanner de texto
Hola,
Aquí tienes un ejemplo sencillo, puedes utilizar AutoGUI para modificar la ventana.
Aquí tienes un ejemplo sencillo, puedes utilizar AutoGUI para modificar la ventana.
Code: Select all
; REEMPLAZA 'String' por la cadena a buscar
C := "String"
; -------------------------------------------------------------------
Gui Add, Edit, x8 y8 w518 h21 hWndhEdit
Gui Add, Button, x536 y7 w23 h23 gS, ...
Gui Add, Button, x7 y39 w163 h25 gComp, Comprobar
Gui Add, Picture, x187 y39 w339 h25 HWNDhPic
Gui Show
Control, Style, -0x3,, ahk_id %hPic%
Control, Style, +0xE,, ahk_id %hPic%
Return
GuiEscape:
GuiClose:
ExitApp
Comp:
If (hBitmap := DllCall("User32.dll\SendMessageW", "Ptr", hPic, "UInt", 0x0173, "UInt", 0, "Ptr", 0, "Ptr"))
DllCall("Gdi32.dll\DeleteObject", "Ptr", hBitmap)
hBitmap := DllCall("Gdi32.dll\CreateBitmap", "Int", 1, "Int", 1, "UInt", 1, "UInt", 24, "Ptr", 0, "Ptr")
hBitmap := DllCall("User32.dll\CopyImage", "Ptr", hBitmap, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0x2008, "Ptr")
VarSetCapacity(BITSCOLORDATA, 4, 0)
ControlGetText, Text,, ahk_id %hEdit%
FileRead, Text, % Text
NumPut(InStr(Text, C) ? 0x0000FF : 0xFF0000, BITSCOLORDATA, 0, "UInt")
DllCall("Gdi32.dll\SetBitmapBits", "Ptr", hBitmap, "UInt", 4, "Ptr", &BITSCOLORDATA)
hBitmap := DllCall("User32.dll\CopyImage", "Ptr", hBitmap, "Int", 0, "Int", 339, "Int", 25, "Int", 0x200C, "Ptr")
DllCall("User32.dll\SendMessageW", "Ptr", hPic, "UInt", 0x0172, "Ptr", 0, "Ptr", hBitmap)
Return
S:
FileSelectFile FN
If (!ErrorLevel)
ControlSetText,, % FN, ahk_id %hEdit%
Return
Re: Scanner de texto
Como puedo hacer para que busque mas de 1 string?
Re: Scanner de texto
El ejemplo lo hice rápido y un poco 'desordenado', tal vez se te dificulte un poco entender bien como funciona, aquí te lo dejo un poco más ordenado.
Lee los comentarios:
Fíjate en la línea 24 y lee InStr.
Lee los comentarios:
Code: Select all
Gui Add, Edit, x8 y8 w518 h21 hWndhEdit
Gui Add, Button, x536 y7 w23 h23 gS, ...
Gui Add, Button, x7 y39 w163 h25 gComp, Comprobar
Gui Add, Picture, x187 y39 w339 h25 HWNDhPic
Gui Show
Return
; Ejecutado al cerrar la ventana o presionar escape
GuiEscape:
GuiClose:
ExitApp
; Ejecutado cuando haces clic en el botón 'Comprobar'
Comp:
; Obtenemos el texto del control Edit
ControlGetText, Text,, ahk_id %hEdit%
; Leemos el archivo
FileRead, Text, % Text
If (!ErrorLevel) ;Si el archivo se ha leído con éxito
{
; Comprueba por las cadenas 'String' o 'Hola'
If (InStr(Text, "String") || InStr(Text, "Hola"))
Color := 0x00FF00 ;verde
Else
Color := 0xFF0000 ;rojo
SetPicColor(hPic, Color) ;Cambiar color
}
Return
; Ejecutado cuando haces clic en el botón '...'
S:
FileSelectFile FN ;diálogo para seleccionar un archivo
If (!ErrorLevel) ;si el usuario aceptó el diálogo
ControlSetText,, % FN, ahk_id %hEdit% ;cambiar el texto del control Edit
Return
/*
Esta función cambia el color de un control Picture
hPic es el identificador del control
Color es el color RGB
*/
SetPicColor(hPic, Color)
{
Control, Style, -0x3,, ahk_id %hPic%
Control, Style, +0xE,, ahk_id %hPic%
If (hBitmap := DllCall("User32.dll\SendMessageW", "Ptr", hPic, "UInt", 0x0173, "UInt", 0, "Ptr", 0, "Ptr"))
DllCall("Gdi32.dll\DeleteObject", "Ptr", hBitmap)
hBitmap := DllCall("Gdi32.dll\CreateBitmap", "Int", 1, "Int", 1, "UInt", 1, "UInt", 24, "Ptr", 0, "Ptr")
hBitmap := DllCall("User32.dll\CopyImage", "Ptr", hBitmap, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0x2008, "Ptr")
VarSetCapacity(BITSCOLORDATA, 4, 0)
NumPut(Color, BITSCOLORDATA, 0, "UInt")
DllCall("Gdi32.dll\SetBitmapBits", "Ptr", hBitmap, "UInt", 4, "Ptr", &BITSCOLORDATA)
hBitmap := DllCall("User32.dll\CopyImage", "Ptr", hBitmap, "Int", 0, "Int", 339, "Int", 25, "Int", 0x200C, "Ptr")
DllCall("User32.dll\SendMessageW", "Ptr", hPic, "UInt", 0x0172, "Ptr", 0, "Ptr", hBitmap)
}
Re: Scanner de texto
Hola vuelvo a revivir el tema ya que me surgio un problema, por mucho que intento esto no lo consigo, quiero que halla dos hWndhPic y que cada uno busque distintas strings en el texto que escanea, pondre un ejemplo: El hWndhPic1 escanea string1 y el hWndhPic2 escanea string2 si en el texto que escanea esta string2 solo se pone en verde el hWndhPic2.
Re: Scanner de texto
Tal vez la mejor manera de hacerlo sería utilizando otro tipo de control, como un ListView, eso te lo dejo a tí, es algo más complejo pero te recomiendo que mires en la documentación todo lo que es GUI. Puedes utilizar AutoGUI para crear tu propia ventana.
Code: Select all
Gui Add, Edit, x8 y8 w518 h21 hWndhEdit
Gui Add, Button, x536 y7 w23 h23 gS, ...
Gui Add, Button, x7 y39 w163 h25 gComp, Comprobar
Gui Add, Picture, x187 y39 w100 h50 HWNDhPic Border
Gui Add, Picture, x387 y39 w109 h50 HWNDhPic2 Border
Gui Show
Return
; Ejecutado al cerrar la ventana o presionar escape
GuiEscape:
GuiClose:
ExitApp
; Ejecutado cuando haces clic en el botón 'Comprobar'
Comp:
; Obtenemos el texto del control Edit
ControlGetText, Text,, ahk_id %hEdit%
; Leemos el archivo
FileRead, Text, % Text
If (!ErrorLevel) ;Si el archivo se ha leído con éxito
{
; Comprueba por las cadenas 'String' o 'Hola' en 'hPic'
If (InStr(Text, "String") || InStr(Text, "Hola"))
Color := 0x00FF00 ;verde
Else
Color := 0xFF0000 ;rojo
SetPicColor(hPic, Color) ;Cambiar color
; Comprueba por las cadenas 'String2' o 'Hola2' en 'hPic2'
If (InStr(Text, "String2") || InStr(Text, "Hola2"))
Color := 0x00FF00 ;verde
Else
Color := 0xFF0000 ;rojo
SetPicColor(hPic2, Color) ;Cambiar color
}
Return
; Ejecutado cuando haces clic en el botón '...'
S:
FileSelectFile FN ;diálogo para seleccionar un archivo
If (!ErrorLevel) ;si el usuario aceptó el diálogo
ControlSetText,, % FN, ahk_id %hEdit% ;cambiar el texto del control Edit
Return
/*
Esta función cambia el color de un control Picture
hPic es el identificador del control
Color es el color RGB
*/
SetPicColor(hPic, Color)
{
WinGetPos,,, W, H, ahk_id %hPic%
Control, Style, -0x3,, ahk_id %hPic%
Control, Style, +0xE,, ahk_id %hPic%
If (hBitmap := DllCall("User32.dll\SendMessageW", "Ptr", hPic, "UInt", 0x0173, "UInt", 0, "Ptr", 0, "Ptr"))
DllCall("Gdi32.dll\DeleteObject", "Ptr", hBitmap)
hBitmap := DllCall("Gdi32.dll\CreateBitmap", "Int", 1, "Int", 1, "UInt", 1, "UInt", 24, "Ptr", 0, "Ptr")
hBitmap := DllCall("User32.dll\CopyImage", "Ptr", hBitmap, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0x2008, "Ptr")
VarSetCapacity(BITSCOLORDATA, 4, 0)
NumPut(Color, BITSCOLORDATA, 0, "UInt")
DllCall("Gdi32.dll\SetBitmapBits", "Ptr", hBitmap, "UInt", 4, "Ptr", &BITSCOLORDATA)
hBitmap := DllCall("User32.dll\CopyImage", "Ptr", hBitmap, "Int", 0, "Int", W, "Int", H, "Int", 0x200C, "Ptr")
DllCall("User32.dll\SendMessageW", "Ptr", hPic, "UInt", 0x0172, "Ptr", 0, "Ptr", hBitmap)
}
Who is online
Users browsing this forum: No registered users and 37 guests