Thread: Newbie Question about SetWindowPos()

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    Newbie Question about SetWindowPos()

    Hey people. I'm cutting my teeth with MFC Dialog windows. Currently, I'm trying to have a edit box grow to the right, and move a label for that edit box to match. To this end I have a CEdit object m_ViewPulseCtrl, and a CStatic object m_PulseTotalCtrl. here's the code:

    Code:
    int pulseDigits = 32;
    CRect * calcR = new CRect();
    m_ViewPulseCtrl.GetWindowRect(calcR);			
    m_ViewPulseCtrl.SetWindowPos (NULL, 0, 0, pulseDigits , calcR->bottom - calcR->top, SWP_NOZORDER | SWP_NOMOVE);
    m_PulseTotalCtrl.GetWindowRect(calcR);
    m_PulseTotalCtrl.SetWindowPos (NULL, calcR->left + pulseDigits , calcR->top, 0, 0, SWP_NOZORDER | SWP_NOSIZE );
    m_PulseTotalCtrl.GetWindowRect(calcR);
    Now, the edit box resizes correctly, but the CStatic object flies off into lala land. I tracked the value of calcR in the debugger and got this:

    Code:
    line 4: calcR{top=513 bottom=536 left=218 right=247}
    line 6: calcR{top=620 bottom=633 left=380 right=449}
    what am I doing wrong?

  2. #2
    pwning noobs Zlatko's Avatar
    Join Date
    Jun 2009
    Location
    The Great White North
    Posts
    132
    Hey MadBoat, the pulseDigits is the new width of your text field. You need to slide the label to the right by the change in the width, not the width.

    Code:
    int pulseDigits = 32;
    CRect * calcR = new CRect();
    m_ViewPulseCtrl.GetWindowRect(calcR);            
    
    int deltaWidth = pulseDigits - (calcR->right - calcR->left);
    
    m_ViewPulseCtrl.SetWindowPos (NULL, 0, 0, pulseDigits , calcR->bottom - calcR->top, SWP_NOZORDER | SWP_NOMOVE);
    m_PulseTotalCtrl.GetWindowRect(calcR);
    m_PulseTotalCtrl.SetWindowPos (NULL, calcR->left + deltaWidth , calcR->top, 0, 0, SWP_NOZORDER | SWP_NOSIZE );
    m_PulseTotalCtrl.GetWindowRect(calcR);
    Let me know how that works for you.

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    This really should have been moved to the Windows forum since its a platform specific question. Zlatko is right, you need to move it by the delta, not the absolute.

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    Quote Originally Posted by Zlatko
    Hey MadBoat, the pulseDigits is the new width of your text field. You need to slide the label to the right by the change in the width, not the width.
    You are correct, the code I wrote would move the CStatic too far right. but that doesn't explain the big jump in y value; I'm getting the top value of the CStatic (513), and then setting the top value to 513, then reading it back and discovering top is now 620. All I can think of is, calcR and m_PulseTotalCtrl are representing two different coordinate systems?

    Quote Originally Posted by abachler
    This really should have been moved to the Windows forum since its a platform specific question. Zlatko is right, you need to move it by the delta, not the absolute.
    Sorry about that. I'm confused. the page's navigation bar puts me in the windows programming forum. Did a mod move the thread?

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    oh, nevermind, I got it. Needed a ScreenToClient() call. Thanks guys.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 06:45 PM
  3. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 04:38 PM
  4. confusion with integers (newbie question)
    By imortal in forum C Programming
    Replies: 7
    Last Post: 12-06-2002, 04:09 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM