Queria saber cual api o que metodo puedo usar para dibujar lineas "en el aire" es decir, fuera de la aplicación bv6, por ejemplo,que me mueva el mouse y se vaya creando una linea sobre el escritorio con todos los lugares por donde ha pasado el puntero desde que el programa esté activo... o simplemente, que me cree una linea rectade un pixel (x,y) que yo le indique a otro pixel indicado...
Draw on Desktop (http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=57100&lngWId=1)
este ejemplo puede servirte
http://foro.elhacker.net/programacion_vb/codigo_mini_graficador_quiza_sirva_de_algo_a_alguien-t164203.0.html;msg774955#msg774955
Saludos
Edito: En el text pones la distancia en pixeles y clic en el boton
.
Espero y te sirva esto que te hice:
Pegar en un formulario y agregar un TIMER
Option Explicit
' // GetSystemMetrics
Const SM_CXSCREEN = 0 'X Size of screen
Const SM_CYSCREEN = 1 'Y Size of Screen
' // CreatePen
Const PS_DOT = 2
Const PS_SOLID = 0
' // Apis
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As Any) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type tLineas
PuntoInicio As POINTAPI
PuntoFinal As POINTAPI
End Type
Dim RegionWindows As RECT
Dim hdcDestino As Long
Private Sub Form_Load()
Hide
' // Región/Resolución de Pantalla
With RegionWindows
.Bottom = GetSystemMetrics(SM_CYSCREEN)
.Left = 1
.Right = GetSystemMetrics(SM_CXSCREEN)
.Top = 1
End With
hdcDestino = GetDC(0)
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim Linea As tLineas
Dim hPen As Long
' // Dibujamos lineas al Azar
' // Calculamos el Punto de Inicio
Linea.PuntoInicio.x = NumeroAleatorio(RegionWindows.Left, RegionWindows.Right)
Linea.PuntoInicio.y = NumeroAleatorio(RegionWindows.Top, RegionWindows.Bottom)
' // Calculamos el Punto Final
Linea.PuntoFinal.x = NumeroAleatorio(RegionWindows.Left, RegionWindows.Right)
Linea.PuntoFinal.y = NumeroAleatorio(RegionWindows.Top, RegionWindows.Bottom)
' // Dibujamos la Linea
' // Dibujamos los puntos Inicio y Final en color rojo
' // Color de la Linea
hPen = CreatePen(PS_SOLID, 1, vbRed)
SelectObject hdcDestino, hPen
Ellipse hdcDestino, Linea.PuntoInicio.x - 2, Linea.PuntoInicio.y - 2, Linea.PuntoInicio.x + 2, Linea.PuntoInicio.y + 2
Ellipse hdcDestino, Linea.PuntoFinal.x - 2, Linea.PuntoFinal.y - 2, Linea.PuntoFinal.x + 2, Linea.PuntoFinal.y + 2
DeleteObject hPen
' // Color de la Linea
hPen = CreatePen(PS_SOLID, 1, (RGB(NumeroAleatorio(0, 255), NumeroAleatorio(0, 255), NumeroAleatorio(0, 255))))
SelectObject hdcDestino, hPen
' // Iniciamos una nueva Linea (Punto de Inicio)
MoveToEx hdcDestino, Linea.PuntoInicio.x, Linea.PuntoInicio.y, ByVal 0&
' // Finalizamos la Linea (Punto Final)
LineTo hdcDestino, Linea.PuntoFinal.x, Linea.PuntoFinal.y
DeleteObject hPen
End Sub
Public Function NumeroAleatorio(MinNum As Long, MaxNum As Long) As Long
Dim Tmp As Long
If MaxNum < MinNum Then: Tmp = MaxNum: MaxNum = MinNum: MinNum = Tmp
Randomize: NumeroAleatorio = CLng((MinNum - MaxNum + 1) * Rnd + MaxNum)
End Function
Temibles Lunas!¡.
.
Gracias por la ayuda a todos, el de BlackZero se apega mas a mis necesidades! :P
@░▒▓BlackZeroҖ▓▒░
esta bueno el ejemplo, te voy a tirar una sugerencia como ya me lo hicieron a mi en mi foro
(http://www.leandroascierto.com.ar/foro/index.php?topic=126.0)
al pasarle un lapiz a un hdc hay que eliminar el antiguo lapiz, esto es tanto como para un brocha, o un bitmap.
DeleteObject SelectObject(hdc, hPen)
y luego por ulitmo eliminas tu lapiz creado
DeleteObject hPen
.
En otras palabras a todo lo que se le haga SelectObject()
oo ya entonces si tenia que hacerlo haci (entonces mi deducción era cierta... pero me cai >:( ¬¬")
DeleteObject SelectObject(hdc, hPen)
ya lo tenia pero mmm medio vi algo raro y lo deje así (Por ello esta editado quien sabe cuantas veces el post de arriba xP)
SelectObject hdc, hPen
bla bla bla
DeleteObject hPen
Muchas gracias LeandroA.
Temibles Lunas!¡.
.