|
8722
|
Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets)
|
en: 23 Junio 2013, 01:21 am
|
Dim WithEvents temer As System.Windows.Forms.Timer 'Aquí se define el Timer dinámicamente que posteriormente será creado, cortesía de Elektro :)
¿cortesía mía?, ¿seguro?, que yo recuerde nunca te hablé de Timers xD, pero ya que estamos, voy con mi sugerencia... Fíjate aquí: Dim WithEvents temer As System.Windows.Forms.Timer 'Aquí se define el Timer dinámicamente que posteriormente será creado, cortesía de Elektro :) Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load temer = New System.Windows.Forms.Timer 'Aquí se crea finalmente temer.Interval = 15000 'Aquí los ms que tarda en comprobar si la app está updateada temer.Start() 'Aquí comienza a contar End Sub
Esa parte la puedes mejorar, y mucho. 1. Puedes declarar un objeto e instanciarlo al mismo tiempo con "New". 2. Además puedes modificar sus propiedades e inicializarlo (timer.start) con "With". 3. ...Todo en la misma línea, y así el Sub:"Form1_Load" sobraría complétamente. Aquí tienes: Public Class Form1 Dim WithEvents temer As New Timer With {.Interval = 15000, .Enabled = True} 'Ahora si que es cortesía de Elektro :) Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' Nothing to do here End Sub End Class
PD: Apréndete estas pequeñas cosas para ahorrar código. Saludos!
|
|
|
8727
|
Programación / .NET (C#, VB.NET, ASP) / Re: Crear PictureBox a través de una config .ini?
|
en: 22 Junio 2013, 20:36 pm
|
Referencia a objeto no establecida como instancia de un objeto. Traducción: El objeto no existe. Posible causa: Estás intentando llamar al panel cuando todavia no se ha creado/instanciado en la ventana del load. Me apuesto mi casa entera a que tienes ese código de los pcbs() en el form load, muevelo todo al evento shown, no al load. Saludos!
|
|
|
8728
|
Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets)
|
en: 22 Junio 2013, 20:28 pm
|
Obtener en WinAmp el título o la ruta del archivo de la canción actual. PD: Son códigos de VB6 que convertí a .NET (no todo...) con algo de ayuda. #Region " WinAmp Info" ' [ WinAmp Info ] ' ' // By Elektro H@cker ' ' Examples: ' MsgBox(WinAmp.Get_Title) ' Result: Artist - Title ' MsgBox(WinAmp.Get_FileName) ' Result: C:\Title.ext Public Class WinAmp Private Const WinampClassName As String = "Winamp v1.x" Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr Private Declare Auto Function GetWindowText Lib "user32" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Integer) As Integer Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, ByRef lpdwProcessId As Long) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByRef lpBuffer As Byte, ByVal nSize As Long, ByRef lpNumberOfBytesRead As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Public Shared Function Get_Title() As String Dim hwnd As IntPtr = FindWindow(WinampClassName, vbNullString) Dim lpText As String = String.Empty Dim strTitle As String = String.Empty Dim intLength As Integer = 0 Dim intName As Integer = 0 Dim intLeft As Integer = 0 Dim intRight As Integer = 0 Dim intDot As Integer = 0 If hwnd.Equals(IntPtr.Zero) Then Return "WinAmp is not running" lpText = New String(Chr(0), 100) intLength = GetWindowText(hwnd, lpText, lpText.Length) If (intLength <= 0) _ OrElse (intLength > lpText.Length) _ Then Return "Unknown" strTitle = lpText.Substring(0, intLength) intName = strTitle.IndexOf(" - Winamp") intLeft = strTitle.IndexOf("[") intRight = strTitle.IndexOf("]") If (intName >= 0) _ AndAlso (intLeft >= 0) _ AndAlso (intName < intLeft) _ AndAlso (intRight >= 0) _ AndAlso (intLeft + 1 < intRight) _ Then Return strTitle.Substring(intLeft + 1, intRight - intLeft - 1) If (strTitle.EndsWith(" - Winamp")) _ AndAlso (strTitle.Length > " - Winamp".Length) _ Then strTitle = strTitle.Substring(0, strTitle.Length - " - Winamp".Length) intDot = strTitle.IndexOf(".") If (intDot > 0) _ AndAlso (IsNumeric(strTitle.Substring(0, intDot))) _ Then strTitle = strTitle.Remove(0, intDot + 1) Return strTitle.Trim End Function Public Shared Function Get_FileName() As String Dim lp As Long, lpWinamp As Long, iIndex As Long, PID As Long, bRet As Long, dwRead As Long Dim Buffer(260) As Byte Dim hWndWinamp As IntPtr = FindWindow(WinampClassName, vbNullString) If hWndWinamp = 0 Then Return Nothing iIndex = SendMessage(hWndWinamp, &H400, 0, 125) lp = SendMessage(hWndWinamp, &H400, iIndex, 211) If lp = 0 Then Return Nothing Call GetWindowThreadProcessId(hWndWinamp, PID) lpWinamp = OpenProcess(&H10, 0, PID) If lpWinamp = 0 Then Return Nothing bRet = ReadProcessMemory(lpWinamp, lp, Buffer(0), 260, dwRead) Call CloseHandle(lpWinamp) Return System.Text.UnicodeEncoding.Default.GetString(Buffer) End Function End Class #End Region
|
|
|
|
|
|
|