GetSystemMetrics

Windows specific forum
Master Games
User
User
Posts: 22
Joined: Mon Oct 06, 2003 1:42 am

GetSystemMetrics

Post by Master Games »

I have a problem that the SM_CYSCREEN returns the SM_CXSCREEN value instead of what it should be, SM_CXSCREEN works fine.

My screen resolution is 1024 by 768 and SM_CXSCREEN and SM_CYSCREEN both return 1024. Is this a bug or am I doing something wrong?

Code: Select all

;Gets Screen X and Y
ScreenX = GetSystemMetrics_(SM_CXSCREEN)
ScreenY = GetSystemMetrics_(SM_CYSCREEN)



;Creates window
If OpenWindow(0, ScreenX/2-Int(0.75*ScreenX/2), ScreenY/2-Int(0.4*ScreenY/2), Int(0.75*ScreenX), Int(0.4*ScreenY), #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar , "GetSystemMetrics Example for Forum")
  
EndIf

MessageRequester("ScreenX",Str(ScreenX))
MessageRequester("ScreenY",Str(ScreenY))

Repeat
  
  EventID = WaitWindowEvent()

  
Until EventID = #PB_EventCloseWindow

End
I was not sure what part of the forums I should have posted this in, it was either this or Beginners.
Thanks,
Master Games

System: P4 1.9 GHZ, 1 GB DDR Memory, 80 GB Hard Drive, WinXP Home Edition with Latest Patch, Creative labs Audigy Sound Blaster Platinum Sound Card, Geforce 3 Graphics card with 52.16 drivers
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

Post by Codemonger »

You did not define the following variables --- as constants

Code: Select all

#SM_CXSCREEN = 0
#SM_CYSCREEN = 1
the value was defaulted to 0 so it was passing the default x screen metrics or whatever. Anyway use the above two constants and maybe it will work ??
<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

You do not need to define 99.9% of all WinAPI constants as they are already a part of PB, just remember to include the # before them to use them! Your code should look like this:

Code: Select all

ScreenX = GetSystemMetrics_(#SM_CXSCREEN)
ScreenY = GetSystemMetrics_(#SM_CYSCREEN)
--Kale

Image
Master Games
User
User
Posts: 22
Joined: Mon Oct 06, 2003 1:42 am

Post by Master Games »

Thank you Kale and Codemonger, it works now :)
Thanks,
Master Games

System: P4 1.9 GHZ, 1 GB DDR Memory, 80 GB Hard Drive, WinXP Home Edition with Latest Patch, Creative labs Audigy Sound Blaster Platinum Sound Card, Geforce 3 Graphics card with 52.16 drivers
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: GetSystemMetrics

Post by PB »

> ScreenX = GetSystemMetrics_(SM_CXSCREEN)
> ScreenY = GetSystemMetrics_(SM_CYSCREEN)

You're supposed to use #SM_CXSCREEN and #SM_CYSCREEN,
with no need to declare them because PureBasic already knows them.
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Re: GetSystemMetrics

Post by einander »

In WinXP, I've found that #SM_CXSCREEN AND _#SM_CYSCREEN are 8 and 62 pixs longer than the screen :?:

Code: Select all

_X=GetSystemMetrics_(#SM_CXSCREEN)-8 : _Y=GetSystemMetrics_(#SM_CYSCREEN)-62
hWnd=OpenWindow(0,0,0,_X,_Y,#WS_OVERLAPPEDWINDOW,"") 
Repeat
    Event = WaitWindowEvent()
Until Event= #PB_Event_CloseWindow 
End  


Einander
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: GetSystemMetrics

Post by PB »

> In WinXP, I've found that #SM_CXSCREEN AND _#SM_CYSCREEN are
> 8 and 62 pixs longer than the screen

No, you're just misunderstanding how the OpenWindow command works.
The X and Y values that you specified are for the inner client area of the
window, and NOT the outer borders of the window. This was needed to
support XP's skinning ability, and it's in the PureBasic docs. :wink:

The following shows the exact Desktop size as expected:

Code: Select all

Debug GetSystemMetrics_(#SM_CXSCREEN)
Debug GetSystemMetrics_(#SM_CYSCREEN)
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Re: GetSystemMetrics

Post by einander »

Thanx PB for your explanation! :)

Einander
Post Reply