Microsoft KB Archive/141024

= How to Start a Visual Basic Screen Saver Using SendMessage API =

Article ID: 141024

Article Last Modified on 12/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q141024



SUMMARY
The sample code below shows how to start a Visual Basic screen saver by sending a Windows message to the Control-menu box on a form.



MORE INFORMATION
Microsoft Windows starts screen savers through the System-menu box on a form. The System-menu box is also known as the Control-menu box in Visual Basic. You can send Windows messages to the Control-menu box by using the SendMessage Windows API (application programming interface) function.

[general declarations] Private Declare Function SendMessage Lib "user32" Alias _ "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _    ByVal wParam As Long, ByVal lParam As Long) As Long Const WM_SYSCOMMAND = &H112& Const SC_SCREENSAVE = &HF140& Private Declare Function SendMessage Lib "User" (ByVal _        hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As _             Integer, lParam As Any) As Long Const WM_SYSCOMMAND = &H112 Const SC_SCREENSAVE = &HF140&
 * 1) If Win32 Then
 * 1) Else
 * 1) End If

Private Sub Command1_Click Dim result As Long result = SendMessage(Form1.hWnd, WM_SYSCOMMAND, _    SC_SCREENSAVE, 0&) End Sub

