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. SetWindowPos & GetWindowRect

SetWindowPos & GetWindowRect

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
3 Posts 3 Posters 0 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.
  • M Offline
    M Offline
    Mr Simple
    wrote on last edited by
    #1

    Hi, I am trying to resize 2 CButtons at runtime, but am having a really hard time getting them to appear in the correct place. GetWindowRect gives me values that are offset to the dialog. To demonstrate, the code i am using is something like the following; CRect btnRect; btn1.GetWindowRect(btnRect); ::SetWindowPos(btn1.m_hwnd, btnRect.left, btnRect.top, btnRect.Width(), btnRect.Height(), SWP_SHOWWINDOW); This results in the button moving diagonally across the screen, it doesnt stay still, which is what I would have expected. I find that if i take away (rectDialog.left + 3) and (rectDialog.top + 29) from btnRect.left and .top it will work (stay still). I assume the '3' is the width of the boarder, and '29' the height of the title bar. Is this correct? If so, how can I find it programatically? Thank you very much for your help.

    M R 2 Replies Last reply
    0
    • M Mr Simple

      Hi, I am trying to resize 2 CButtons at runtime, but am having a really hard time getting them to appear in the correct place. GetWindowRect gives me values that are offset to the dialog. To demonstrate, the code i am using is something like the following; CRect btnRect; btn1.GetWindowRect(btnRect); ::SetWindowPos(btn1.m_hwnd, btnRect.left, btnRect.top, btnRect.Width(), btnRect.Height(), SWP_SHOWWINDOW); This results in the button moving diagonally across the screen, it doesnt stay still, which is what I would have expected. I find that if i take away (rectDialog.left + 3) and (rectDialog.top + 29) from btnRect.left and .top it will work (stay still). I assume the '3' is the width of the boarder, and '29' the height of the title bar. Is this correct? If so, how can I find it programatically? Thank you very much for your help.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      SetWindowPos coordinates for child windows are relative to the client area of the parent window. You are using window coordinates relative to the screen. Try GetClientRect instead of GetWindowRect. What Roger said :) Also, MoveWindow is simpler and more appropriate for this than SetWindowPos. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      • M Mr Simple

        Hi, I am trying to resize 2 CButtons at runtime, but am having a really hard time getting them to appear in the correct place. GetWindowRect gives me values that are offset to the dialog. To demonstrate, the code i am using is something like the following; CRect btnRect; btn1.GetWindowRect(btnRect); ::SetWindowPos(btn1.m_hwnd, btnRect.left, btnRect.top, btnRect.Width(), btnRect.Height(), SWP_SHOWWINDOW); This results in the button moving diagonally across the screen, it doesnt stay still, which is what I would have expected. I find that if i take away (rectDialog.left + 3) and (rectDialog.top + 29) from btnRect.left and .top it will work (stay still). I assume the '3' is the width of the boarder, and '29' the height of the title bar. Is this correct? If so, how can I find it programatically? Thank you very much for your help.

        R Offline
        R Offline
        Roger Broomfield
        wrote on last edited by
        #3

        MapWindowPoints() or ScreenToClient() CRect btnRect; btn1.GetWindowRect(btnRect); ScreenToClient(&btnRect); //assumes that this is the parent of btn1 btn1.SetWindowPos(wndTop, btnRect.left, btnRect.top, btnRect.Width(), btnRect.Height(), SWP_SHOWWINDOW);

        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