|
Mostrar Mensajes
|
Páginas: [1] 2 3 4 5 6
|
1
|
Programación / .NET (C#, VB.NET, ASP) / Re: Obtener EXEpath de la ventana activa
|
en: 17 Abril 2023, 07:40 am
|
Creo que con el pedazo de código que tengo me puedo explicar mejor Imports System.Runtime.InteropServices Public Class Form1 Private WithEvents tmr As New Timer With {.Interval = 100, .Enabled = True} <DllImport("user32.dll")> Private Shared Function GetForegroundWindow() As IntPtr End Function Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub tmr_Tick(sender As Object, e As EventArgs) Handles tmr.Tick Dim hWnd As IntPtr = GetForegroundWindow() Text = hWnd 'Aquí necesito obtener la ruta de la aplicación que tiene la ventana activa 'usando el hWnd que me devuelve la API GetForegroundWindow 'o de alguna otra manera 'Lo importante es que se obtenga la ruta de la aplicación que tiene la ventana activa End Sub End Class
|
|
|
3
|
Programación / .NET (C#, VB.NET, ASP) / Re: Error Genérico en GDI+
|
en: 10 Abril 2023, 20:28 pm
|
Ya lo agregué, pero sigue el problema, por eso aquí comparto todo el código para que se vea mejor cual puede ser el problema Public Class Form1 Private WithEvents tmrRefresh As New Timer With {.Enabled = True, .Interval = 1} Private Sub tmrRefresh_Tick(sender As Object, e As EventArgs) Handles tmrRefresh.Tick Dim gr As Graphics Dim bmp As Bitmap = My.Resources.white Dim br As New SolidBrush(Color.Black) Dim free As String = AutoScaleSize(My.Computer.Info.AvailablePhysicalMemory, 2, False) Dim x() As String Dim por As Integer Dim colBar As Color Text = free x = Split(free) free = x(0) x = Split(free, ",") If Len(x(0)) = 1 Then x(0) = $"0{x(0)}" If Len(x(1)) = 1 Then x(1) = $"0{x(1)}" gr = Graphics.FromImage(bmp) gr.DrawString($"{x(0)},", New Font("Arial", 12, FontStyle.Bold), br, New PointF(0, 0)) gr.DrawString(x(1), New Font("Arial", 12, FontStyle.Bold), br, New PointF(0, 14)) por = Porciento(My.Computer.Info.AvailablePhysicalMemory, My.Computer.Info.TotalPhysicalMemory) Select Case por Case Is >= 75 : colBar = Color.Green Case Is >= 50 : colBar = Color.Yellow Case Is >= 25 : colBar = Color.Orange Case Is >= 0 : colBar = Color.Red End Select gr.DrawLine(New Pen(colBar, 5), 28, 2, 28, 30) Icon = ToIcon(bmp, 32, 32) bmp.Dispose() gr.Dispose() br.Dispose() End Sub End Class Module modExtras Public Function Porciento(Parte As ULong, Total As ULong, Optional Round As Boolean = False, Optional Decimals As Integer = 0) As Double Porciento = 0 Try Porciento = Parte * 100 / Total If Round Then Porciento = Math.Round(Porciento, Decimals) Catch ex As Exception End Try End Function Public Function ToIcon(Image As Image, Width As Integer, Height As Integer, Optional MakeTransparent As Boolean = False, Optional Transparent As Color = Nothing) As Icon ToIcon = Nothing 'Try If IsNothing(Transparent) Then Transparent = Color.White Dim thumb As Bitmap = CType(Image.GetThumbnailImage(Width, Height, Nothing, IntPtr.Zero), Bitmap) If MakeTransparent Then thumb.MakeTransparent(Transparent) ToIcon = Icon.FromHandle(thumb.GetHicon()) thumb.Dispose() Image.Dispose() 'Catch ex As Exception 'End Try End Function Public Function AutoScaleSize(Bytes As Decimal, Optional Decimals As Integer = 2, Optional FullName As Boolean = False, Optional BaseMil As Boolean = False) As String AutoScaleSize = "" Try Dim C As Integer Dim b As Decimal = Bytes Dim Div As Integer If BaseMil Then Div = 1000 Else Div = 1024 Do While b >= Div b /= Div C += 1 Loop b = Math.Round(b, Decimals) Select Case C Case 0 : If FullName Then Return b & " Bytes" Else Return b & " B" Case 1 : If FullName Then Return b & " KiloBytes" Else Return b & " KB" Case 2 : If FullName Then Return b & " MegaBytes" Else Return b & " MB" Case 3 : If FullName Then Return b & " GigaBytes" Else Return b & " GB" Case 4 : If FullName Then Return b & " TeraBytes" Else Return b & " TB" Case 5 : If FullName Then Return b & " PetaBytes" Else Return b & " PB" Case 6 : If FullName Then Return b & " ExaBytes" Else Return b & " EB" Case 7 : If FullName Then Return b & " ZettaBytes" Else Return b & " ZB" Case 8 : If FullName Then Return b & " YottaBytes" Else Return b & " YB" Case Else : If FullName Then Return Bytes & " Bytes" Else Return Bytes & " B" End Select Catch ex As Exception End Try End Function End Module
|
|
|
4
|
Programación / .NET (C#, VB.NET, ASP) / Error Genérico en GDI+
|
en: 9 Abril 2023, 08:22 am
|
Hola tengo esta función para convertir un bitmap a icono y en algunas ocasiones ocurre la excepción 'Error Genérico en GDI+' en la última línea, alguna idea de que pueda estar pasando Public Function ToIcon(Image As Image, Width As Integer, Height As Integer, Optional MakeTransparent As Boolean = False, Optional Transparent As Color = Nothing) As Icon ToIcon = Nothing If IsNothing(Transparent) Then Transparent = Color.White Dim thumb As Bitmap = CType(Image.GetThumbnailImage(Width, Height, Nothing, IntPtr.Zero), Bitmap) If MakeTransparent Then thumb.MakeTransparent(Transparent) ToIcon = Icon.FromHandle(thumb.GetHicon()) End Function
|
|
|
5
|
Programación / .NET (C#, VB.NET, ASP) / Agregar propiedades a lista de tareas
|
en: 19 Octubre 2022, 08:46 am
|
Lo que quiero saber es de que manera cuando se crea un control personalizado se puede colocar una propiedad del control en la lista de tareas del control, como lo hace por ejemplo el control PictureBox con la propiedad SizeMode o en el caso del TextBox lo hace con la propiedad MultiLine.
|
|
|
7
|
Programación / .NET (C#, VB.NET, ASP) / Re: Obtener número de serie de un disco físico (no volumen lógico)
|
en: 3 Febrero 2021, 18:28 pm
|
Buscando me he encontrado un código en vb6, pero me parece que no logró adaptarlo correctamente a vb.net, ya que me genera un error cuando se va a usar la api ZeroMemory Alguien que tenga alguna idea de que hay que corregir, ya que a mi no se me ocurre nada más Private Declare Auto Function CreateFile _ Lib "kernel32" Alias "CreateFileA" ( ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As IntPtr ) As Integer Private Declare Auto Function CloseHandle _ Lib "kernel32" ( ByVal hObject As IntPtr ) As Integer Private Declare Auto Function DeviceIoControl _ Lib "kernel32" ( ByVal hDevice As IntPtr, ByVal dwIoControlCode As Integer, <MarshalAs(UnmanagedType.AsAny)> lpInBuffer As Object, ByVal nInBufferSize As Integer, <MarshalAs(UnmanagedType.AsAny)> lpOutBuffer As Object, ByVal nOutBufferSize As Integer, lpBytesReturned As Integer, ByVal lpOverlapped As Integer ) As Integer Private Declare Auto Sub ZeroMemory _ Lib "kernel32" Alias "RtlZeroMemory" ( <MarshalAs(UnmanagedType.AsAny)> dest As Object, ByVal numBytes As Integer) 'Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Object, Source As Object, ByVal Length As Integer) Private Declare Auto Function GetLastError Lib "kernel32" () As Integer Private Const DFP_RECEIVE_DRIVE_DATA = &H7C088 Private Const FILE_SHARE_READ = &H1 Private Const FILE_SHARE_WRITE = &H2 Private Const GENERIC_READ = &H80000000 Private Const GENERIC_WRITE = &H40000000 Private Const OPEN_EXISTING = 3 Private Const CREATE_NEW = 1 Private Enum HDInfo HD_MODEL_NUMBER = 0 HD_SERIAL_NUMBER = 1 HD_FIRMWARE_REVISION = 2 End Enum Private Structure IDEREGS Public bFeaturesReg As Byte Public bSectorCountReg As Byte Public bSectorNumberReg As Byte Public bCylLowReg As Byte Public bCylHighReg As Byte Public bDriveHeadReg As Byte Public bCommandReg As Byte Public bReserved As Byte End Structure Private Structure SENDCMDINPARAMS Public cBufferSize As Integer Public irDriveRegs As IDEREGS Public bDriveNumber As Byte <VBFixedArray(1, 3)> Public bReserved() As Byte <VBFixedArray(1, 4)> Public dwReserved() As Integer End Structure Private Structure DRIVERSTATUS Public bDriveError As Byte Public bIDEStatus As Byte <VBFixedArray(1, 2)> Public bReserved() As Byte <VBFixedArray(1, 2)> Public dwReserved() As Integer End Structure Private Structure SENDCMDOUTPARAMS Public cBufferSize As Integer Public DStatus As DRIVERSTATUS <VBFixedArray(1, 512)> Public bBuffer() As Byte End Structure Private mvarCurrentDrive As Byte Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MsgBox(GetHDDInfo(0, "serial")) End End Sub Public Function GetHDDInfo(ByVal Number As Byte, ByVal Cmd As String) As String mvarCurrentDrive = Number Select Case LCase(Cmd) Case "model" : GetHDDInfo = CmnGetHDData(HDInfo.HD_MODEL_NUMBER) Case "serial" : GetHDDInfo = CmnGetHDData(HDInfo.HD_SERIAL_NUMBER) Case "firmware" : GetHDDInfo = CmnGetHDData(HDInfo.HD_FIRMWARE_REVISION) Case Else : GetHDDInfo = "" End Select End Function Private Function CmnGetHDData(hdi As HDInfo) As String Dim Bin As SENDCMDINPARAMS Dim Bout As SENDCMDOUTPARAMS Dim hdh As Long Dim br As Long Dim Ix As Long Dim hddfr As Long Dim hddln As Long Dim S As String Select Case hdi Case HDInfo.HD_MODEL_NUMBER hddfr = 55 hddln = 40 Case HDInfo.HD_SERIAL_NUMBER hddfr = 21 hddln = 20 Case HDInfo.HD_FIRMWARE_REVISION hddfr = 47 hddln = 8 Case Else : Err. Raise(10001, "Illegal HD Data type") End Select hdh = CreateFile("\\.\PhysicalDrive" & mvarCurrentDrive, GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ + FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0) If hdh = 0 Then Err. Raise(10003, , "Error on CreateFile") ZeroMemory(Bin, Len(Bin)) ZeroMemory(Bout, Len(Bout)) With Bin .bDriveNumber = mvarCurrentDrive .cBufferSize = 512 With .irDriveRegs If (mvarCurrentDrive And 1) Then .bDriveHeadReg = &HB0 Else .bDriveHeadReg = &HA0 End If .bCommandReg = &HEC .bSectorCountReg = 1 .bSectorNumberReg = 1 End With End With DeviceIoControl(hdh, DFP_RECEIVE_DRIVE_DATA, Bin, Len(Bin), Bout, Len(Bout), br, 0) S = "" For Ix = hddfr To hddfr + hddln - 1 Step 2 If Bout.bBuffer(Ix + 1) = 0 Then Exit For S &= Chr(Bout.bBuffer(Ix + 1)) If Bout.bBuffer(Ix) = 0 Then Exit For S &= Chr(Bout.bBuffer(Ix)) Next Ix CloseHandle(hdh) CmnGetHDData = Trim(S) End Function
|
|
|
9
|
Sistemas Operativos / Windows / Re: Papel Tapiz con carpeta de imágenes
|
en: 3 Febrero 2021, 04:28 am
|
Waooo, nunca se me hubiera ocurrido eso. Pero ese mecanismo solo empeora mi situación, ya que no obtengo la ruta de la imagen original, solo la de la copia que hace windows.
Lo que necesito es la ruta de la imagen original que ahora me parece más complejo de obtener
Gracias
|
|
|
10
|
Sistemas Operativos / Windows / Re: Papel Tapiz con carpeta de imágenes
|
en: 3 Febrero 2021, 00:32 am
|
Parece que no me explique bien, yo me refiero a que en el registro de Windows en la clave
HKEY_CURRENT_USER\Control Panel\Desktop
en el valor Wallpaper aparece la ruta completa de la imagen de papel tapiz actual.
El problema es que cuando pongo una carpeta de imágenes para que cambie el papel tapiz cada cierto tiempo lo que aparece en ese valor del registro es
C:\Users\Usuario\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper
Y de esta manera no puedo obtener la ruta de la imagen actual y quisiera saber si existe algún método para obtener la ruta en este caso
Gracias
|
|
|
|
|
|
|