I wish my single document, scroll view based, application (VC++6.0) to
open up with the scroll view set to a particular position (bottom left
of the document instead of top left).
I set the SetScrollPosition command into the InitialUpdate of the view
but it seems that when the application starts the document is not yet
constructed.
I also tried to send a message from the InitialUpdate to the view itself
in order to process the command afterwards, but to no avail.
Where is the correct place where I can call the SetScrollPosition
function in order to have my application to open up an empty document
with the view set to the position I want ?
Cheers,
Giulio
Giulio:
There is something a bit messed up about the initialization of SDI applications,
but I am not quite sure what you mean here.
When you say the "document is not yet constructed" in OnInitialUpdate, what do
you mean? Does GetDocument() return NULL?
I don't think it should be necessary here, but to get a delayed reaction as you
desire you should use PostMessage() not SendMessage().
Also, if the document is empty, why do you need scrollbars?
--
David Wilkinson
Visual C++ MVP
> There is something a bit messed up about the initialization of SDI
> applications, but I am not quite sure what you mean here.
>
> When you say the "document is not yet constructed" in OnInitialUpdate,
> what do you mean? Does GetDocument() return NULL?
>
No, simply that if I call ScrollToPosition in OnInitialUpdate, the view
lands into incorrect coordinates (don't know why). This makes me think
that the document is not fully constructed yet.
The codes is as follows:
void CPPViewerView::RecalcDoc()
{
CSize sizeTotal = ComputeDocSize();
SetScrollSizes(MM_TEXT, sizeTotal);
Invalidate();
}
void CPPViewerView::OnInitialUpdate()
{
CPPViewerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CScrollView::OnInitialUpdate();
RecalcDoc(); // computes doc view size
// get current position
CPoint p = GetScrollPosition();
// set the y coord to the bottom
CSize sizeTotal = ComputeDocSize();
p.y = sizeTotal.cy;
// ok, scroll document, but doesn't work!
ScrollToPosition(p);
UpdateSeqBar();
}
> I don't think it should be necessary here, but to get a delayed reaction
> as you desire you should use PostMessage() not SendMessage().
>
Good, it seems to work with PostMessage, thank you!
> Also, if the document is empty, why do you need scrollbars?
>
The app. shows the cartesian axes on bottom left. Since by default the
document is larger than the view, I want on startup with the X and Y
axis visible, therefore I need the view to be scrolled bottom left.
Thanks,
Giulio.