Page 1 of 1

GetSystemMetrics

Posted: Wed Oct 15, 2003 4:57 am
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.

Posted: Wed Oct 15, 2003 5:53 am
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 ??

Posted: Wed Oct 15, 2003 12:13 pm
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)

Posted: Wed Oct 15, 2003 3:33 pm
by Master Games
Thank you Kale and Codemonger, it works now :)

Re: GetSystemMetrics

Posted: Thu Oct 16, 2003 9:33 am
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.

Re: GetSystemMetrics

Posted: Thu Oct 16, 2003 1:06 pm
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

Re: GetSystemMetrics

Posted: Fri Oct 17, 2003 10:35 am
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)

Re: GetSystemMetrics

Posted: Sat Oct 18, 2003 11:33 am
by einander
Thanx PB for your explanation! :)

Einander