When you create a screen saver in Visual Basic, you may sometimes utilize the command-line options such as “/s” to start a screen saver directly or “/c” to run the configuration. By simply using App.PrevInstance, your application may not detect the running screen saver and attempt to start another when the normal Windows screen saver time-out occurs. To ensure that Windows will detect the running screen saver, regardless of the use of command-line options, use this code:
Private Declare Function GetModuleHandle% Lib "Kernel" _ (ByVal lpModuleName$)Private Declare Function GetModuleUsage% Lib "Kernel" _ (ByVal hModule%)Sub StartUp()Dim Inst% Inst = GetModuleHandle(App.Path + _ "" + CStr(Trim(App.EXEName) + ".scr")) If GetModuleUsage_ (GetModuleHandle(App.Path + "" _ + CStr(Trim(App.EXEName) + ".scr"))) > 1 Then EndEnd Sub
Call the sub like this:
Sub Main() Call StartUpEnd
This method works well with Windows 3.11. You can use this basic idea with any application you write, not just screen savers.