HOWTO: Use APIs to Check, Enable, or Disable Full Window Drag

ID: Q185637


The information in this article applies to:
  • Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
  • Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 16-bit and 32-bit, for Windows, version 4.0


SUMMARY

Normally, when a window is moved or sized, the operating system informs the window by posting the appropriate messages at the end of the move or size operation. These messages include WM_MOVE, WM_WINDOWPOSCHANGED, WM_PAINT, and WM_SIZE among others. Windows NT 4.0, and Windows 95 (with the Microsoft Plus! add-in), and Windows 98 offer the ability to show the entire contents of a window as it is moved or resized. The operating system accomplishes this by continuously sending these messages to the window during moving or resizing, not just at the end of the operation. This causes the window to redraw itself multiple times during one resize or move operation.

At times, you may want to disable this feature to avoid possible flickering of the screen or to prevent code in an event like the ReSize event from occurring multiple times during one resize operation. Using the SystemParametersInfo API function, the status of this feature can be checked, enabled, or disabled as needed. This technique is demonstrated in the sample code below for both the 16- and 32-bit Visual Basic development environments.


MORE INFORMATION

Steps to Create Sample 32-Bit Project

  1. Create a new Visual Basic project. Form1 is created by default.


  2. Paste the following code into the code module for Form1:
    
          Option Explicit
    
          Private Declare Function SystemParametersInfo Lib "user32" _
             Alias "SystemParametersInfoA" (ByVal uAction As Long, _
             ByVal uParam As Long, ByRef lpvParam As Any, _
             ByVal fuWinIni As Long) As Long
    
          Private Const SPI_GETDRAGFULLWINDOWS = 38
          Private Const SPI_SETDRAGFULLWINDOWS = 37
          Private Const SPIF_SENDWININICHANGE = 2
    
          Private Function IsFullWindowDragOn() As Boolean
              Dim result As Long
    
              'Call API and check for successful call.
              If SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0&, result, 0&) _
                     <> 0 Then
                  'Feature supported now check value of result.
                  If result = 0 Then
                      IsFullWindowDragOn = False
                  Else
                      IsFullWindowDragOn = True
                  End If
    
              'Call failed, feature not supported.
              Else
                  IsFullWindowDragOn = False
              End If
          End Function
    
          Private Sub Form_Click()
              Dim result As Long
    
              'Toggle the setting.
              If IsFullWindowDragOn Then
                  'Turn full window drag off.
                  result = SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, 0&, _
                     ByVal vbNullString, SPIF_SENDWININICHANGE)
              Else
                  'Turn full window drag on.
                  result = SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, 1&, _
                     ByVal vbNullString, SPIF_SENDWININICHANGE)
              End If
          End Sub
     


  3. Save and run the project.


  4. Click the form. This toggles full window dragging.


  5. Move or resize the window to test the full window dragging state.

    RESULT: Full window dragging is toggled on and off with each click of the form.


Steps to Create Sample 16-Bit Project

Repeat steps 1-5 above but replace the code in step 2 with the following code:

   Option Explicit

   Private Declare Function SystemParametersInfo Lib "user" ( _
      ByVal uAction As Integer, ByVal uParam As Integer, _
      ByRef lpvParam As Any, ByVal fuWinIni As Integer) As Integer

   Private Const SPI_GETDRAGFULLWINDOWS = 38
   Private Const SPI_SETDRAGFULLWINDOWS = 37
   Private Const SPIF_SENDWININICHANGE = 2

   Private Function IsFullWindowDragOn() As Boolean
       Dim result As Integer

       'Call API and check for successful call.
       If SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0, result, 0) _
              <> 0 Then
           'Feature supported now check value of result.
           If result = 0 Then
               IsFullWindowDragOn = False
           Else
               IsFullWindowDragOn = True
           End If

       'Call failed, feature not supported.
       Else
           IsFullWindowDragOn = False
       End If
   End Function

   Private Sub Form_Click()
       Dim result As Integer

       'Toggle the setting.
       If IsFullWindowDragOn Then
           'Turn full window drag off.
           result = SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, 0, _
              ByVal vbNullString, SPIF_SENDWININICHANGE)
       Else
           'Turn full window drag on.
           result = SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, 1, _
              ByVal vbNullString, SPIF_SENDWININICHANGE)
       End If
   End Sub 

Additional query words: kbSDKWin32 kbAPI kbVBp400 kbVBp500 kbVBp kbDSupport Kbdsd kbVBp600

Keywords : kbGrpVB
Version :
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: January 5, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.