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. Moving Windows

Moving Windows

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelplounge
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.
  • D Offline
    D Offline
    DougW48
    wrote on last edited by
    #1

    I'm trying to align static text windows on a CFormView dialog. I used the visual editor, but sometimes there's a larger gap between text windows than others, so I want to make this even. I've tried to adjust the window positions in the OnInitialUpdate function. The confusing part to me is that the following 4 lines end up putting my static text window in random places within my application. Between the 3rd and 4th lines of code I would obviously adjust the CRect borders, but I was hoping somebody could give me a reason as to how and why these lines of code cause my window to appear (if it shows at all) in random locations within my dialog. How can I fix this? Thanks a ton!!! :-D CWnd * MyWindow = GetDlgItem( NUMBER_STATIC ); ASSERT( NUMBER_STATIC ); MyWindow->GetWindowRect( &WindowRect ); MyWindow->MoveWindow( &WindowRect ); Douglas A. Wright dawrigh3@kent.edu

    B D 2 Replies Last reply
    0
    • D DougW48

      I'm trying to align static text windows on a CFormView dialog. I used the visual editor, but sometimes there's a larger gap between text windows than others, so I want to make this even. I've tried to adjust the window positions in the OnInitialUpdate function. The confusing part to me is that the following 4 lines end up putting my static text window in random places within my application. Between the 3rd and 4th lines of code I would obviously adjust the CRect borders, but I was hoping somebody could give me a reason as to how and why these lines of code cause my window to appear (if it shows at all) in random locations within my dialog. How can I fix this? Thanks a ton!!! :-D CWnd * MyWindow = GetDlgItem( NUMBER_STATIC ); ASSERT( NUMBER_STATIC ); MyWindow->GetWindowRect( &WindowRect ); MyWindow->MoveWindow( &WindowRect ); Douglas A. Wright dawrigh3@kent.edu

      B Offline
      B Offline
      Beer26
      wrote on last edited by
      #2

      you're using GetWindowRect, which is the rect of the window on the screen. GetClientRect would return the control rect on the client x,y BUT, grabbing a rect, then moving the window right back to the same position will do absolutely nothing, even if you do it right.

      1 Reply Last reply
      0
      • D DougW48

        I'm trying to align static text windows on a CFormView dialog. I used the visual editor, but sometimes there's a larger gap between text windows than others, so I want to make this even. I've tried to adjust the window positions in the OnInitialUpdate function. The confusing part to me is that the following 4 lines end up putting my static text window in random places within my application. Between the 3rd and 4th lines of code I would obviously adjust the CRect borders, but I was hoping somebody could give me a reason as to how and why these lines of code cause my window to appear (if it shows at all) in random locations within my dialog. How can I fix this? Thanks a ton!!! :-D CWnd * MyWindow = GetDlgItem( NUMBER_STATIC ); ASSERT( NUMBER_STATIC ); MyWindow->GetWindowRect( &WindowRect ); MyWindow->MoveWindow( &WindowRect ); Douglas A. Wright dawrigh3@kent.edu

        D Offline
        D Offline
        Dave Bryant
        wrote on last edited by
        #3

        GetWindowRect() retrieves the window position in screen co-ordinates (i.e. 0,0 is the top-left corner of the screen. MoveWindow() moves the window to the specified client co-ordinates of its parent window (i.e. 0,0 is the top-left corner of the parent window). You need to peform a conversion between the screen and client co-ordinates before moving the window as follows: MyWindow->GetWindowRect( &WindowRect ); ScreenToClient( &WindowRect ); // Adjust the position here... MyWindow->MoveWindow( &WindowRect ); Dave http://www.cloudsofheaven.org

        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