Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetSystemMetrics API Call Problem - Screen Resolution 2

Status
Not open for further replies.

ripper12

Programmer
Mar 24, 2001
5
US
Using
ResX = GetSystemMetrics (SM_CXSCREEN)
and
ResY = GetSystemMetrics (SM_CYSCREEN)

No matter what resolution I'm actually at,
I always get the correct ResX but the ResY is always the same as the ResX !!

I've tried it under Windows 98, NT 4.0 and Windows ME with the same result.

Any help?

Thanks
Mike
mripley@sprynet.com
 
Have you set the contants? SM_CXSCREEN=0, Y=1


Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1

Later,
Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
I assume you've already double checked that SM_CYSCREEN is defined with the correct value (1).

You've probably got the Declare Function coded incorrectly. The parameter should be a Long. If you defined it as an Integer, the DLL would be looking at slack bytes for the function code, and the slack bytes would most likely be zeros. The same thing would happen when you pass either SM_CXSCREEN or SM_CYSCREEN, but since SM_CXSCREEN happens to be 0 anyway, it appears to work correctly.

The correct declaration is:
Public Declare Function GetSystemMetrics Lib "user32" Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

If you coded it "nIndex As Integer" because you were translating it from a C-code definition, you were probably tricked by the fact that a C "int" is 4 bytes long, while a VBA Integer is only 2 bytes. C "int" is equivalent to VBA Long. (BTW, in .NET the VBA Integer will become 4 bytes, so that all languages will share common data types. The 2 byte integer will be renamed to ShortInt.) Rick Sprague
 
Yeah, I didn't declare the constants correctly.

THANKS!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top