Is the origin reset...

This is a discussion on Is the origin reset... within the Windows Programming forums, part of the Platform Specific Boards category; ...to 0,0 when the window is resized? I'm learning windows programming and I'm working on a practice program that uses ...

  1. #1
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176

    Is the origin reset...

    ...to 0,0 when the window is resized?

    I'm learning windows programming and I'm working on a practice program that uses scroll bars. The only problem is that when the window is resized, the view shifts back to the upper left corner instead of remaining where it was scrolled to. After reviewing my program several times (becoming more and more frustrated), the only thing I can come up with is that Windows resets the origin to 0,0. Is this true, or do I need to keep looking for a problem in my program? I've looked around for some sort of documentation that says Yes or No but I've come up empty.

    Thanks,
    fletch
    "Logic is the art of going wrong with confidence."
    Morris Kline

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    Why don't you post some of the code so we can see what is going on.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    Sorry, all of you hardcore API programmers - it's MFC
    Here are the portions I believe to be applicable: the OnSize and OnPaint message handlers.
    Code:
    void RulerMainWindow::OnSize(UINT nType, int cx, int cy)
    {
    	SCROLLINFO	ScrollBarData;
    	CClientDC	RulerWindow(this);
    	CPoint		Origin = RulerWindow.GetWindowOrg();
    
    // Using debug, I've determined that Origin.x and 
    // Origin.y both equal 0 at this point
    
    	if (cx < 1400)	// If insufficient horizontal space, create scroll bar
    	{
    		ScrollBarData.fMask = SIF_ALL;
    		ScrollBarData.nMin = 0;
    		ScrollBarData.nMax = 1399;
    		ScrollBarData.nPage = cx;
    		ScrollBarData.nPos = Origin.x;
    		SetScrollInfo(SB_HORZ, &ScrollBarData, TRUE);
    	}
    	else		// If too much horizontal space, no scroll bar for you!
    	{
    		ScrollBarData.fMask = SIF_RANGE;
    		ScrollBarData.nMin = 0;
    		ScrollBarData.nMax = 0;
    		SetScrollInfo(SB_HORZ, &ScrollBarData, TRUE);
    	}
    
    	if (cy < 300)	// If insufficient vertical space
    	{
    		ScrollBarData.fMask = SIF_ALL;
    		ScrollBarData.nMin = 0;
    		ScrollBarData.nMax = 299;
    		ScrollBarData.nPage = cy;
    		ScrollBarData.nPos = (Origin.y * -1);
    		SetScrollInfo(SB_VERT, &ScrollBarData, TRUE);
    	}
    	else		// If too much vertical space
    	{
    		ScrollBarData.fMask = SIF_RANGE;
    		ScrollBarData.nMin = 0;
    		ScrollBarData.nMax = 0;
    		SetScrollInfo(SB_VERT, &ScrollBarData, TRUE);
    	}
    }
    Code:
    void RulerMainWindow::OnPaint()
    {
    	int		Counter;
    	CPaintDC	RulerWindow(this);			
    	CBrush		RulerBrush(RGB(255,255,0));	
    	CString		RulerText;
    	SCROLLINFO	ScrollBarData;
    	CPoint		Origin;
    
    	RulerWindow.SetMapMode(MM_LOENGLISH);	// Change logical mapping mode
    	RulerWindow.SelectObject(&RulerBrush);	// Set yellow brush
    	RulerWindow.SetBkMode(TRANSPARENT);	// Set background to transparent
    	RulerWindow.SetTextAlign(TA_CENTER | TA_BOTTOM);
    
    	GetScrollInfo(SB_VERT, &ScrollBarData, SIF_ALL);  // Get positional data from scroll bars
    	Origin.y = (ScrollBarData.nPos * -1);
            GetScrollInfo(SB_HORZ, &ScrollBarData, SIF_ALL);
    	Origin.x = ScrollBarData.nPos;
    	RulerWindow.SetWindowOrg(Origin);            // and move origin
    
    
    	RulerWindow.Rectangle(100, -100, 1300, -200);
    // A whole bunch of drawing that I removed for space
    }
    I remarked in the OnSize message handler where I've used debug to determine the value of Origin. That's the chief reason why I think that Windows resets the origin when the window is resized.
    If you want more code, I'll upload the whole thing. Thanks again.

    fletch
    "Logic is the art of going wrong with confidence."
    Morris Kline

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    ...the only thing I can come up with is that Windows resets the origin to 0,0. Is this true...?
    Yes.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    That's what I figured, but I couldn't find it written down, so I decided to ask the professionals before I worked around it.

    Anyways, I modified my program and it now works like a champ.

    Thanks,
    fletch
    "Logic is the art of going wrong with confidence."
    Morris Kline

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to reset variables
    By matrixx333 in forum C Programming
    Replies: 19
    Last Post: 03-21-2009, 01:18 PM
  2. Fixing bug in Quake 2 Engine!
    By hajas in forum Game Programming
    Replies: 4
    Last Post: 06-22-2007, 11:12 AM
  3. strtok reset
    By lavinpj1 in forum C Programming
    Replies: 3
    Last Post: 04-25-2006, 07:00 PM
  4. Reloading Meshes on Device Reset
    By Epo in forum Game Programming
    Replies: 6
    Last Post: 05-30-2005, 05:21 PM
  5. Direct3D won't reset
    By Magos in forum Game Programming
    Replies: 1
    Last Post: 05-10-2004, 02:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21