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