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

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


  Mostrar Mensajes
Páginas: 1 ... 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 [707] 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 ... 1236
7061  Programación / .NET (C#, VB.NET, ASP) / [APORTE] Ejemplo de un LL-Hook para el Mouse. en: 28 Junio 2014, 08:14 am
Hola

Para todos los que estén interesados en iniciarse en los Hooks de bajo nivel (en lo cual yo no soy ningún experto) esto les podría servir, ya que considero haberlo dejado muy bien documentado y se puede aprender algo solo leyendo los comentarios XML.

Simplemente es un Hook que intercepta los eventos del ratón, pudiendo suscribirse a ellos, nada más que eso.

Código
  1. ' ***********************************************************************
  2. ' Author           : Elektro
  3. ' Last Modified On : 05-13-2014
  4. ' ***********************************************************************
  5. ' <copyright file="MouseHook.vb" company="Elektro Studios">
  6. '     Copyright (c) Elektro Studios. All rights reserved.
  7. ' </copyright>
  8. ' ***********************************************************************
  9.  
  10. #Region " Instructions "
  11.  
  12. ' Go to page:
  13. ' Project > Properties > Debug
  14. '
  15. ' And uncheck the option:
  16. ' Enable the Visual Studio Hosting Process
  17.  
  18. #End Region
  19.  
  20. #Region " Usage Examples "
  21.  
  22. ' ''' <summary>
  23. ' ''' A low level mouse hook that captures mouse events.
  24. ' ''' </summary>
  25. 'Private WithEvents MouseEvents As MouseHook = Nothing
  26.  
  27. ' ''' <summary>
  28. ' ''' Handles the 'MouseLeftDown' event of the Mouse Hook.
  29. ' ''' </summary>
  30. ' ''' <param name="MouseLocation">Indicates the mouse [X,Y] coordinates.</param>
  31. 'Private Sub MouseEvents_MouseLeftDown(ByVal MouseLocation As Point) Handles MouseEvents.MouseLeftDown
  32. '
  33. '    Debug.WriteLine(String.Format("Mouse Left Down At: x={0}, y={1}", CStr(MouseLocation.X), CStr(MouseLocation.Y)))
  34. '
  35. 'End Sub
  36.  
  37. ' ''' <summary>
  38. ' ''' Handles the 'MouseLeftUp' event of the Mouse Hook.
  39. ' ''' </summary>
  40. ' ''' <param name="MouseLocation">Indicates the mouse [X,Y] coordinates.</param>
  41. 'Private Sub MouseEvents_MouseLeftUp(ByVal MouseLocation As Point) Handles MouseEvents.MouseLeftUp
  42. '
  43. '    Debug.WriteLine(String.Format("Mouse Left Up At: x={0}, y={1}", CStr(MouseLocation.X), CStr(MouseLocation.Y)))
  44. '
  45. 'End Sub
  46.  
  47. ' ''' <summary>
  48. ' ''' Handles the 'MouseMove' event of the Mouse Hook.
  49. ' ''' </summary>
  50. ' ''' <param name="MouseLocation">Indicates the mouse [X,Y] coordinates.</param>
  51. 'Private Sub MouseEvents_MouseMove(ByVal MouseLocation As Point) Handles MouseEvents.MouseMove
  52. '
  53. '    Debug.WriteLine(String.Format("Mouse Moved To: x={0}, y={1}", CStr(MouseLocation.X), CStr(MouseLocation.Y)))
  54. '
  55. 'End Sub
  56.  
  57. ' ''' <summary>
  58. ' ''' Handles the 'Click' event of the 'ButtonStartHook' control.
  59. ' ''' </summary>
  60. 'Private Sub ButtonStartHook() Handles ButtonStartHook.Click
  61.  
  62. '    ' Start the Mouse Hook.
  63. '    MouseEvents = New MouseHook
  64.  
  65. 'End Sub
  66.  
  67. ' ''' <summary>
  68. ' ''' Handles the 'Click' event of the 'ButtonStopHook' control.
  69. ' ''' </summary>
  70. 'Private Sub ButtonStopHook() Handles ButtonStopHook.Click
  71.  
  72. '    ' Stop the Mouse Hook.
  73. '    MouseEvents = Nothing
  74.  
  75. 'End Sub
  76.  
  77. #End Region
  78.  
  79. #Region " Imports "
  80.  
  81. Imports System.ComponentModel
  82. Imports System.Reflection
  83. Imports System.Runtime.InteropServices
  84.  
  85. #End Region
  86.  
  87. #Region " MouseHook "
  88.  
  89. ''' <summary>
  90. ''' A low level mouse hook class that captures mouse events.
  91. ''' </summary>
  92. Public Class MouseHook
  93.  
  94. #Region " WinAPI "
  95.  
  96. #Region " Methods "
  97.  
  98.    ''' <summary>
  99.    ''' Passes the hook information to the next hook procedure in the current hook chain.
  100.    ''' A hook procedure can call this function either before or after processing the hook information.
  101.    ''' For more info see here:
  102.    ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms644974%28v=vs.85%29.aspx
  103.    ''' </summary>
  104.    ''' <param name="idHook">
  105.    ''' This parameter is ignored.
  106.    ''' </param>
  107.    ''' <param name="nCode">
  108.    ''' The hook code passed to the current hook procedure.
  109.    ''' The next hook procedure uses this code to determine how to process the hook information.
  110.    ''' </param>
  111.    ''' <param name="wParam">
  112.    ''' The wParam value passed to the current hook procedure.
  113.    ''' The meaning of this parameter depends on the type of hook associated with the current hook chain.
  114.    ''' </param>
  115.    ''' <param name="lParam">
  116.    ''' The lParam value passed to the current hook procedure.
  117.    ''' The meaning of this parameter depends on the type of hook associated with the current hook chain.
  118.    ''' </param>
  119.    ''' <returns>
  120.    ''' This value is returned by the next hook procedure in the chain.
  121.    ''' The current hook procedure must also return this value.
  122.    ''' The meaning of the return value depends on the hook type.
  123.    ''' For more information, see the descriptions of the individual hook procedures.
  124.    ''' </returns>
  125.    <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)>
  126.    Private Shared Function CallNextHookEx(
  127.           ByVal idHook As Integer,
  128.           ByVal nCode As Integer,
  129.           ByVal wParam As Integer,
  130.           ByVal lParam As MSLLHOOKSTRUCT
  131.    ) As Integer
  132.    End Function
  133.  
  134.    ''' <summary>
  135.    ''' Installs an application-defined hook procedure into a hook chain.
  136.    ''' You would install a hook procedure to monitor the system for certain types of events.
  137.    ''' These events are associated either with a specific thread
  138.    ''' or with all threads in the same desktop as the calling thread.
  139.    ''' For more info see here:
  140.    ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx
  141.    ''' </summary>
  142.    ''' <param name="idHook">
  143.    ''' The type of hook procedure to be installed.
  144.    ''' </param>
  145.    ''' <param name="lpfn">
  146.    ''' A pointer to the hook procedure.
  147.    ''' If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process,
  148.    ''' the lpfn parameter must point to a hook procedure in a DLL.
  149.    ''' Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
  150.    ''' </param>
  151.    ''' <param name="hInstance">
  152.    ''' A handle to the DLL containing the hook procedure pointed to by the lpfn parameter.
  153.    ''' The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by
  154.    ''' the current process and if the hook procedure is within the code associated with the current process.
  155.    ''' </param>
  156.    ''' <param name="threadId">
  157.    ''' The identifier of the thread with which the hook procedure is to be associated.
  158.    ''' For desktop apps, if this parameter is zero, the hook procedure is associated
  159.    ''' with all existing threads running in the same desktop as the calling thread.
  160.    ''' </param>
  161.    ''' <returns>
  162.    ''' If the function succeeds, the return value is the handle to the hook procedure.
  163.    ''' If the function fails, the return value is NULL.
  164.    ''' </returns>
  165.    <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)>
  166.    Private Shared Function SetWindowsHookEx(
  167.           ByVal idHook As HookType,
  168.           ByVal lpfn As MouseProcDelegate,
  169.           ByVal hInstance As IntPtr,
  170.           ByVal threadId As Integer
  171.    ) As Integer
  172.    End Function
  173.  
  174.    ''' <summary>
  175.    ''' Removes a hook procedure installed in a hook chain by the 'SetWindowsHookEx' function.
  176.    ''' For more info see here:
  177.    ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms644993%28v=vs.85%29.aspx
  178.    ''' </summary>
  179.    ''' <param name="idHook">
  180.    ''' A handle to the hook to be removed.
  181.    ''' This parameter is a hook handle obtained by a previous call to SetWindowsHookEx.
  182.    ''' </param>
  183.    ''' <returns>
  184.    ''' If the function succeeds, the return value is nonzero.
  185.    ''' If the function fails, the return value is zero.
  186.    ''' </returns>
  187.    <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)>
  188.    Private Shared Function UnhookWindowsHookEx(
  189.           ByVal idHook As Integer
  190.    ) As Boolean
  191.    End Function
  192.  
  193. #End Region
  194.  
  195. #Region " Enums "
  196.  
  197.    ''' <summary>
  198.    ''' Indicates a type of Hook procedure to be installed.
  199.    ''' </summary>
  200.    <Description("Enum used in 'idHook' parameter of 'SetWindowsHookEx' function")>
  201.    Private Enum HookType As Integer
  202.  
  203.        ' **************************************
  204.        ' This enumeration is partially defined.
  205.        ' **************************************
  206.  
  207.        ''' <summary>
  208.        ''' Installs a hook procedure that monitors low-level mouse input events.
  209.        ''' For more information, see the LowLevelMouseProc hook procedure.
  210.        ''' </summary>
  211.        WH_MOUSE_LL = 14
  212.  
  213.    End Enum
  214.  
  215. #End Region
  216.  
  217. #Region " Structures "
  218.  
  219.    ''' <summary>
  220.    ''' Contains information about a low-level mouse input event.
  221.    ''' </summary>
  222.    <Description("Structure used in 'lParam' parameter of 'CallNextHookEx' function")>
  223.    Private Structure MSLLHOOKSTRUCT
  224.  
  225.        ''' <summary>
  226.        ''' The ptThe x- and y-coordinates of the cursor, in screen coordinates.
  227.        ''' </summary>
  228.        Public pt As Point
  229.  
  230.        ''' <summary>
  231.        ''' If the message is 'WM_MOUSEWHEEL', the high-order word of this member is the wheel delta.
  232.        ''' The low-order word is reserved.
  233.        ''' A positive value indicates that the wheel was rotated forward, away from the user;
  234.        ''' a negative value indicates that the wheel was rotated backward, toward the user.
  235.        ''' One wheel click is defined as 'WHEEL_DELTA', which is '120'.
  236.        ''' </summary>
  237.        Public mouseData As Integer
  238.  
  239.        ''' <summary>
  240.        ''' The event-injected flag.
  241.        ''' </summary>
  242.        Public flags As Integer
  243.  
  244.        ''' <summary>
  245.        ''' The time stamp for this message.
  246.        ''' </summary>
  247.        Public time As Integer
  248.  
  249.        ''' <summary>
  250.        ''' Additional information associated with the message.
  251.        ''' </summary>
  252.        Public dwExtraInfo As Integer
  253.  
  254.    End Structure
  255.  
  256. #End Region
  257.  
  258. #End Region
  259.  
  260. #Region " Variables "
  261.  
  262.    ''' <summary>
  263.    '''
  264.    ''' </summary>
  265.    Private MouseHook As Integer
  266.  
  267. #End Region
  268.  
  269. #Region " Delegates "
  270.  
  271.    ''' <summary>
  272.    ''' Delegate MouseProcDelegate
  273.    ''' </summary>
  274.    ''' <returns>System.Int32.</returns>
  275.    Private Delegate Function MouseProcDelegate(
  276.            ByVal nCode As Integer,
  277.            ByVal wParam As Integer,
  278.            ByRef lParam As MSLLHOOKSTRUCT
  279.    ) As Integer
  280.  
  281.    ''' <summary>
  282.    ''' </summary>
  283.    Private MouseHookDelegate As MouseProcDelegate
  284.  
  285. #End Region
  286.  
  287. #Region " Enums "
  288.  
  289.    ''' <summary>
  290.    ''' Indicates a Windows Message related to a mouse events.
  291.    ''' For more info see here:
  292.    ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ff468877%28v=vs.85%29.aspx
  293.    ''' </summary>
  294.    Private Enum MouseWindowsMessages As Integer
  295.  
  296.        ''' <summary>
  297.        ''' Posted to a window when the cursor moves.
  298.        ''' If the mouse is not captured, the message is posted to the window that contains the cursor.
  299.        ''' Otherwise, the message is posted to the window that has captured the mouse
  300.        ''' </summary>
  301.        WM_MOUSEMOVE = &H200
  302.  
  303.        ''' <summary>
  304.        ''' Posted when the user presses the left mouse button while the cursor is in the client area of a window.
  305.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  306.        ''' Otherwise, the message is posted to the window that has captured the mouse
  307.        ''' </summary>
  308.        WM_LBUTTONDOWN = &H201
  309.  
  310.        ''' <summary>
  311.        ''' Posted when the user releases the left mouse button while the cursor is in the client area of a window.
  312.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  313.        ''' Otherwise, the message is posted to the window that has captured the mouse
  314.        ''' </summary>
  315.        WM_LBUTTONUP = &H202
  316.  
  317.        ''' <summary>
  318.        ''' Posted when the user double-clicks the left mouse button while the cursor is in the client area of a window.
  319.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  320.        ''' Otherwise, the message is posted to the window that has captured the mouse
  321.        ''' </summary>
  322.        WM_LBUTTONDBLCLK = &H203
  323.  
  324.        ''' <summary>
  325.        ''' Posted when the user presses the right mouse button while the cursor is in the client area of a window.
  326.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  327.        ''' Otherwise, the message is posted to the window that has captured the mouse
  328.        ''' </summary>
  329.        WM_RBUTTONDOWN = &H204
  330.  
  331.        ''' <summary>
  332.        ''' Posted when the user releases the right mouse button while the cursor is in the client area of a window.
  333.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  334.        ''' Otherwise, the message is posted to the window that has captured the mouse
  335.        ''' </summary>
  336.        WM_RBUTTONUP = &H205
  337.  
  338.        ''' <summary>
  339.        ''' Posted when the user double-clicks the right mouse button while the cursor is in the client area of a window.
  340.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  341.        ''' Otherwise, the message is posted to the window that has captured the mouse
  342.        ''' </summary>
  343.        WM_RBUTTONDBLCLK = &H206
  344.  
  345.        ''' <summary>
  346.        ''' Posted when the user presses the middle mouse button while the cursor is in the client area of a window.
  347.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  348.        ''' Otherwise, the message is posted to the window that has captured the mouse
  349.        ''' </summary>
  350.        WM_MBUTTONDOWN = &H207
  351.  
  352.        ''' <summary>
  353.        ''' Posted when the user releases the middle mouse button while the cursor is in the client area of a window.
  354.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  355.        ''' Otherwise, the message is posted to the window that has captured the mouse
  356.        ''' </summary>
  357.        WM_MBUTTONUP = &H208
  358.  
  359.        ''' <summary>
  360.        ''' Posted when the user double-clicks the middle mouse button while the cursor is in the client area of a window.
  361.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  362.        ''' Otherwise, the message is posted to the window that has captured the mouse
  363.        ''' </summary>
  364.        WM_MBUTTONDBLCLK = &H209
  365.  
  366.        ''' <summary>
  367.        ''' Sent to the active window when the mouse's horizontal scroll wheel is tilted or rotated.
  368.        ''' The DefWindowProc function propagates the message to the window's parent.
  369.        ''' There should be no internal forwarding of the message,
  370.        ''' since DefWindowProc propagates it up the parent chain until it finds a window that processes it.
  371.        ''' </summary>
  372.        WM_MOUSEWHEEL = &H20A
  373.  
  374.    End Enum
  375.  
  376.    ''' <summary>
  377.    ''' Indicates the whell direction of the mouse.
  378.    ''' </summary>
  379.    Public Enum WheelDirection
  380.  
  381.        ''' <summary>
  382.        ''' The wheel is moved up.
  383.        ''' </summary>
  384.        WheelUp
  385.  
  386.        ''' <summary>
  387.        ''' The wheel is moved down.
  388.        ''' </summary>
  389.        WheelDown
  390.  
  391.    End Enum
  392.  
  393. #End Region
  394.  
  395. #Region " Events "
  396.  
  397.    ''' <summary>
  398.    ''' Occurs when the mouse moves.
  399.    ''' </summary>
  400.    Public Event MouseMove(ByVal MouseLocation As Point)
  401.  
  402.    ''' <summary>
  403.    ''' Occurs when the mouse left button is pressed.
  404.    ''' </summary>
  405.    Public Event MouseLeftDown(ByVal MouseLocation As Point)
  406.  
  407.    ''' <summary>
  408.    ''' Occurs when the mouse left button is released.
  409.    ''' </summary>
  410.    Public Event MouseLeftUp(ByVal MouseLocation As Point)
  411.  
  412.    ''' <summary>
  413.    ''' Occurs when the mouse left button is double-clicked.
  414.    ''' </summary>
  415.    Public Event MouseLeftDoubleClick(ByVal MouseLocation As Point)
  416.  
  417.    ''' <summary>
  418.    ''' Occurs when the mouse right button is pressed.
  419.    ''' </summary>
  420.    Public Event MouseRightDown(ByVal MouseLocation As Point)
  421.  
  422.    ''' <summary>
  423.    ''' Occurs when the mouse right button is released.
  424.    ''' </summary>
  425.    Public Event MouseRightUp(ByVal MouseLocation As Point)
  426.  
  427.    ''' <summary>
  428.    ''' Occurs when the mouse right button is double-clicked.
  429.    ''' </summary>
  430.    Public Event MouseRightDoubleClick(ByVal MouseLocation As Point)
  431.  
  432.    ''' <summary>
  433.    ''' Occurs when the mouse middle button is pressed.
  434.    ''' </summary>
  435.    Public Event MouseMiddleDown(ByVal MouseLocation As Point)
  436.  
  437.    ''' <summary>
  438.    ''' Occurs when the mouse middle button is released.
  439.    ''' </summary>
  440.    Public Event MouseMiddleUp(ByVal MouseLocation As Point)
  441.  
  442.    ''' <summary>
  443.    ''' Occurs when the mouse middle button is double-clicked.
  444.    ''' </summary>
  445.    Public Event MouseMiddleDoubleClick(ByVal MouseLocation As Point)
  446.  
  447.    ''' <summary>
  448.    ''' Occurs when [mouse move].
  449.    ''' </summary>
  450.    Public Event MouseWheel(ByVal MouseLocation As Point,
  451.                            ByVal WheelDirection As WheelDirection)
  452.  
  453. #End Region
  454.  
  455. #Region " Constructors "
  456.  
  457.    ''' <summary>
  458.    ''' Initializes a new instance of this class.
  459.    ''' </summary>
  460.    Public Sub New()
  461.  
  462.        MouseHookDelegate = New MouseProcDelegate(AddressOf MouseProc)
  463.  
  464.        MouseHook = SetWindowsHookEx(HookType.WH_MOUSE_LL,
  465.                                     MouseHookDelegate,
  466.                                     Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
  467.    End Sub
  468.  
  469. #End Region
  470.  
  471. #Region " Protected Methods "
  472.  
  473.    ''' <summary>
  474.    ''' Allows an object to try to free resources
  475.    ''' and perform other cleanup operations before it is reclaimed by garbage collection.
  476.    ''' </summary>
  477.    Protected Overrides Sub Finalize()
  478.  
  479.        UnhookWindowsHookEx(MouseHook)
  480.        MyBase.Finalize()
  481.  
  482.    End Sub
  483.  
  484. #End Region
  485.  
  486. #Region " Private Methods "
  487.  
  488.    ''' <summary>
  489.    ''' Processes the mouse windows messages and raises it's corresponding events.
  490.    ''' </summary>
  491.    ''' <returns>System.Int32.</returns>
  492.    Private Function MouseProc(ByVal nCode As Integer,
  493.                               ByVal wParam As Integer,
  494.                               ByRef lParam As MSLLHOOKSTRUCT
  495.    ) As Integer
  496.  
  497.        If nCode = 0 Then
  498.  
  499.            Select Case wParam
  500.  
  501.                Case MouseWindowsMessages.WM_MOUSEMOVE
  502.                    RaiseEvent MouseMove(lParam.pt)
  503.  
  504.                Case MouseWindowsMessages.WM_LBUTTONDOWN
  505.                    RaiseEvent MouseLeftDown(lParam.pt)
  506.  
  507.                Case MouseWindowsMessages.WM_LBUTTONUP
  508.                    RaiseEvent MouseLeftUp(lParam.pt)
  509.  
  510.                Case MouseWindowsMessages.WM_LBUTTONDBLCLK
  511.                    RaiseEvent MouseLeftDoubleClick(lParam.pt)
  512.  
  513.                Case MouseWindowsMessages.WM_RBUTTONDOWN
  514.                    RaiseEvent MouseRightDown(lParam.pt)
  515.  
  516.                Case MouseWindowsMessages.WM_RBUTTONUP
  517.                    RaiseEvent MouseRightUp(lParam.pt)
  518.  
  519.                Case MouseWindowsMessages.WM_RBUTTONDBLCLK
  520.                    RaiseEvent MouseRightDoubleClick(lParam.pt)
  521.  
  522.                Case MouseWindowsMessages.WM_MBUTTONDOWN
  523.                    RaiseEvent MouseMiddleDown(lParam.pt)
  524.  
  525.                Case MouseWindowsMessages.WM_MBUTTONUP
  526.                    RaiseEvent MouseMiddleUp(lParam.pt)
  527.  
  528.                Case MouseWindowsMessages.WM_MBUTTONDBLCLK
  529.                    RaiseEvent MouseMiddleDoubleClick(lParam.pt)
  530.  
  531.                Case MouseWindowsMessages.WM_MOUSEWHEEL
  532.                    Dim wDirection As WheelDirection
  533.                    If lParam.mouseData < 0 Then
  534.                        wDirection = WheelDirection.WheelDown
  535.                    Else
  536.                        wDirection = WheelDirection.WheelUp
  537.                    End If
  538.                    RaiseEvent MouseWheel(lParam.pt, wDirection)
  539.  
  540.            End Select
  541.  
  542.        End If
  543.  
  544.        Return CallNextHookEx(MouseHook, nCode, wParam, lParam)
  545.  
  546.    End Function
  547.  
  548. #End Region
  549.  
  550. End Class
  551.  
  552. #End Region
7062  Programación / .NET (C#, VB.NET, ASP) / [APORTE] Screen-Region Selector (para capturadores de pantalla) en: 28 Junio 2014, 08:06 am
Hola

Desarrollé este Snippet para que dibuja una forma cuadrada/rectangular sobre la pantalla para seleccionar un área de la imagen en movimiento, y devuelve los datos de la estructura del rectángulo seleccionado para, posteriormente, poder capturar esa región de la imagen.

Hay 2 formas (que yo sepa al menos) de llevar esto a cabo, una es "congelando" la imagen, y la otra es en tiempo real, yo opté por la segunda opción, a pesar de ser mucho más complicada es lo que se adaptaba a mis necesidades.

Espero que puedan sacar algo de provecho en este código.

Código
  1. ' ***********************************************************************
  2. ' Author           : Elektro
  3. ' Last Modified On : 06-03-2014
  4. ' ***********************************************************************
  5. ' <copyright file="RegionSelector.vb" company="Elektro Studios">
  6. '     Copyright (c) Elektro Studios. All rights reserved.
  7. ' </copyright>
  8. ' ***********************************************************************
  9.  
  10. #Region " Usage Examples "
  11.  
  12. 'Public Class Form1
  13.  
  14. '    Dim SelectedRegion As Rectangle = Rectangle.Empty
  15. '    Dim RegionSelectorIsWorking As Boolean = False
  16.  
  17. '    Private Sub Button_Click() Handles Button1.Click
  18. '        GetScreenRegion()
  19. '    End Sub
  20.  
  21. '    Public Sub GetScreenRegion()
  22.  
  23. '        Dim Callback As RegionSelector.RegionSelectedDelegate
  24.  
  25. '        Dim Selector As New RegionSelector(BorderColor:=Color.YellowGreen,
  26. '                                           BorderSize:=3,
  27. '                                           backgroundcolor:=Color.YellowGreen,
  28. '                                           BackgroundOpacity:=0.06R)
  29.  
  30. '        Select Case RegionSelectorIsWorking
  31.  
  32. '            Case True ' Only one selection at once!
  33. '                Exit Sub
  34.  
  35. '            Case Else
  36. '                RegionSelectorIsWorking = True
  37. '                Callback = New RegionSelector.RegionSelectedDelegate(AddressOf SelectionFinished)
  38.  
  39. '                With Selector
  40. '                    .Callback = Callback
  41. '                    .Show()
  42. '                End With
  43.  
  44. '        End Select
  45.  
  46. '        ' Don't do any stuff here... do it in Rectangle Drawn...
  47.  
  48. '    End Sub
  49.  
  50. '    Private Sub SelectionFinished(ByVal Region As Rectangle)
  51.  
  52. '        RegionSelectorIsWorking = False ' Allow draw again.
  53. '        Me.SelectedRegion = Region
  54.  
  55. '        Dim sb As New System.Text.StringBuilder
  56. '        With sb
  57. '            .AppendLine("Selected Area")
  58. '            .AppendLine()
  59. '            .AppendLine("· Size")
  60. '            .AppendLine(String.Format("Width: {0}", CStr(SelectedRegion.Width)))
  61. '            .AppendLine(String.Format("Height: {0}", CStr(SelectedRegion.Height)))
  62. '            .AppendLine()
  63. '            .AppendLine("· Coordinates")
  64. '            .AppendLine(String.Format("Top: {0}", CStr(SelectedRegion.Top)))
  65. '            .AppendLine(String.Format("Left: {0}", CStr(SelectedRegion.Left)))
  66. '            .AppendLine(String.Format("Right: {0}", CStr(SelectedRegion.Right)))
  67. '            .AppendLine(String.Format("Bottom: {0}", CStr(SelectedRegion.Bottom)))
  68. '            .AppendLine()
  69. '        End With
  70.  
  71. '        MessageBox.Show(sb.ToString)
  72.  
  73. '    End Sub
  74.  
  75. 'End Class
  76.  
  77. #End Region
  78.  
  79. ''' <summary>
  80. ''' Selects a region on the Screen.
  81. ''' </summary>
  82. Public NotInheritable Class RegionSelector : Inherits Form
  83.  
  84. #Region " Delegates "
  85.  
  86.    ''' <summary>
  87.    ''' Delegate RegionSelectedDelegate.
  88.    ''' </summary>
  89.    ''' <param name="Region">The region.</param>
  90.    Public Delegate Sub RegionSelectedDelegate(ByVal Region As Rectangle)
  91.  
  92. #End Region
  93.  
  94. #Region " Properties "
  95.  
  96.    ''' <summary>
  97.    ''' Callback to be invoked when drawing is done...
  98.    ''' </summary>
  99.    ''' <value>Delegate of Region Selected</value>
  100.    Public Property Callback As RegionSelectedDelegate = Nothing
  101.  
  102.    ''' <summary>
  103.    ''' Gets or sets the border size of the region selector.
  104.    ''' </summary>
  105.    ''' <value>The size of the border.</value>
  106.    Public Property BorderSize As Integer = 2
  107.  
  108.    ''' <summary>
  109.    ''' Gets or sets the border color of the region selector.
  110.    ''' </summary>
  111.    ''' <value>The color of the border.</value>
  112.    Public Property BorderColor As Color = Color.Red
  113.  
  114.    ''' <summary>
  115.    ''' Gets or sets the background color of the region selector.
  116.    ''' </summary>
  117.    ''' <value>The color of the border.</value>
  118.    Public Property BackgroundColor As Color = Color.RoyalBlue
  119.  
  120.    ''' <summary>
  121.    ''' Gets or sets the background opacity of the region selector.
  122.    ''' </summary>
  123.    ''' <value>The color of the border.</value>
  124.    Public Property BackgroundOpacity As Double = 0.08R
  125.  
  126.    ''' <summary>
  127.    ''' Gets the rectangle that contains the selected region.
  128.    ''' </summary>
  129.    Public ReadOnly Property SelectedRegion As Rectangle
  130.        Get
  131.            Return Me.DrawRect
  132.        End Get
  133.    End Property
  134.  
  135. #End Region
  136.  
  137. #Region " Objects "
  138.  
  139.    ''' <summary>
  140.    ''' Indicates the initial location when the mouse left button is clicked.
  141.    ''' </summary>
  142.    Private InitialLocation As Point = Point.Empty
  143.  
  144.    ''' <summary>
  145.    ''' The rectangle where to draw the region.
  146.    ''' </summary>
  147.    Public DrawRect As Rectangle = Rectangle.Empty
  148.  
  149.    ''' <summary>
  150.    ''' The Graphics object to draw on the screen.
  151.    ''' </summary>
  152.    Private ScreenGraphic As Graphics = Graphics.FromHwnd(IntPtr.Zero)
  153.  
  154.    ''' <summary>
  155.    ''' Indicates the Rectangle Size.
  156.    ''' </summary>
  157.    Dim DrawSize As Size
  158.  
  159.    ''' <summary>
  160.    ''' Indicates the draw form.
  161.    ''' </summary>
  162.    Dim DrawForm As Form
  163.  
  164.    ''' <summary>
  165.    ''' Indicates whether the RegionSelector is busy drawing the rectangle.
  166.    ''' </summary>
  167.    Public IsDrawing As Boolean = False
  168.  
  169. #End Region
  170.  
  171. #Region " Constructors "
  172.  
  173.    ''' <summary>
  174.    ''' Initializes a new instance of the <see cref="RegionSelector"/> class.
  175.    ''' </summary>
  176.    Public Sub New()
  177.    End Sub
  178.  
  179.    ''' <summary>
  180.    ''' Initializes a new instance of the <see cref="RegionSelector" /> class.
  181.    ''' </summary>
  182.    ''' <param name="BorderColor">Indicates the border color of the region selector.</param>
  183.    ''' <param name="BorderSize">Indicates the border size of the region selector.</param>
  184.    ''' <param name="BackgroundColor">Indicates the background color of the region selector.</param>
  185.    ''' <param name="BackgroundOpacity">Indicates the background opacity size of the region selector.</param>
  186.    Public Sub New(Optional ByVal BorderColor As Color = Nothing,
  187.                   Optional ByVal BorderSize As Integer = 2,
  188.                   Optional ByVal BackgroundColor As Color = Nothing,
  189.                   Optional ByVal BackgroundOpacity As Double = 0.1R)
  190.  
  191.        If BorderColor = Nothing _
  192.        OrElse BorderColor = Color.Transparent Then
  193.            BorderColor = Color.Red
  194.        End If
  195.  
  196.        If BackgroundColor = Nothing _
  197.        OrElse BackgroundColor = Color.Transparent Then
  198.            BackgroundColor = Color.Black
  199.        End If
  200.  
  201.        Me.BorderSize = BorderSize
  202.        Me.BorderColor = BorderColor
  203.        Me.BackgroundOpacity = BackgroundOpacity
  204.        Me.BackgroundColor = BackgroundColor
  205.  
  206.    End Sub
  207.  
  208. #End Region
  209.  
  210. #Region " Event Handlers "
  211.  
  212.    ''' <summary>
  213.    ''' Handles the Load event of the RegionSelector.
  214.    ''' </summary>
  215.    ''' <param name="sender">The source of the event.</param>
  216.    ''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  217.    Private Sub RegionSelector_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
  218.  
  219.        Me.SuspendLayout()
  220.  
  221.        Me.AutoScaleMode = AutoScaleMode.None
  222.        Me.BackColor = Me.BackgroundColor
  223.        Me.BackgroundImageLayout = ImageLayout.None
  224.        Me.CausesValidation = False
  225.        Me.ClientSize = New Size(0, 0)
  226.        Me.ControlBox = False
  227.        Me.Cursor = Cursors.Cross
  228.        Me.DoubleBuffered = True
  229.        Me.FormBorderStyle = FormBorderStyle.None
  230.        Me.MaximizeBox = False
  231.        Me.MinimizeBox = False
  232.        Me.Name = "RegionSelector"
  233.        Me.Opacity = Me.BackgroundOpacity
  234.        Me.ShowIcon = False
  235.        Me.ShowInTaskbar = False
  236.        Me.SizeGripStyle = SizeGripStyle.Hide
  237.        Me.StartPosition = FormStartPosition.CenterScreen
  238.        Me.TopMost = False
  239.        Me.WindowState = FormWindowState.Maximized
  240.  
  241.        Me.ResumeLayout(False)
  242.  
  243.        Me.DrawForm = New DrawingRegionClass(Me)
  244.        With DrawForm
  245.            .AutoScaleMode = AutoScaleMode.None
  246.            .BackColor = Color.Tomato
  247.            .BackgroundImageLayout = ImageLayout.None
  248.            .ControlBox = False
  249.            .FormBorderStyle = FormBorderStyle.None
  250.            .MaximizeBox = False
  251.            .MinimizeBox = False
  252.            .ShowIcon = False
  253.            .ShowInTaskbar = False
  254.            .SizeGripStyle = SizeGripStyle.Hide
  255.            .StartPosition = FormStartPosition.CenterScreen
  256.            .TopLevel = True
  257.            .TopMost = True
  258.            .TransparencyKey = Color.Tomato
  259.            .WindowState = FormWindowState.Maximized
  260.        End With
  261.  
  262.        Me.AddOwnedForm(Me.DrawForm)
  263.        Me.DrawForm.Show()
  264.  
  265.    End Sub
  266.  
  267.    ''' <summary>
  268.    ''' Raises the <see cref="E:System.Windows.Forms.Control.MouseDown" /> event.
  269.    ''' </summary>
  270.    ''' <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.</param>
  271.    Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  272.  
  273.        If e.Button = MouseButtons.Left Then
  274.            Me.InitialLocation = e.Location
  275.            Me.IsDrawing = True
  276.        End If
  277.  
  278.    End Sub
  279.  
  280.    ''' <summary>
  281.    ''' Raises the <see cref="E:System.Windows.Forms.Control.MouseUp" /> event.
  282.    ''' </summary>
  283.    ''' <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.</param>
  284.    Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  285.  
  286.        Me.IsDrawing = False
  287.        Callback.Invoke(SelectedRegion)
  288.        Me.Close() ' Must be called last.
  289.  
  290.    End Sub
  291.  
  292.    ''' <summary>
  293.    ''' Raises the <see cref="E:System.Windows.Forms.Control.MouseMove" /> event.
  294.    ''' </summary>
  295.    ''' <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.</param>
  296.    Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  297.  
  298.        If Me.IsDrawing Then
  299.  
  300.            Me.DrawSize = New Size(e.X - Me.InitialLocation.X, e.Y - Me.InitialLocation.Y)
  301.            Me.DrawRect = New Rectangle(Me.InitialLocation, Me.DrawSize)
  302.  
  303.            If Me.DrawRect.Height < 0 Then
  304.                Me.DrawRect.Height = Math.Abs(Me.DrawRect.Height)
  305.                Me.DrawRect.Y -= Me.DrawRect.Height
  306.            End If
  307.  
  308.            If Me.DrawRect.Width < 0 Then
  309.                Me.DrawRect.Width = Math.Abs(Me.DrawRect.Width)
  310.                Me.DrawRect.X -= Me.DrawRect.Width
  311.            End If
  312.  
  313.            Me.DrawForm.Invalidate()
  314.  
  315.        End If
  316.  
  317.    End Sub
  318.  
  319. #End Region
  320.  
  321. End Class
  322.  
  323. ''' <summary>
  324. ''' Class DrawingRegionClass. This class cannot be inherited.
  325. ''' </summary>
  326. Friend NotInheritable Class DrawingRegionClass : Inherits Form
  327.  
  328.    Private DrawParent As RegionSelector
  329.  
  330.    Public Sub New(ByVal Parent As Form)
  331.  
  332.        Me.DrawParent = Parent
  333.  
  334.    End Sub
  335.  
  336.    Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
  337.  
  338.        Dim Bg As Bitmap
  339.        Dim Canvas As Graphics
  340.  
  341.        If Me.DrawParent.IsDrawing Then
  342.  
  343.            Bg = New Bitmap(Width, Height)
  344.            Canvas = Graphics.FromImage(Bg)
  345.            Canvas.Clear(Color.Tomato)
  346.  
  347.            Using pen As New Pen(Me.DrawParent.BorderColor, Me.DrawParent.BorderSize)
  348.                Canvas.DrawRectangle(pen, Me.DrawParent.DrawRect)
  349.            End Using
  350.  
  351.            Canvas.Dispose()
  352.            e.Graphics.DrawImage(Bg, 0, 0, Width, Height)
  353.            Bg.Dispose()
  354.  
  355.        Else
  356.            MyBase.OnPaintBackground(e)
  357.        End If
  358.  
  359.    End Sub
  360.  
  361. End Class


Complemento adicional:

Código
  1.    ' Take Region ScreenShot
  2.    ' ( By Elektro )
  3.    '
  4.    ' Usage Examples :
  5.    '
  6.    ' Dim RegionScreenShot As Bitmap = TakeRegionScreenShot(New Point(0, 0), New Size(256, 256))
  7.    ' Dim RegionScreenShot As Bitmap = TakeRegionScreenShot(New Rectangle With {.Location = Point.Empty, .Size = New Size(256, 256)})
  8.    ' PictureBox1.BackgroundImage = RegionScreenShot
  9.    ' RegionScreenShot.Save("C:\RegionScreenShot.png", Imaging.ImageFormat.Png)
  10.    '
  11.    ''' <summary>
  12.    ''' Takes an image screenshot of an specific screen region.
  13.    ''' </summary>
  14.    ''' <param name="Coordinates">
  15.    ''' The X-coordinate is the point at the upper-left corner of the region.
  16.    ''' The Y-coordinate is the point at the upper-left corner of the region.
  17.    ''' </param>
  18.    ''' <param name="Size">Indicates the size of the area to be transferred.</param>
  19.    ''' <param name="PixelFormat">Indicates the Bitmap pixel format.</param>
  20.    ''' <returns>Bitmap.</returns>
  21.    Private Function TakeRegionScreenShot(ByVal Coordinates As Point,
  22.                                          ByVal [Size] As Size,
  23.                                          Optional ByVal [PixelFormat] As Imaging.PixelFormat =
  24.                                                                          Imaging.PixelFormat.Format24bppRgb) As Bitmap
  25.  
  26.        Using ScreenImage As New Bitmap([Size].Width, [Size].Height, [PixelFormat])
  27.  
  28.            Using ScreenGraphics As Graphics = Graphics.FromImage(ScreenImage)
  29.  
  30.                ScreenGraphics.CopyFromScreen(Coordinates, Point.Empty, ScreenImage.Size)
  31.  
  32.            End Using ' ScreenGraphics
  33.  
  34.            Return CType(ScreenImage.Clone, Bitmap)
  35.  
  36.        End Using ' ScreenImage
  37.  
  38.    End Function
  39.  
  40.    ''' <summary>
  41.    ''' Takes an image screenshot of an specific screen region.
  42.    ''' </summary>
  43.    ''' <param name="Region">Indicates a Rectangle structure that contains the region coordinates and the size.</param>
  44.    ''' <param name="PixelFormat">Indicates the Bitmap pixel format.</param>
  45.    ''' <returns>Bitmap.</returns>
  46.    Private Function TakeRegionScreenShot(ByVal [Region] As Rectangle,
  47.                                          Optional ByVal [PixelFormat] As Imaging.PixelFormat =
  48.                                                                          Imaging.PixelFormat.Format24bppRgb) As Bitmap
  49.  
  50.        Return TakeRegionScreenShot([Region].Location, [Region].Size, [PixelFormat])
  51.  
  52.    End Function
7063  Programación / .NET (C#, VB.NET, ASP) / [APORTE] Contar agrupaciones "()[]" en un String, obtener indices, y más... en: 28 Junio 2014, 07:57 am
Bueno pues empecé haciendo un código muy sencillo (quiero decir, muy pequeño) y acabé expandiendo su funcionalidad...

Se trata de una función que cuenta los caracteres de agrupación dentro de un String, comprueba si hay agrupaciones abiertas o vacias, y la cantidad de agrupaciones abiertas y cerradas hay, y obtiene sus índices de posición en el string, la función devuelve todos estos datos gracias a una Class personalizado para la ocasión.

No es gran cosa, simplemente quise compartirlo.

Espero que a alguien le ayude.

Código
  1.    ' Count Agrupations In String
  2.    ' // By Elektro
  3.    '
  4.    ' Example Usages :
  5.    '
  6.    'Private Sub Test()
  7.    '
  8.    '    Dim InputStrings As String() =
  9.    '        {
  10.    '            "(This) is (good)",
  11.    '            "This (is (good))",
  12.    '            "This is good",
  13.    '            "This is (bad))",
  14.    '            "This is (bad",
  15.    '            "This is bad)",
  16.    '            "This is bad)("
  17.    '        }
  18.    '
  19.    '    Dim AgrupationChars As New Tuple(Of Char, Char)("(", ")")
  20.    '
  21.    '    For Each InputString As String In InputStrings
  22.    '
  23.    '        Dim Info As AgrupationCharsInfo = Me.CountAgrupationsInString(AgrupationChars, InputString)
  24.    '
  25.    '        Dim sb As New System.Text.StringBuilder
  26.    '
  27.    '        With sb
  28.    '
  29.    '            .AppendLine(String.Format("Input String: {0}", Info.InputString))
  30.    '            .AppendLine(String.Format("Agrupation Characters: {0}{1}", Info.AgrupationChars.Item1,
  31.    '                                                                       Info.AgrupationChars.Item2))
  32.    '
  33.    '            .AppendLine()
  34.    '            .AppendLine(String.Format("String has closed agrupations?: {0}", Info.StringHasClosedAgrupations))
  35.    '            .AppendLine(String.Format("String has opened agrupations?: {0}", Info.StringHasOpenedAgrupations))
  36.    '
  37.    '            .AppendLine()
  38.    '            .AppendLine(String.Format("Closed Agrupations Count: {0}", Info.CountClosedAgrupations))
  39.    '            .AppendLine(String.Format("Opened Agrupations Count: {0}", Info.CountOpenedAgrupations))
  40.    '
  41.    '            .AppendLine()
  42.    '            .AppendLine("Closed Agrupations Indexes:")
  43.    '            For Each Item As Tuple(Of Integer, Integer) In Info.ClosedAgrupationsIndex
  44.    '                .AppendLine(String.Format("Start: {0}, End: {1}",
  45.    '                                          CStr(Item.Item1), CStr(Item.Item2)))
  46.    '            Next Item
  47.    '
  48.    '            .AppendLine()
  49.    '            .AppendLine(String.Format("Opened Agrupations Indexes: {0}",
  50.    '                                      String.Join(", ", Info.OpenedAgrupationsIndex)))
  51.    '
  52.    '        End With '/ sb
  53.    '
  54.    '        MessageBox.Show(sb.ToString, "Agrupations Information",
  55.    '                        MessageBoxButtons.OK, MessageBoxIcon.Information)
  56.    '
  57.    '    Next InputString
  58.    '
  59.    'End Sub
  60.  
  61.    ''' <summary>
  62.    ''' Retrieves info about the closed and opened agrupation characters inside a String.
  63.    ''' </summary>
  64.    ''' <param name="AgrupationChars">Indicates the characters to determine agrupations.</param>
  65.    ''' <param name="InputString">Indicates the string where to count the agrupations.</param>
  66.    ''' <returns>AgrupationCharsInfo.</returns>
  67.    ''' <exception cref="System.Exception">'InputString' parameter cannot be an empty String..</exception>
  68.    Public Function CountAgrupationsInString(ByVal AgrupationChars As Tuple(Of Char, Char),
  69.                                             ByVal InputString As String) As AgrupationCharsInfo
  70.  
  71.        If String.IsNullOrEmpty(InputString) OrElse String.IsNullOrWhiteSpace(InputString) Then
  72.            Throw New Exception("'InputString' parameter cannot be an empty String.")
  73.        End If
  74.  
  75.        Dim CharStack As New Stack(Of Integer)
  76.        Dim Result As New AgrupationCharsInfo
  77.  
  78.        With Result
  79.  
  80.            .InputString = InputString
  81.            .AgrupationChars = New Tuple(Of Char, Char)(AgrupationChars.Item1, AgrupationChars.Item2)
  82.  
  83.            For i As Integer = 0 To InputString.Length - 1
  84.  
  85.                Select Case InputString(i)
  86.  
  87.                    Case .AgrupationChars.Item1
  88.                        CharStack.Push(i)
  89.                        .OpenedAgrupationsIndex.Add(i)
  90.                        .CountOpenedAgrupations += 1
  91.  
  92.                    Case .AgrupationChars.Item2
  93.                        Select Case CharStack.Count
  94.  
  95.                            Case Is = 0
  96.                                .CountOpenedAgrupations += 1
  97.                                .OpenedAgrupationsIndex.Add(i)
  98.  
  99.                            Case Else
  100.                                .CountClosedAgrupations += 1
  101.                                .CountOpenedAgrupations -= 1
  102.                                .ClosedAgrupationsIndex.Add(Tuple.Create(Of Integer, Integer)(CharStack.Pop, i))
  103.                                .OpenedAgrupationsIndex.RemoveAt(.OpenedAgrupationsIndex.Count - 1)
  104.  
  105.                        End Select '/ CharStack.Count
  106.  
  107.                End Select '/ InputString(i)
  108.  
  109.            Next i
  110.  
  111.            .StringHasClosedAgrupations = .CountClosedAgrupations <> 0
  112.            .StringHasOpenedAgrupations = .CountOpenedAgrupations <> 0
  113.  
  114.        End With '/ Result
  115.  
  116.        Return Result
  117.  
  118.    End Function
  119.  
  120.    ''' <summary>
  121.    ''' Stores info about closed and opened agrupations of chars in a String.
  122.    ''' </summary>
  123.    Public NotInheritable Class AgrupationCharsInfo
  124.  
  125.        ''' <summary>
  126.        ''' Indicates the input string.
  127.        ''' </summary>
  128.        ''' <value>The input string.</value>
  129.        Public Property InputString As String = String.Empty
  130.  
  131.        ''' <summary>
  132.        ''' Indicates the agrupation characters.
  133.        ''' </summary>
  134.        ''' <value>The agrupation characters.</value>
  135.        Public Property AgrupationChars As Tuple(Of Char, Char) = Nothing
  136.  
  137.        ''' <summary>
  138.        ''' Determines whether the input string contains closed agrupation.
  139.        ''' </summary>
  140.        Public Property StringHasClosedAgrupations As Boolean = False
  141.  
  142.        ''' <summary>
  143.        ''' Determines whether the input string contains opened agrupations.
  144.        ''' </summary>
  145.        Public Property StringHasOpenedAgrupations As Boolean = False
  146.  
  147.        ''' <summary>
  148.        ''' Indicates the total amount of closed agrupations.
  149.        ''' </summary>
  150.        ''' <value>The closed agrupations count.</value>
  151.        Public Property CountClosedAgrupations As Integer = 0
  152.  
  153.        ''' <summary>
  154.        ''' Indicates the total amount of opened agrupations.
  155.        ''' </summary>
  156.        ''' <value>The opened agrupations count.</value>
  157.        Public Property CountOpenedAgrupations As Integer = 0
  158.  
  159.        ''' <summary>
  160.        ''' Indicates the closed agrupations index positions in the string.
  161.        ''' </summary>
  162.        ''' <value>The closed agrupations index positions.</value>
  163.        Public Property ClosedAgrupationsIndex As New List(Of Tuple(Of Integer, Integer))
  164.  
  165.        ''' <summary>
  166.        ''' Indicates the opened agrupations index positions in the string.
  167.        ''' </summary>
  168.        ''' <value>The opened agrupations index positions.</value>
  169.        Public Property OpenedAgrupationsIndex As New List(Of Integer)
  170.  
  171.    End Class '/ AgrupationCharsInfo
  172.  
7064  Programación / Scripting / Re: Crear un .bat que ponga la barra de herramientas en su posición normal. en: 28 Junio 2014, 07:42 am
Pues no pides ni nada, @Jeny, has ido a elegir el lenguaje más simple para una tarea que requiere el manejo de la WinAPI.

Si tienes conocimientos de VB/VB.NET no te debería resultar muy compleja la tarea (lo único con algo de dificultad sería documentarse en MSDN sobre el manejo de las funciones, y las constantes que sean necesarias utilizar), un ejemplo que puede servir: http://www.codeguru.com/vb/gen/vb_general/miscellaneous/article.php/c15757/The-TaskBar-and-VBNET.htm

Saludos.
7065  Programación / Scripting / Re: Ayuda Código CMD- USB Stealer en: 28 Junio 2014, 07:32 am
Podrías sacar algunas ideas productivas de aquí:



[BATCH] [APORTE] USB MON (Roba USB)

PD: Pero opino lo mismo que ya te comentaron, deberías utilizar un lenguaje de verdad.

Saludos
7066  Programación / Scripting / Re: ayuda con archivos bat en: 28 Junio 2014, 07:16 am
Una aplicación GUI también puede terminar su ejecución enviando, de manera intencionada, un código de salida a la consola, y en ese caso se podrá leer ese código de retorno desde la CMD.

De todas formas yo intuyo que el proceso que quieres ejecutas es CLI, así que esto te servirá (en ese caso):

Código
  1. Start /W "" "a.exe"
  2. If %ErrorLevel% Neq 0 (
  3.   :: Error detectado, abrir la imagen del error aquí.
  4. )

Saludos
7067  Programación / .NET (C#, VB.NET, ASP) / Re: Arraste de raton en aplicacion externa en: 28 Junio 2014, 07:06 am
vale, y yo no entendia tu último comentario donde insinuabas que me burlaba de los nuevos y que estaba mintiendo sobre la existencia de dicha función, no sabía si también era sarcasmo... pero ahora al haber explicado el malentendido creo que entiendo porque lo dijiste.

PD: Le puse la "s" sin querer (costumbre) xD.

Aquí no ha pasado nada,
Saludos.
7068  Programación / .NET (C#, VB.NET, ASP) / Re: Arraste de raton en aplicacion externa en: 28 Junio 2014, 06:56 am
en qué parte dice que la función "mouse_event()" de la API de Windows se ha quedado obsoleta.

-> mouse_event function (Windows) - MSDN - Microsoft

Citar
Note: This function has been superseded.
Use SendInput instead
.

Por si no ha quedado claro lo que pone en Inglés, una traducción:
Citar
Nota: Esta función se ha sustituido.
Utilice SendInput en su lugar
.

En ningún momento he dicho más haya de la realidad, no he dicho que no sea compatible, ni nada, el sarcasmo sobra...

Saludos.
7069  Programación / .NET (C#, VB.NET, ASP) / Re: Problema con instruccion en: 28 Junio 2014, 06:51 am
Pd: por lo que entiendo dice que tengo que convertir un double o string si no me equivoco pero no se como hacerlo.

No exactamente, el mensaje de error te indica que es imposible tratar un valor de tipo Double como si fuera de tipo String, y la solución sería realizar la conversión a String, pero en mi opinión no es un buen enfoque.

¿Si estás tratando valores numéricos, porque intentas almacenarlos como tipo String?, ¿y si estás usando valores de tipo Double, porque intentas tratarlos como Decimales (CDec)?

Quédate con un datatype (Double o Decimal) e intenta no realizar conversiones innecesarias.

Prueba así:
Código
  1. Dim Valores As Double() =
  2.    (From Valor As Double In listaelementos.Items Order By Valor Ascending).ToArray

Saludos.
7070  Programación / .NET (C#, VB.NET, ASP) / Re: [APORTE] Elektro ErrorDialog en: 28 Junio 2014, 06:36 am
Esta muy bien el programa Eleкtro, lo voi a usar en un proyecto que estoy usando.

Saludos y gracias por el aporte.

Gracias, si encuentras algún bug (no debería porque, pero nunca se sabe xD) te agradecería que me lo comunicases



por que el code tiene tanto comentario en ingles, no puede ir en español?
Porque me gusta y estoy acostumbrado a desarrollar en el idioma Universal, aunque eso no quiere decir que no me sienta orgulloso de mi idioma, el Castellano.
Eres libre de tomar el código y traducirlo al Castellano xD.

de donde obtenes esos codes?
¿A que códigos te refieres?, solo tomé ideas que me pudieran servir y las realizé desde cero dándoles (mi) otra perspectiva, pero de todas formas la fuente de esas ideas está explicado más arriba en el post.

de donde obtenes esos codes?
es como tener una segunda opinion en temas graves y que uno a veces no da con el error, me parece una idea genial y util.

Gracias

Saludos.
Páginas: 1 ... 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 [707] 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 ... 1236
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines