elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: (TUTORIAL) Aprende a emular Sentinel Dongle By Yapis


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Píxeles y Bucle For
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] 3 Ir Abajo Respuesta Imprimir
Autor Tema: Píxeles y Bucle For  (Leído 5,937 veces)
raul338


Desconectado Desconectado

Mensajes: 2.633


La sonrisa es la mejor forma de afrontar las cosas


Ver Perfil WWW
Re: Píxeles y Bucle For
« Respuesta #10 en: 18 Septiembre 2011, 23:54 pm »

No entiendo el porqué lo ideal sería colocar el cursor luego de encontrar el pixel que se busca, pero pues sabes lo que haces.
Eso, importa el puntero del mouse? GetDC y ReleaseDC consumen IO :P


En línea

ignorantev1.1


Desconectado Desconectado

Mensajes: 617


/\ Así acabo cuando quiero programar...


Ver Perfil WWW
Re: Píxeles y Bucle For
« Respuesta #11 en: 19 Septiembre 2011, 00:24 am »

Citar
P.D: Te importaría darme tu msn?

Si es para mí, mandame tu msn por PM, si no lo es... emmm... el caballo corre por el campo...

Citar
Eso, importa el puntero del mouse? GetDC y ReleaseDC consumen IO :P

Exacto, ¿por qué no colocarlos fuera del bucle?

¿Y de mi plantiamiento ni hablamos verdad?  :xD

Saludos!


En línea

raul338


Desconectado Desconectado

Mensajes: 2.633


La sonrisa es la mejor forma de afrontar las cosas


Ver Perfil WWW
Re: Píxeles y Bucle For
« Respuesta #12 en: 19 Septiembre 2011, 00:31 am »

¿Y de mi plantiamiento ni hablamos verdad?  :xD
Para eso es la misma tecnica, no podemos usar el DC como un mapa de bits :-\ asi que hay que convertirlo a BMP de ahi trabajar libremente :P
En línea

calk9

Desconectado Desconectado

Mensajes: 69


Ver Perfil
Re: Píxeles y Bucle For
« Respuesta #13 en: 19 Septiembre 2011, 00:46 am »

Jaj no me había fijado en eso, ya lo saqué del bucle pero el problema no era eso sino la sentencia if y el ver el color del pixel actual en donde se encuentra el mouse. Yo pense en ponerlo en un timer el código para verificar el color del pixel pero el bucle for es mucho más rapido que 1 milisegundo (que es el menor intervalo de un timer). Pues entonces digo, hago un hook y que al detectar WM_MOUSEMOVE verifique el color del pixel así estaría a la misma velocidad que el bulce... supongo jej. Pero necesito hacer un hook al mouse, no a mi aplicación y de otra ni hablar ya que tendría que inyectar una DLL... y no en basic  :rolleyes:.

Alguna idea?  :P

Saludos.
« Última modificación: 19 Septiembre 2011, 00:48 am por calk9 » En línea

raul338


Desconectado Desconectado

Mensajes: 2.633


La sonrisa es la mejor forma de afrontar las cosas


Ver Perfil WWW
Re: Píxeles y Bucle For
« Respuesta #14 en: 19 Septiembre 2011, 01:09 am »

Para hacer un hook al mouse no tienes que inyectar una DLL, solo necesitas una funcion en un modulo :xD
En línea

calk9

Desconectado Desconectado

Mensajes: 69


Ver Perfil
Re: Píxeles y Bucle For
« Respuesta #15 en: 19 Septiembre 2011, 03:33 am »

Sep pero para un proceso que no es el mio si necesito inyectar una DLL. Como podría hookear el mouse, sin especificar un determinado hwnd, simplemente los mensajes del mouse?

Saludos
En línea

Hasseds

Desconectado Desconectado

Mensajes: 145



Ver Perfil
Re: Píxeles y Bucle For
« Respuesta #16 en: 19 Septiembre 2011, 04:01 am »

mmm... revisá si esto  puede servir, en caso q sirva... te toca optimizar.

Código
  1.  
  2. Option Explicit
  3.  
  4. Private Sub Form_Load()
  5.  Call SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, &H2 Or &H1)
  6.  AutoRedraw = True
  7.  FontBold = True
  8.  BackColor = &HAA431B
  9.  ForeColor = vbWhite
  10.  StartHook
  11. End Sub
  12.  
  13. Private Sub Form_Unload(Cancel As Integer)
  14.  StopHook
  15. End Sub
  16.  
  17.  



Código
  1.  
  2. Option Explicit
  3.  
  4. Private Declare Function SetWindowsHookEx Lib "user32.dll" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
  5. Private Declare Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hHook As Long) As Long
  6. Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
  7. Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
  8. Public 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
  9.  
  10. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
  11. Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long, ByVal hdc As Long) As Long
  12.  
  13. Private Const WH_MOUSE_LL As Long = 14
  14.  
  15. Private Type POINTAPI: x As Long: y As Long: End Type
  16.  
  17. Dim hHook As Long
  18. Dim lDC As Long
  19.  
  20. Public Sub StartHook()
  21.    hHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf MouseProc, App.hInstance, &H0&)
  22.    lDC = GetWindowDC(&H0&)
  23. End Sub
  24.  
  25.  
  26. Public Sub StopHook()
  27.    Call UnhookWindowsHookEx(hHook)
  28.    hHook = &H0&
  29.    Call ReleaseDC(&H0&, lDC)
  30. End Sub
  31.  
  32.  
  33. Private Function MouseProc(ByVal ncode As Long, ByVal wParam As Long, lParam As POINTAPI) As Long
  34.  
  35.    Dim lColor As Long
  36.    lColor = GetPixel(lDC, lParam.x, lParam.y)
  37.  
  38.    'If Not lColor < 0 Then
  39.      'Form1.Cls
  40.      'Form1.Print Hex(lColor)
  41.      If lColor = &HAA431B Then
  42.        Form1.Caption = "SI"
  43.      Else
  44.        Form1.Caption = "NO"
  45.      End If
  46.    'End If
  47.  
  48.  MouseProc = CallNextHookEx(hHook, ncode, wParam, lParam)
  49.  
  50. End Function
  51.  
  52.  
  53.  
  54.  








« Última modificación: 19 Septiembre 2011, 05:36 am por Hasseds » En línea

Sergio Desanti
raul338


Desconectado Desconectado

Mensajes: 2.633


La sonrisa es la mejor forma de afrontar las cosas


Ver Perfil WWW
Re: Píxeles y Bucle For
« Respuesta #17 en: 19 Septiembre 2011, 11:04 am »

Creo que estas equivocando en conceptos :P

Para hacer un Hook al mouse no necesitas un hwnd especifico, es directo al mouse, pase por donde pase, haga lo que haga :P

Lo que tu quieres caputrar son los mensajes del mouse sobre una ventana, se llama "subclassing". Esta la clase de Paul Caton para subclassifcar formularios de tus proyectos, pero cuando se trata de otras aplicaciones, solo queda una dll que se injecta sola (anda dando vueltas por ahi :xD)

Revisa bien que quieres hacer, para mi que con solo hookear el mouse alcanza
En línea

LeandroA
Moderador
***
Desconectado Desconectado

Mensajes: 760


www.leandroascierto.com


Ver Perfil WWW
Re: Píxeles y Bucle For
« Respuesta #18 en: 19 Septiembre 2011, 21:19 pm »

Hola, si es masomenos lo que entiendo esta es la forma mas rapida

Código
  1. Option Explicit
  2. 'Autor: Leandro Ascierto
  3. 'Web: http://leandroascierto.com/blog/
  4. Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hDC As Long, pBitmapInfo As BITMAPINFO, ByVal un As Long, lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As Long
  5. Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
  6. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
  7. Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
  8. Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
  9. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
  10. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  11. Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
  12. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  13. Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Ptr() As Any) As Long
  14. Private Declare Function OleTranslateColor Lib "oleaut32.dll" (ByVal lOleColor As Long, ByVal lHPalette As Long, ByVal lColorRef As Long) As Long
  15. Private Declare Function SetCursorPos Lib "user32.dll" (ByVal x As Long, ByVal y As Long) As Long
  16.  
  17. Private Type RGBQUAD
  18.    rgbBlue As Byte
  19.    rgbGreen As Byte
  20.    rgbRed As Byte
  21.    rgbReserved As Byte
  22. End Type
  23.  
  24. Private Type BITMAPINFOHEADER
  25.    biSize As Long
  26.    biWidth As Long
  27.    biHeight As Long
  28.    biPlanes As Integer
  29.    biBitCount As Integer
  30.    biCompression As Long
  31.    biSizeImage As Long
  32.    biXPelsPerMeter As Long
  33.    biYPelsPerMeter As Long
  34.    biClrUsed As Long
  35.    biClrImportant As Long
  36. End Type
  37.  
  38. Private Type BITMAPINFO
  39.    bmiHeader As BITMAPINFOHEADER
  40.    bmiColors As RGBQUAD
  41. End Type
  42.  
  43. Private Type SAFEARRAYBOUND
  44.    cElements As Long
  45.    lLbound As Long
  46. End Type
  47.  
  48. Private Type SAFEARRAY2D
  49.    cDims As Integer
  50.    fFeatures As Integer
  51.    cbElements As Long
  52.    cLocks As Long
  53.    pvData As Long
  54.    Bounds(0 To 1) As SAFEARRAYBOUND
  55. End Type
  56.  
  57. Private Type POINTAPI
  58.    x As Long
  59.    y As Long
  60. End Type
  61.  
  62. Private Const DIB_RGB_COLORS = 0
  63. Private Const BI_RGB = 0&
  64.  
  65.  
  66. Private Function FindColorInScreen(ByVal oColor As OLE_COLOR, ByRef PT() As POINTAPI) As Long
  67.    Dim ScreenDC As Long
  68.    Dim TmpDC As Long
  69.    Dim hBmp As Long
  70.    Dim OldBmp As Long
  71.    Dim Addrs As Long
  72.    Dim x As Long
  73.    Dim y As Long
  74.    Dim lpBits() As Long
  75.    Dim BI As BITMAPINFO
  76.    Dim SA As SAFEARRAY2D
  77.    Dim W As Long, H As Long
  78.    Dim lColor As Long
  79.  
  80.    W = Screen.Width / Screen.TwipsPerPixelX
  81.    H = Screen.Height / Screen.TwipsPerPixelY
  82.  
  83.    With BI.bmiHeader
  84.        .biSize = Len(BI.bmiHeader)
  85.        .biWidth = W
  86.        .biHeight = H
  87.        .biPlanes = 1
  88.        .biBitCount = 32
  89.        .biCompression = BI_RGB
  90.        .biSizeImage = AlignScan(.biWidth, .biBitCount) * .biHeight
  91.    End With
  92.  
  93.    ScreenDC = GetDC(0)
  94.    TmpDC = CreateCompatibleDC(ScreenDC)
  95.    hBmp = CreateDIBSection(ScreenDC, BI, DIB_RGB_COLORS, Addrs, 0, 0)
  96.  
  97.    OldBmp = SelectObject(TmpDC, hBmp)
  98.  
  99.    Call BitBlt(TmpDC, 0, 0, W, H, ScreenDC, 0, 0, vbSrcCopy)
  100.  
  101.    Call ReleaseDC(0&, ScreenDC)
  102.  
  103.    With SA
  104.        .cbElements = 4
  105.        .cDims = 2
  106.        .Bounds(0).lLbound = 0
  107.        .Bounds(0).cElements = H
  108.        .Bounds(1).lLbound = 0
  109.        .Bounds(1).cElements = (BI.bmiHeader.biSizeImage \ .Bounds(0).cElements) \ 4
  110.        .pvData = Addrs
  111.    End With
  112.  
  113.    CopyMemory ByVal VarPtrArray(lpBits), VarPtr(SA), 4
  114.  
  115.    ReDim PT(0)
  116.  
  117.    lColor = ConvertColor(oColor)
  118.  
  119.    For y = H - 1 To 0 Step -1
  120.        For x = 0 To W - 1
  121.            If lpBits(x, y) = lColor Then
  122.                ReDim Preserve PT(FindColorInScreen)
  123.                With PT(FindColorInScreen)
  124.                    .x = x
  125.                    .y = H - y
  126.                End With
  127.                FindColorInScreen = FindColorInScreen + 1
  128.            End If
  129.        Next
  130.    Next
  131.  
  132.    CopyMemory ByVal VarPtrArray(lpBits), 0&, 4
  133.    Call DeleteObject(SelectObject(TmpDC, OldBmp))
  134.    Call DeleteDC(TmpDC)
  135. End Function
  136.  
  137. Private Function AlignScan(ByVal inWidth As Long, ByVal inDepth As Integer) As Long
  138.    AlignScan = (((inWidth * inDepth) + &H1F) And Not &H1F&) \ &H8
  139. End Function
  140.  
  141. Private Function ConvertColor(oColor As OLE_COLOR) As Long
  142.    Dim RGBA(0 To 3) As Byte
  143.    Dim BGRA(0 To 3) As Byte
  144.    OleTranslateColor oColor, 0, VarPtr(RGBA(0))
  145.    BGRA(0) = RGBA(2)
  146.    BGRA(1) = RGBA(1)
  147.    BGRA(2) = RGBA(0)
  148.    BGRA(3) = &HFF
  149.    CopyMemory ConvertColor, BGRA(0), 4&
  150. End Function
  151.  
  152. Private Sub Form_Load()
  153.    Dim lCount As Long
  154.    Dim PT() As POINTAPI
  155.    Me.AutoRedraw = True
  156.    lCount = FindColorInScreen(vbBlue, PT)
  157.    If lCount > 0 Then
  158.        SetCursorPos PT(0).x, PT(0).y
  159.        Dim i As Long
  160.        For i = 0 To lCount - 1
  161.            Debug.Print PT(i).x, PT(i).y
  162.        Next
  163.    End If
  164. End Sub
  165.  
En línea

calk9

Desconectado Desconectado

Mensajes: 69


Ver Perfil
Re: Píxeles y Bucle For
« Respuesta #19 en: 20 Septiembre 2011, 00:51 am »

mmm... revisá si esto  puede servir, en caso q sirva... te toca optimizar.

Código
  1.  
  2. Option Explicit
  3.  
  4. Private Sub Form_Load()
  5.  Call SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, &H2 Or &H1)
  6.  AutoRedraw = True
  7.  FontBold = True
  8.  BackColor = &HAA431B
  9.  ForeColor = vbWhite
  10.  StartHook
  11. End Sub
  12.  
  13. Private Sub Form_Unload(Cancel As Integer)
  14.  StopHook
  15. End Sub
  16.  
  17.  



Código
  1.  
  2. Option Explicit
  3.  
  4. Private Declare Function SetWindowsHookEx Lib "user32.dll" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
  5. Private Declare Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hHook As Long) As Long
  6. Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
  7. Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
  8. Public 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
  9.  
  10. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
  11. Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long, ByVal hdc As Long) As Long
  12.  
  13. Private Const WH_MOUSE_LL As Long = 14
  14.  
  15. Private Type POINTAPI: x As Long: y As Long: End Type
  16.  
  17. Dim hHook As Long
  18. Dim lDC As Long
  19.  
  20. Public Sub StartHook()
  21.    hHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf MouseProc, App.hInstance, &H0&)
  22.    lDC = GetWindowDC(&H0&)
  23. End Sub
  24.  
  25.  
  26. Public Sub StopHook()
  27.    Call UnhookWindowsHookEx(hHook)
  28.    hHook = &H0&
  29.    Call ReleaseDC(&H0&, lDC)
  30. End Sub
  31.  
  32.  
  33. Private Function MouseProc(ByVal ncode As Long, ByVal wParam As Long, lParam As POINTAPI) As Long
  34.  
  35.    Dim lColor As Long
  36.    lColor = GetPixel(lDC, lParam.x, lParam.y)
  37.  
  38.    'If Not lColor < 0 Then
  39.      'Form1.Cls
  40.      'Form1.Print Hex(lColor)
  41.      If lColor = &HAA431B Then
  42.        Form1.Caption = "SI"
  43.      Else
  44.        Form1.Caption = "NO"
  45.      End If
  46.    'End If
  47.  
  48.  MouseProc = CallNextHookEx(hHook, ncode, wParam, lParam)
  49.  
  50. End Function
  51.  
  52.  
  53.  
  54.  


Excelente justo lo que necesitaba! Gracias.
« Última modificación: 20 Septiembre 2011, 01:07 am por calk9 » En línea

Páginas: 1 [2] 3 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
de pixeles a vectores
Diseño Gráfico
kaliyas 5 2,506 Último mensaje 21 Noviembre 2005, 14:43 pm
por noob_Setup
pixeles
Diseño Gráfico
_loko_ 1 2,032 Último mensaje 9 Febrero 2006, 07:42 am
por Sub_Cero
Duda (Parar bucle con dato boolean) [bucle while]
Java
Dem0ny 5 18,285 Último mensaje 17 Diciembre 2008, 17:43 pm
por Dem0ny
ACERCA DE PIXELES
Programación Visual Basic
AsTeroine 2 1,578 Último mensaje 19 Febrero 2009, 05:40 am
por AsTeroine
Pixeles!
Programación General
prometheus48 2 1,850 Último mensaje 29 Diciembre 2011, 13:18 pm
por prometheus48
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines