Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. accounting for the scrollbar GetSystemMetrics(SM_CYBORDER)

accounting for the scrollbar GetSystemMetrics(SM_CYBORDER)

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 2 Offline
    2 Offline
    23_444
    wrote on last edited by
    #1

    Do I need to incorporate SM_CYBORDER to catch the border of the horizontal scrollbar or is this value inclusive in SM_CYHSCROLL? Here is why I am asking I have a window that I need to know the client height if a scrollbar is present. (horiz scrollbar is not set yet) GetClientRect returns 292. Using ::GetSystemMetrics(SM_CYHSCROLL) + ::GetSystemMetrics(SM_CYBORDER) returns 21. Therefore, the window will have a client height of 271 when this window gets a scrollbar. After the horizontal scrollbar is set I use GetClientRect (which should return 271) It returns 272. Do I need to incorporate SM_CYBORDER to catch the border of the horizontal scrollbar or is this value inclusive in SM_CYHSCROLL? GetClientRect is off by one pixel when scrollbar is present MSDN says SM_CYBORDER = Width and height, in pixels, of a window border. But it doesn't say whether this is already included in the SM_CYHSCROLL value. I saw some code that uses both to determine the scrollbar size so its messing with my head. That pixel may be a misunderstanding of some other factor. Thanks

    G 1 Reply Last reply
    0
    • 2 23_444

      Do I need to incorporate SM_CYBORDER to catch the border of the horizontal scrollbar or is this value inclusive in SM_CYHSCROLL? Here is why I am asking I have a window that I need to know the client height if a scrollbar is present. (horiz scrollbar is not set yet) GetClientRect returns 292. Using ::GetSystemMetrics(SM_CYHSCROLL) + ::GetSystemMetrics(SM_CYBORDER) returns 21. Therefore, the window will have a client height of 271 when this window gets a scrollbar. After the horizontal scrollbar is set I use GetClientRect (which should return 271) It returns 272. Do I need to incorporate SM_CYBORDER to catch the border of the horizontal scrollbar or is this value inclusive in SM_CYHSCROLL? GetClientRect is off by one pixel when scrollbar is present MSDN says SM_CYBORDER = Width and height, in pixels, of a window border. But it doesn't say whether this is already included in the SM_CYHSCROLL value. I saw some code that uses both to determine the scrollbar size so its messing with my head. That pixel may be a misunderstanding of some other factor. Thanks

      G Offline
      G Offline
      Gwenio
      wrote on last edited by
      #2

      I think I see where the problem is: the original client height (292) does not include the border, therefore when you subtract (::GetSystemMetrics(SM_CYHSCROLL) + ::GetSystemMetrics(SM_CYBORDER)) from it, you get a value smaller than the real client area. Summary: the border had already been subracted from the client height, and you subtracted it again. 272 is the correct value for the height in this case.

      2 1 Reply Last reply
      0
      • G Gwenio

        I think I see where the problem is: the original client height (292) does not include the border, therefore when you subtract (::GetSystemMetrics(SM_CYHSCROLL) + ::GetSystemMetrics(SM_CYBORDER)) from it, you get a value smaller than the real client area. Summary: the border had already been subracted from the client height, and you subtracted it again. 272 is the correct value for the height in this case.

        2 Offline
        2 Offline
        23_444
        wrote on last edited by
        #3

        Thanks for the response, I appreciate it. The question is really this. When people/you/me account for scrollbars, do we also need to account for the border of the scrollbar with GetSystemMetrics(SM_CYBORDER)? The border I think you were talking about is the border of the client window which I realize I don't need to subtract. (::GetSystemMetrics(SM_CYHSCROLL) Does this include the entire scrollbar (bar + borders of scrollbar)? It appears to. It's just that I saw some code in which the programmer subtracted the border (GetSystemMetrics(SM_CYBORDER))in addition to the scrollbar and so I'm wondering why they did it. Thanks again.

        G 1 Reply Last reply
        0
        • 2 23_444

          Thanks for the response, I appreciate it. The question is really this. When people/you/me account for scrollbars, do we also need to account for the border of the scrollbar with GetSystemMetrics(SM_CYBORDER)? The border I think you were talking about is the border of the client window which I realize I don't need to subtract. (::GetSystemMetrics(SM_CYHSCROLL) Does this include the entire scrollbar (bar + borders of scrollbar)? It appears to. It's just that I saw some code in which the programmer subtracted the border (GetSystemMetrics(SM_CYBORDER))in addition to the scrollbar and so I'm wondering why they did it. Thanks again.

          G Offline
          G Offline
          Gwenio
          wrote on last edited by
          #4

          No, you do not have to account for the scrollbar's border, and my previous statement should alude to this (I think?). The best way to test something like this (in my opinion) is to Use FillRect for what you believe to be the correct client area, and see if it covers only the real client area.

          2 1 Reply Last reply
          0
          • G Gwenio

            No, you do not have to account for the scrollbar's border, and my previous statement should alude to this (I think?). The best way to test something like this (in my opinion) is to Use FillRect for what you believe to be the correct client area, and see if it covers only the real client area.

            2 Offline
            2 Offline
            23_444
            wrote on last edited by
            #5

            Okay, great. I appreciate your responses. I'll do the FillRect thing and do some testing. Thanks again!

            2 1 Reply Last reply
            0
            • 2 23_444

              Okay, great. I appreciate your responses. I'll do the FillRect thing and do some testing. Thanks again!

              2 Offline
              2 Offline
              23_444
              wrote on last edited by
              #6

              Yep, 272, the value returned from GetRectClient() does correctly account for the scrollbar's presence/absence. Why other people are using GetSystemMetrics(SM_CYBORDER) along with GetSystemMetrics(SM_CYHSCROLL)is beyond me. Using dc.FillSolidRect was a good suggestion and helped me to determine what was going on. Thanks again.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups