dcsimg
November 27, 2020
Hot Topics:

Quickstart Guide to Screensavers

  • By Karl Moore
  • Send Email »
  • More Articles »

Previewing your screensaver means recreating a smaller version of it in the 'Preview' panel in the Display applet. This is not as difficult as it sounds and simply requires you to copy-and-paste a chunk of code.

Previewing your Screensaver

  • Add the following code to a module in your screensaver application:
Private Type RECT   Left As Long   Top As Long   Right As Long   Bottom As LongEnd TypePrivate Const WS_CHILD = &H40000000Private Const GWL_STYLE = (-16)Private Const GWL_HWNDPARENT = (-8)Private Const HWND_TOP = 0&Private Const SWP_NOZORDER = &H4Private Const SWP_NOACTIVATE = &H10Private Const SWP_SHOWWINDOW = &H40Declare Function GetClientRect Lib "user32" _    (ByVal hwnd As Long, lpRect As RECT) As LongDeclare Function GetWindowLong Lib "user32" _    Alias "GetWindowLongA" (ByVal hwnd As Long, _    ByVal nIndex As Long) As LongDeclare Sub 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)Declare Function SetWindowLong Lib "user32" _    Alias "SetWindowLongA" (ByVal hwnd As Long, _    ByVal nIndex As Long, ByVal dwNewLong As Long) As LongDeclare Function SetParent Lib "user32" _    (ByVal hWndChild As Long, _    ByVal hWndNewParent As Long) As LongPublic Sub DoPreviewMode(PreviewForm As Form)        Dim lngStyle As Long, dispHWND As Long, DispRec As RECT        dispHWND = CLng(Right(Command, Len(Command) - 3))        Load PreviewForm    GetClientRect dispHWND, DispRec    lngStyle = GetWindowLong(PreviewForm.hwnd, GWL_STYLE)    lngStyle = lngStyle Or WS_CHILD ' Append "WS_CHILD"    SetWindowLong PreviewForm.hwnd, GWL_STYLE, lngStyle    SetParent PreviewForm.hwnd, dispHWND    SetWindowLong PreviewForm.hwnd, GWL_HWNDPARENT, dispHWND    SetWindowPos PreviewForm.hwnd, HWND_TOP, 0&, 0&, _        DispRec.Right, DispRec.Bottom, _        SWP_NOZORDER Or SWP_NOACTIVATE Or SWP_SHOWWINDOW        End Sub
  • When a preview is requested (see Determining the Mode), run the DoPreviewMode method, passing it your form to preview as an argument




Page 4 of 8



This article was originally published on November 20, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.


Thanks for your registration, follow us on our social networks to keep up-to-date