Excelente critica a McDonalds. Recomendado.
descargar
viernes, 20 de abril de 2007
miércoles, 18 de abril de 2007
COMO HACER UN PROTECTOR DE PANTALLAS EN VISUAL BASIC 6.0
La parte básica y la que todos saben es que un protector de pantallas es un ejecutable con extensión .scr; entonces para hacer un salvapantallas, hacer un ejecutable Standard en vb y le cambias la extensión. Luego lo instalas y ya está.
El formulario que se muestra, no debe tener bordes y estar maximizado, ese formulario
tendrá la animación que forma nuestro salvapantallas. Además en el evento mousemove
debe tener una sentencia que descargue el formulario.
Lo que viene de aquí en adelante no es complicado y aunque no estoy muy seguro de
hacerme entender, NO importa, porque al final les doy un modulo de clase que hace
todo el trabajo por nosotros.
Sin embargo pocas personas saben que los protectores de pantalla reciben parámetros
del sistema operativo que les indica su modo de ejecución:
/s modo normal (mostrar el screensaver)
/p modo preview (mostrar el screensaver en esa pantallita de propiedades de pantalla)
/c modo de configuración.
Teniendo esta información, son aun menos las personas que saben como colocar su
screensaver en esa pantallita de propiedades de pantalla. Pues les cuento que esto se
hace conociendo el hwnd (identificador de ventana, un número en hexadecimal) de la
ventanita en cuestión, y afortunadamente el hwnd es pasado en la línea de argumentos.
Diseñé un modulo de clase que nos ayuda con la tareita.
MODO DE USO DEL MODULO DE CLASE
Crearemos un modulo Standard desde donde iniciara el protector de pantallas. Debes
colocar como objeto inicial: Sub Main.
Option Explicit
Public screenSaver As cSalvaPantallas
Sub Main()
App.Title = "nombre del screensaver"
Set screenSaver = New cSalvaPantallas
Set screenSaver.mainWindow = frmMain
Set screenSaver.configWindow = frmConfig
screenSaver.iniciar
End Sub
Observa que necesitas dos formularios, uno de ellos es el protector de pantallas, es
decir, en el form_load comienzas a cargar animaciones, y con un timer las actualizas. El otro es un form de configuración, si no quieres que tu screensaver se pueda configurar, simplemente coloca allí el acerca de... Lo que sigue es el modulo de clase que les prometí.
'=====================================================================
' cSalvaPantallas
' Modulo de clase para trabajar modos de ejecución en salvapantallas
'=====================================================================
' Created By: Throglokan
' Published Date: 18/04/2007
' WebSite: Throglokan.blogspot.com
' Legal Copyright: Throglokan © 18/04/2007
'=====================================================================
====================
Option Explicit
Public Enum eRunMode
RM_NORMAL
RM_PREVIEW
RM_CONFIGURE
End Enum
Private Type RECT
Left As Long
top As Long
Right As Long
Bottom As Long
End Type
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Const HWND_TOPMOST = -1
Private Const SWP_SHOWWINDOW = &h40
Private Const GWL_STYLE = (-16)
Private Const WS_CHILD = &h40000000
Private Const GWL_HWNDPARENT = (-8)
Private Const HWND_TOP = 0
Private Const SWP_NOZORDER = &h4
Private Const SWP_NOACTIVATE = &h10
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private 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
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private DisplayHwnd As Long, DispRec As RECT, PrevWndProc As Long
Private DeskBmp As BITMAP, DeskDC As Long, cmd As String
Public RunMode As eRunMode
Private vMainWindow As Form, vConfigWindow As Form
Private Sub Class_Initialize()
Dim Style As Long
cmd = LCase$(Trim$(Command$))
Select Case Mid$(cmd, 1, 2)
Case "", "/s" '[Modo de normal de salvapantallas]
RunMode = RM_NORMAL
Case "/p" '[Modo de preview de salvapantallas] correr dentro de la pantalla de previsualización de propiedades
RunMode = RM_PREVIEW
Case "/c" '[Modo de configuración]
RunMode = RM_CONFIGURE
Case Else
#If DebugOn Then
MsgBox "Unknown Command Line Param: [" & Command$ & "]"
#End If
End
End Select
End Sub
Private Function GetHwndFromCmd(cmd As String) As Long
Dim Str As String
Dim lenStr As Long
Dim Idx As Long
Str = Trim$(cmd)
lenStr = Len(Str)
For Idx = lenStr tO 1 Step -1
Str = Right$(Str, Idx)
If IsNumeric(Str) Then
GetHwndFromCmd = Val(Str)
Exit For
End If
Next
End Function
Public Property Set mainWindow(ByVal vNewValue As Variant)
Set vMainWindow = vNewValue
End Property
Public Property Set configWindow(ByVal vNewValue As Variant)
Set vConfigWindow = vNewValue
End Property
Public Sub iniciar()
Dim Style As Long
cmd = LCase$(Trim$(Command$))
Select Case RunMode
Case Is = RM_NORMAL
GetWindowRect GetDesktopWindow(), DispRec
Load vMainWindow
#If DebugOn Then
Form1.Show 1
#Else
SetWindowPos vMainWindow.hwnd, HWND_TOPMOST, 0&, 0&,
DispRec.Right, DispRec.Bottom, SWP_SHOWWINDOW
#End If
Case Is = RM_PREVIEW
DisplayHwnd = GetHwndFromCmd(cmd)
GetClientRect DisplayHwnd, DispRec
Load vMainWindow
vMainWindow.Caption = "Preview"
Style = GetWindowLong(vMainWindow.hwnd, GWL_STYLE)
Style = Style or WS_CHILD
SetWindowLong vMainWindow.hwnd, GWL_STYLE, Style
SetParent vMainWindow.hwnd, DisplayHwnd
SetWindowLong vMainWindow.hwnd, GWL_HWNDPARENT,
DisplayHwnd
SetWindowPos vMainWindow.hwnd, HWND_TOP, 0&, 0&,
DispRec.Right, DispRec.Bottom, SWP_NOZORDER or SWP_NOACTIVATE or
SWP_SHOWWINDOW
Case Is = RM_CONFIGURE
Load vConfigWindow
vConfigWindow.Show
End Select
End Sub
Public Property Get height() As Variant
height = DispRec.Bottom
End Property
Public Property Get Width() As Variant
Width = DispRec.Right
End Property
Descargar documento y ejemplos:Descargar
Autor: Throglokan
Dedicado con todo mi amor a Tuniwield.
.... Y que viva el guarapo.
El formulario que se muestra, no debe tener bordes y estar maximizado, ese formulario
tendrá la animación que forma nuestro salvapantallas. Además en el evento mousemove
debe tener una sentencia que descargue el formulario.
Lo que viene de aquí en adelante no es complicado y aunque no estoy muy seguro de
hacerme entender, NO importa, porque al final les doy un modulo de clase que hace
todo el trabajo por nosotros.
Sin embargo pocas personas saben que los protectores de pantalla reciben parámetros
del sistema operativo que les indica su modo de ejecución:
/s modo normal (mostrar el screensaver)
/p modo preview (mostrar el screensaver en esa pantallita de propiedades de pantalla)
/c modo de configuración.
Teniendo esta información, son aun menos las personas que saben como colocar su
screensaver en esa pantallita de propiedades de pantalla. Pues les cuento que esto se
hace conociendo el hwnd (identificador de ventana, un número en hexadecimal) de la
ventanita en cuestión, y afortunadamente el hwnd es pasado en la línea de argumentos.
Diseñé un modulo de clase que nos ayuda con la tareita.
MODO DE USO DEL MODULO DE CLASE
Crearemos un modulo Standard desde donde iniciara el protector de pantallas. Debes
colocar como objeto inicial: Sub Main.
Option Explicit
Public screenSaver As cSalvaPantallas
Sub Main()
App.Title = "nombre del screensaver"
Set screenSaver = New cSalvaPantallas
Set screenSaver.mainWindow = frmMain
Set screenSaver.configWindow = frmConfig
screenSaver.iniciar
End Sub
Observa que necesitas dos formularios, uno de ellos es el protector de pantallas, es
decir, en el form_load comienzas a cargar animaciones, y con un timer las actualizas. El otro es un form de configuración, si no quieres que tu screensaver se pueda configurar, simplemente coloca allí el acerca de... Lo que sigue es el modulo de clase que les prometí.
'=====================================================================
' cSalvaPantallas
' Modulo de clase para trabajar modos de ejecución en salvapantallas
'=====================================================================
' Created By: Throglokan
' Published Date: 18/04/2007
' WebSite: Throglokan.blogspot.com
' Legal Copyright: Throglokan © 18/04/2007
'=====================================================================
====================
Option Explicit
Public Enum eRunMode
RM_NORMAL
RM_PREVIEW
RM_CONFIGURE
End Enum
Private Type RECT
Left As Long
top As Long
Right As Long
Bottom As Long
End Type
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Const HWND_TOPMOST = -1
Private Const SWP_SHOWWINDOW = &h40
Private Const GWL_STYLE = (-16)
Private Const WS_CHILD = &h40000000
Private Const GWL_HWNDPARENT = (-8)
Private Const HWND_TOP = 0
Private Const SWP_NOZORDER = &h4
Private Const SWP_NOACTIVATE = &h10
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private 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
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private DisplayHwnd As Long, DispRec As RECT, PrevWndProc As Long
Private DeskBmp As BITMAP, DeskDC As Long, cmd As String
Public RunMode As eRunMode
Private vMainWindow As Form, vConfigWindow As Form
Private Sub Class_Initialize()
Dim Style As Long
cmd = LCase$(Trim$(Command$))
Select Case Mid$(cmd, 1, 2)
Case "", "/s" '[Modo de normal de salvapantallas]
RunMode = RM_NORMAL
Case "/p" '[Modo de preview de salvapantallas] correr dentro de la pantalla de previsualización de propiedades
RunMode = RM_PREVIEW
Case "/c" '[Modo de configuración]
RunMode = RM_CONFIGURE
Case Else
#If DebugOn Then
MsgBox "Unknown Command Line Param: [" & Command$ & "]"
#End If
End
End Select
End Sub
Private Function GetHwndFromCmd(cmd As String) As Long
Dim Str As String
Dim lenStr As Long
Dim Idx As Long
Str = Trim$(cmd)
lenStr = Len(Str)
For Idx = lenStr tO 1 Step -1
Str = Right$(Str, Idx)
If IsNumeric(Str) Then
GetHwndFromCmd = Val(Str)
Exit For
End If
Next
End Function
Public Property Set mainWindow(ByVal vNewValue As Variant)
Set vMainWindow = vNewValue
End Property
Public Property Set configWindow(ByVal vNewValue As Variant)
Set vConfigWindow = vNewValue
End Property
Public Sub iniciar()
Dim Style As Long
cmd = LCase$(Trim$(Command$))
Select Case RunMode
Case Is = RM_NORMAL
GetWindowRect GetDesktopWindow(), DispRec
Load vMainWindow
#If DebugOn Then
Form1.Show 1
#Else
SetWindowPos vMainWindow.hwnd, HWND_TOPMOST, 0&, 0&,
DispRec.Right, DispRec.Bottom, SWP_SHOWWINDOW
#End If
Case Is = RM_PREVIEW
DisplayHwnd = GetHwndFromCmd(cmd)
GetClientRect DisplayHwnd, DispRec
Load vMainWindow
vMainWindow.Caption = "Preview"
Style = GetWindowLong(vMainWindow.hwnd, GWL_STYLE)
Style = Style or WS_CHILD
SetWindowLong vMainWindow.hwnd, GWL_STYLE, Style
SetParent vMainWindow.hwnd, DisplayHwnd
SetWindowLong vMainWindow.hwnd, GWL_HWNDPARENT,
DisplayHwnd
SetWindowPos vMainWindow.hwnd, HWND_TOP, 0&, 0&,
DispRec.Right, DispRec.Bottom, SWP_NOZORDER or SWP_NOACTIVATE or
SWP_SHOWWINDOW
Case Is = RM_CONFIGURE
Load vConfigWindow
vConfigWindow.Show
End Select
End Sub
Public Property Get height() As Variant
height = DispRec.Bottom
End Property
Public Property Get Width() As Variant
Width = DispRec.Right
End Property
Descargar documento y ejemplos:Descargar
Autor: Throglokan
Dedicado con todo mi amor a Tuniwield.
.... Y que viva el guarapo.
Suscribirse a:
Entradas (Atom)