INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Visual Basic (Microsoft) Versions 5/6 FAQ

Screen

How To Determine Size of Desk Top Area by TomKane
Posted: 15 Apr 03

All Products  |   Support  |   Search  |   microsoft.com Home    
  
 
  Support Home  |   Self Support  |   Assisted Support  |   Custom Support  |   Worldwide Support  |  
 
  All Products  |  Support  |  Search  |  microsoft.com Guide  Home   |  Self Support   |  Assisted Support   |  Custom Support   |  Worldwide Support   |


--------------------------------------------------------------------------------
 Downloads
 MS Product Catalog
 Microsoft Accessibility

--------------------------------------------------------------------------------
 Server Products
 Developer Tools
 Office Family
 Windows Family
 MSN
 
--------------------------------------------------------------------------------
 Knowledge Base
 Product Support Options
 Service Partner Referrals
 Year 2000 Compliance
 
--------------------------------------------------------------------------------
 Search microsoft.com
 MSN Web Search
 
--------------------------------------------------------------------------------
 microsoft.com Home
 MSN Home

--------------------------------------------------------------------------------
 Contact Us
 Events
 Newsletters
 Profile Center
 Training & Certification
 Free E-mail Account
 
--------------------------------------------------------------------------------
 Support Home
 microsoft.com
 
--------------------------------------------------------------------------------
 Searchable Knowledge Base
 Download Center
 FAQs by Product
 
--------------------------------------------------------------------------------
 Assisted Support Directory
 Online Support Requests
 Phone Numbers
 
--------------------------------------------------------------------------------
 Worldwide Support
HOWTO: Determine the Size of the Desktop Area

--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 6.0
Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise Editions for Windows, version 5.0
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0

--------------------------------------------------------------------------------


SUMMARY
It is often useful to determine the size and position of the display area taking the system tray into account. There are at least two methods to obtain this information: One requires the use of an OCX, while another makes a call to the Win32 API. This article demonstrates the step-by-step approaches to both of these methods.



MORE INFORMATION

Method 1
NOTE: In Microsoft Visual Basic 4.0, the SYSINFO.OCX control is in the \VB4\TOOLS\SYSINFO folder of the Visual Basic CD-ROM. It does not ship with the diskette version, and it is not automatically installed by Visual Basic Setup. Copy SYSINFO.OCX to the \WINDOWS\SYSTEM folder, and register it with REGOCX32.EXE. In Microsoft Visual Basic 5.0 and later, SYSINFO.OCX is installed by default.

Use the SYSINFO.OCX control in your project. It has a number of useful properties, four of which disclose the size and position of the desktop area in twips. Follow the steps below:

Start Visual Basic. Form1 is created by default.


Add a Command button to Form1.


From the Tools menu, choose Custom Controls and check the "Microsoft System Info" component. If the component is not listed, click the browse button and locate SYSINFO.OCX.


Add a SysInfo control to Form1.


Add the following code to the Command1_Click event:
    Private Sub Command1_Click()

      With SysInfo1
        Print "WorkAreaLeft: " & .WorkAreaLeft / Screen.TwipsPerPixelX
        Print "WorkAreaTop: " & .WorkAreaTop / Screen.TwipsPerPixelY
        Print "WorkAreaWidth: " & .WorkAreaWidth / Screen.TwipsPerPixelX
        Print "WorkAreaHeight: " & .WorkAreaHeight / Screen.TwipsPerPixelY
      End With

    End Sub
 



Choose Start from the Run menu, or press the F5 key to run the project.


Click the Command button to observe the size of the work area.


Method 2
The SystemParametersInfo function has many uses, including the ability to determine the size and position of the desktop. Follow the steps below:

Start Visual Basic. Form1 is created by default.


From the Insert menu, choose Module to add a single code module to the project. Module1 is created by default.


Add the following code to Module1:
      Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
      End Type

      Public Const SPI_GETWORKAREA = 48

      Declare Function SystemParametersInfo Lib "user32" _
        Alias "SystemParametersInfoA" (ByVal uAction As Long, _
        ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) _
        As Long
 



Add a Command button to Form1.


Add the following code to the Command1_Click event:
      Private Sub Command1_Click()

        Dim lRet As Long
        Dim apiRECT As RECT

        lRet = SystemParametersInfo(SPI_GETWORKAREA, vbNull, apiRECT, 0)

        If lRet Then
          Print "WorkAreaLeft: " & apiRECT.Left
          Print "WorkAreaTop: " & apiRECT.Top
          Print "WorkAreaWidth: " & apiRECT.Right - apiRECT.Left
          Print "WorkAreaHeight: " & apiRECT.Bottom - apiRECT.Top
        Else
          Print "Call to SystemParametersInfo failed."
        End If

      End Sub
 



Choose Start from the Run menu, or press the F5 key to run the project.


Click the Command button to observe the size of the work area.





REFERENCES
SYSINFO.HLP in the \TOOLS\SYSINFO directory on the Visual Basic 4.0 CD-ROM. In Visual Basic 5.0 and later, SYSINFO.HLP IS IN THE WINDOWS\HELP directory.

Win32 SDK on the MSDN Visual Basic starter kit. This can be installed by running SETUP.EXE from the MSDN directory on the Visual Basic 4.0 CD-ROM.

For more information, please see the following articles on the Microsoft Knowledge Base:


Q113702 : How to Control the Placement of Desktop Windows

Q97142 : How to Use SystemParametersInfo API for Control Panel Settings

Additional query words: kbVBp400 kbVBp500 kbVBp600 KBWIN32SDK KBAPI kbVBp kbdsd kbDSupport

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


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

  

Article ID: Q154823

Last Reviewed:
January 5, 2000

Provided by Microsoft Product Support Services.




--------------------------------------------------------------------------------

      Did the information in this article help answer your question?
Yes
No
Did not apply

Please provide additional comments about this information. If you require a response or technical support, please click Contact Us.
(255 character max)

 


 
 
 


Back to Visual Basic (Microsoft) Versions 5/6 FAQ Index
Back to Visual Basic (Microsoft) Versions 5/6 Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close