IT CAMPER
asked on
Can I wake up a computer from screen saver with a VB executable?
I have a VB executable that notifies me of new email with a large flashing image. Is there anyway to have the VB wake up the computer once it goes into the screen saver (of course I mean when the executable is run)? I want the screen saver to kick in as normal so that teh screen does not burn in, but I would like for the executable to return the screen to the desktop and the flashing image so that I will see it.
If not with VB then maybe something else?
If not with VB then maybe something else?
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub MousePos(ByRef X As Long, ByRef Y As Long)
Dim Mouse As POINTAPI
GetCursorPos Mouse
X = Mouse.X
Y = Mouse.Y
End Sub
Private Sub SetX(X As Long)
Dim Mouse As POINTAPI
GetCursorPos Mouse
Mouse.X = X
RealMousePos Mouse
mouse_event &H1 Or &H8000, Mouse.X, Mouse.Y, 0, 0
End Sub
Private Sub RealMousePos(ByRef Point As POINTAPI)
Point.X = Point.X * (65536 / GetSystemMetrics(0))
Point.Y = Point.Y * (65536 / GetSystemMetrics(1))
End Sub
I would use this, then when you get new mail do:
Dim X as long,Y as long
MousePos X,Y
SetX x+5
This will send mouse movement. The reason I
suggest this is, if the screensaver is not active,
it will not close a different program (the other
method will). Also, such little mouse movement
will not cause troubles if screensavers not active.
Otherwise you need to MAKE SURE that the
screensaver is active, so you are not closing
the wrong program.
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub MousePos(ByRef X As Long, ByRef Y As Long)
Dim Mouse As POINTAPI
GetCursorPos Mouse
X = Mouse.X
Y = Mouse.Y
End Sub
Private Sub SetX(X As Long)
Dim Mouse As POINTAPI
GetCursorPos Mouse
Mouse.X = X
RealMousePos Mouse
mouse_event &H1 Or &H8000, Mouse.X, Mouse.Y, 0, 0
End Sub
Private Sub RealMousePos(ByRef Point As POINTAPI)
Point.X = Point.X * (65536 / GetSystemMetrics(0))
Point.Y = Point.Y * (65536 / GetSystemMetrics(1))
End Sub
I would use this, then when you get new mail do:
Dim X as long,Y as long
MousePos X,Y
SetX x+5
This will send mouse movement. The reason I
suggest this is, if the screensaver is not active,
it will not close a different program (the other
method will). Also, such little mouse movement
will not cause troubles if screensavers not active.
Otherwise you need to MAKE SURE that the
screensaver is active, so you are not closing
the wrong program.
How about simulating a keypress:
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_S = &H53&
Private Sub Command1_Click()
keybd_event VK_S, 0, 0, 0 ' Press S
keybd_event VK_S, 0, KEYEVENTF_KEYUP, 0 ' Release it
End Sub
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_S = &H53&
Private Sub Command1_Click()
keybd_event VK_S, 0, 0, 0 ' Press S
keybd_event VK_S, 0, KEYEVENTF_KEYUP, 0 ' Release it
End Sub
If you use Vinny's method, I would suggest taking out
the Sleep, seeing how it is unused.
the Sleep, seeing how it is unused.
ASKER
I have increased the points to 500 from 250 because I need a little more help with implementing these solutions. I am okay with either mouse movement or keypress so I will award points to whoever can add code to the already working VB code below and test it working to kill the screensaver. I have very little experience with VB so I am unable to get either to work. The code below is someones else's work and it works perfectly but I need to add the screen saver solution to it. Thanks.
VERSION 5.00
Begin VB.Form frmMain
BorderStyle = 3 'Fixed Dialog
Caption = "Message Notification"
ClientHeight = 3120
ClientLeft = 45
ClientTop = 435
ClientWidth = 7065
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 208
ScaleMode = 3 'Pixel
ScaleWidth = 471
ShowInTaskbar = 0 'False
StartUpPosition = 2 'CenterScreen
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 1000
Left = 120
Top = 2520
End
Begin VB.CommandButton btnClose
Appearance = 0 'Flat
Caption = "Close"
Default = -1 'True
Height = 375
Left = 5760
TabIndex = 1
Top = 2640
Width = 1095
End
Begin VB.Label lblMessage
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "URGENT New message for Backup Guard"
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 375
Left = 240
TabIndex = 0
Top = 1200
Width = 6495
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim arrParams As Variant, _
lngRootColor As Long, _
lngFlashColor As Long
Private Sub Form_Load()
Dim strArguments As String, _
intParamCount As Integer, _
varTemp As Variant
lngRootColor = frmMain.BackColor
lngFlashColor = vbRed
strArguments = Command()
arrParams = Split(strArguments, "/", , vbTextCompare)
For intParamCount = 0 To UBound(arrParams)
varTemp = Trim(Mid(arrParams(intPara mCount), 3))
Select Case LCase(Left(arrParams(intPa ramCount), 1))
Case "a" 'Account parameter
lblMessage.Caption = lblMessage.Caption & " " & varTemp
Case "c" 'Root color parameter
lngFlashColor = Val(varTemp)
Case "h" 'Height of the dialog-box parameter
If IsNumeric(varTemp) Then
frmMain.Height = (Int(varTemp) * Screen.TwipsPerPixelX)
End If
Case "w" 'Width of the dialog-box parameter
If IsNumeric(varTemp) Then
frmMain.Width = (Int(varTemp) * Screen.TwipsPerPixelY)
End If
Case "s" 'Speed parameter
If IsNumeric(varTemp) Then
Timer1.Interval = CLng(varTemp)
End If
End Select
Next
btnClose.Top = frmMain.ScaleHeight - (btnClose.Height + 25)
btnClose.Left = frmMain.ScaleWidth - (btnClose.Width + 25)
lblMessage.Top = (frmMain.ScaleHeight - lblMessage.Height) / 2
lblMessage.Left = (frmMain.ScaleWidth - lblMessage.Width) / 2
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static bolRoot As Boolean
frmMain.BackColor = IIf(bolRoot, lngRootColor, lngFlashColor)
bolRoot = Not bolRoot
DoEvents
End Sub
VERSION 5.00
Begin VB.Form frmMain
BorderStyle = 3 'Fixed Dialog
Caption = "Message Notification"
ClientHeight = 3120
ClientLeft = 45
ClientTop = 435
ClientWidth = 7065
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 208
ScaleMode = 3 'Pixel
ScaleWidth = 471
ShowInTaskbar = 0 'False
StartUpPosition = 2 'CenterScreen
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 1000
Left = 120
Top = 2520
End
Begin VB.CommandButton btnClose
Appearance = 0 'Flat
Caption = "Close"
Default = -1 'True
Height = 375
Left = 5760
TabIndex = 1
Top = 2640
Width = 1095
End
Begin VB.Label lblMessage
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "URGENT New message for Backup Guard"
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 375
Left = 240
TabIndex = 0
Top = 1200
Width = 6495
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim arrParams As Variant, _
lngRootColor As Long, _
lngFlashColor As Long
Private Sub Form_Load()
Dim strArguments As String, _
intParamCount As Integer, _
varTemp As Variant
lngRootColor = frmMain.BackColor
lngFlashColor = vbRed
strArguments = Command()
arrParams = Split(strArguments, "/", , vbTextCompare)
For intParamCount = 0 To UBound(arrParams)
varTemp = Trim(Mid(arrParams(intPara
Select Case LCase(Left(arrParams(intPa
Case "a" 'Account parameter
lblMessage.Caption = lblMessage.Caption & " " & varTemp
Case "c" 'Root color parameter
lngFlashColor = Val(varTemp)
Case "h" 'Height of the dialog-box parameter
If IsNumeric(varTemp) Then
frmMain.Height = (Int(varTemp) * Screen.TwipsPerPixelX)
End If
Case "w" 'Width of the dialog-box parameter
If IsNumeric(varTemp) Then
frmMain.Width = (Int(varTemp) * Screen.TwipsPerPixelY)
End If
Case "s" 'Speed parameter
If IsNumeric(varTemp) Then
Timer1.Interval = CLng(varTemp)
End If
End Select
Next
btnClose.Top = frmMain.ScaleHeight - (btnClose.Height + 25)
btnClose.Left = frmMain.ScaleWidth - (btnClose.Width + 25)
lblMessage.Top = (frmMain.ScaleHeight - lblMessage.Height) / 2
lblMessage.Left = (frmMain.ScaleWidth - lblMessage.Width) / 2
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static bolRoot As Boolean
frmMain.BackColor = IIf(bolRoot, lngRootColor, lngFlashColor)
bolRoot = Not bolRoot
DoEvents
End Sub
Are you using Visual Basic or Wordpad???
Is the vb EXE that tells you you have mail
something you have code for , or a seperate
program?
Is the vb EXE that tells you you have mail
something you have code for , or a seperate
program?
ASKER
I am using Visual Basic to compile the code I provided. I use another program to fire the exe that the visual basic creates. All of the process is working okay, I just need to be able to see the flashing message when the screen saver is running. I just paste the completed code into notepad and name *.frm then open in VB.
Okay for the code I provided:
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub MousePos(ByRef X As Long, ByRef Y As Long)
Dim Mouse As POINTAPI
GetCursorPos Mouse
X = Mouse.X
Y = Mouse.Y
End Sub
Private Sub SetX(X As Long)
Dim Mouse As POINTAPI
GetCursorPos Mouse
Mouse.X = X
RealMousePos Mouse
mouse_event &H1 Or &H8000, Mouse.X, Mouse.Y, 0, 0
End Sub
Private Sub RealMousePos(ByRef Point As POINTAPI)
Point.X = Point.X * (65536 / GetSystemMetrics(0))
Point.Y = Point.Y * (65536 / GetSystemMetrics(1))
End Sub
Paste the above in the declarations under General.
Then paste the following code where you need the
screensaver disabled:
Dim X as long,Y as long
MousePos X,Y
SetX x+5
(In an exisiting sub of course)
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub MousePos(ByRef X As Long, ByRef Y As Long)
Dim Mouse As POINTAPI
GetCursorPos Mouse
X = Mouse.X
Y = Mouse.Y
End Sub
Private Sub SetX(X As Long)
Dim Mouse As POINTAPI
GetCursorPos Mouse
Mouse.X = X
RealMousePos Mouse
mouse_event &H1 Or &H8000, Mouse.X, Mouse.Y, 0, 0
End Sub
Private Sub RealMousePos(ByRef Point As POINTAPI)
Point.X = Point.X * (65536 / GetSystemMetrics(0))
Point.Y = Point.Y * (65536 / GetSystemMetrics(1))
End Sub
Paste the above in the declarations under General.
Then paste the following code where you need the
screensaver disabled:
Dim X as long,Y as long
MousePos X,Y
SetX x+5
(In an exisiting sub of course)
ASKER
please excuse my ignorance in Visual Basic. I am unable to understand where to place your code. I want to execute your mouse movement at the end of the process. Can you please insert all of your code in the correct place within the code I have provided. I will then create a frm file with that code and compile it. Thank you again.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it works...I would also like to create a seperate exe with just your code that I can run by itself. I thought I could do that simply and it works but it creates a small prompt that I have to close manually. Can you assemble code for that too and include a way to make sure it closes any windows it opens.
Again, I just want seperate code of your solution that I can compile by itself without any of my stuff but I want it to move the mouse then exit completely.
Again, I just want seperate code of your solution that I can compile by itself without any of my stuff but I want it to move the mouse then exit completely.
Only need to use the below to move the mouse 10 "mickeys" to the right:
Call mouse_event(&H1, 10, 0, 0, 0)
:P
Call mouse_event(&H1, 10, 0, 0, 0)
:P
ASKER
zzzzzzooc...
I have no experience with Visual Basic, can you make me a complete VB code that I can compile with VB into an exe that will move the mouse as you describe? I create an FRM file in notepad with the source code then open with VB and create the exe.
I have no experience with Visual Basic, can you make me a complete VB code that I can compile with VB into an exe that will move the mouse as you describe? I create an FRM file in notepad with the source code then open with VB and create the exe.
Comment was directed towards List244. It was his suggestion so I'm not going to "muscle in" after his time spent helping. Just trying to make things simpler.
MurryC, I told you put the line wherever it should be disabling the screensaver.
From looking at the code, it appears to me there is no spot where it is to
disable the screensaver. On form load would make no sense, and your
timer.... Has no Ifs.. So, really I don't quite see what you are doing
here. I think you have a seperate program that tells you if you have
mail, and you are trying to write an add-on that makes it disable the
screensaver as well, and well... With your experience in VB... That
is going to be rough, even if one of us GAVE you a solution... Sorry.
However, maybe that program launches yours when you get new mail?
If so, put the mouse-move code on form load. Otherwise... Put it in
the timer, and watch your mouse go crazy as long as your program
is running. Sorry I couldn't help more.
From looking at the code, it appears to me there is no spot where it is to
disable the screensaver. On form load would make no sense, and your
timer.... Has no Ifs.. So, really I don't quite see what you are doing
here. I think you have a seperate program that tells you if you have
mail, and you are trying to write an add-on that makes it disable the
screensaver as well, and well... With your experience in VB... That
is going to be rough, even if one of us GAVE you a solution... Sorry.
However, maybe that program launches yours when you get new mail?
If so, put the mouse-move code on form load. Otherwise... Put it in
the timer, and watch your mouse go crazy as long as your program
is running. Sorry I couldn't help more.
Zzzzzooc If you happen to understand his problem
any better than I apparently do, go right ahead and
jump in, I've helped all I can.
any better than I apparently do, go right ahead and
jump in, I've helped all I can.
ASKER
List244.. the overall solution with my existing coding works great, inlcuding what you added for me. It would be hard for me to explain what it all does for me and how I run it, but I do use a batch file that runs the executable with additional switch information. All I want now is just to have a VB executable that does nothing but moves the mouse when executed. I implemented your coding into my exiting code and placed the line where I wanted it and it wakes up the computer when the exe executes. I would now like to just have your code by itself in an executable that if run does nothing but wakes the computer from the screen saver. I tried creating the FRM file with just your code and it works but it also opens a small window prompt that has to be closed. I am sure it can just run and close all on its own, I just do not know how to do it.
Is that a better explaination?
Is that a better explaination?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks to both list244 and zzzzzooc for the solutions..they both work great...majority of points to List244 for providing main solution...others to zzzzzooc for following up with additional request
ASKER
list224 was supposed to get the accepted answer and zzzzzooc was supposed to get assisted but I reversed them by accident..points where split correctly though..thanks again
Check out this URL:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q140723
Or Try the API
PostMessage (GetForegroundWindow(), WM_CLOSE, 0, 0)
from VB if you are not running NT