Link to home
Start Free TrialLog in
Avatar of janiv
janiv

asked on

Scrolling text in CDialogBar

Hi,
I have a dockable dialog bar, which contains a CDialog with IDC_STATIC.
I have a stack with many messages.
I want to scroll from left to right, message by message.
I want the first letter of each message to appear first(in the right most column of the Dialog bar), and the last letter to appear at the left most column of the window.
After the last letter appears in the left most column, I want the next message to appear from the right most column.

How do I do it ?
10x,
Janiv Ratson

More help:
Imagine I have a flight simulator, and the pilto has a CControlBar that appears for every message, and
display the current message.
If more than one message is sent, I should display them all. Each one in its turn (no way 2 strings
will be displayed togheter).
When there R no messages, the controlBar should dissappear.



I'd be glad 2 answer your questions about it.


ASKER CERTIFIED SOLUTION
Avatar of MadYugoslav
MadYugoslav
Flag of Serbia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of janiv
janiv

ASKER

Yes the message is a text message, inserted into IDC_STATIC !

I want to display message in the CDialog (my CMsgBoard:public CDialog class), which is a window inside my CSimControlBar (:public CControlBar).

First change IDC_STATIC id in something else for example in IDC_MESSAGE_TEXT. This is for enable accessing control window.
If You want messages to be scrolled automaticly Override Ontimer and install some timer in oninitdialog.
In ontimer function parse messages and use SetDlgItemText() to set message text in your control.

Post any comments if this is not what You want.
Avatar of janiv

ASKER

SetDlgItemText with what text ?
on the first frame I want only the first letter to appear ,
on the second 2 letters, on the fifth frame I wanna show 5 letters and so on ... (Scrolling)

How do I know how many scrolls to do ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Make your CStatic text control to be right aligned.
Supose that your current message is in CString variable
with name Message.

Then your OnTimer function should stay:

void CMyDialog::OnTimer(UINT nIDEvent)
{
   if( nIDEvent == 0xFF )// Your timer event
   {
      CString Str;
      GetDlgItemText(IDC_TEXT, Str);
      int Curr=Str.GetLength();
      if( Curr < Message.GetLength() )
         SetDlgItemText(IDC_TEXT, Message.Left(Curr+1));
      else
         SetDlgItemText(IDC_TEXT, "");
   }
   else
      CDialog::OnTimer(nIDEvent);
}
Avatar of janiv

ASKER

BeyondWu,
The example is fine...
But I need every string to appear from the begining, and not concatinating it.
Every string need to be fully scrolled (from left to right) before the next string appears.

MadYuqoslva, this is not what I'm looking for ...

More help:
Imagine I have a flight simulator, and the pilto has a CControlBar that appears for every message, and display the current message.
If more than one message is sent, I should display them all. Each one in its turn (no way 2 strings will be displayed togheter).
When there R no messages, the controlBar should dissappear.

I hope it's clearer now.
This is what You want (scroll for 10 logical units):
You need to somewhere save current x position (initial value is 0) CurrX.

// Function for draw text
int DrawText(CDC* pDC, int x, int y, const char* Str, int Len, int Height, BOOL DrawFlag)
{
   int DC=pDC->SaveDC();
   SetOutputFont(pDC, Height);
   pDC->SetTextColor(0);
   CSize Size=pDC->GetTextExtent(Str, Len);
   if( DrawFlag )
      pDC->TextOut(x, y, Str, Len);
   pDC->RestoreDC(DC);
   return(Size.cx);
}
void CMyDialog::OnTimer(UINT nIDEvent)
{
   if( nIDEvent = 0xFF )
   {
      CWnd* Win=GetDlgItem(IDC_TEXT);
      CDC* pDC=Win->GetDC();
      RECT Rect;
      Win->GetClientRect(&Rect);
      {
         pDC->BeginPath();
         pDC->Rectangle(&Rect);
         pDC->EndPath();
         pDC->SelectClipPath(RGN_COPY);
      }
      pDC->FillSolidRect(&Rect, RGB(255, 255, 255));
      int x=CurrX;
      int Size=DrawText(pDC, 0, 0, LPCTSTR(Message), Message.GetLength(), 20, FALSE);
      if( x < (Size+Rect.right) )
      {
         DrawText(pDC, Rect.right-x, 0, LPCTSTR(Message), Message.GetLength(), 20, TRUE);
         CurrX+=10;
      }
      else
         CurrX=0;
      Win->ReleaseDC(pDC);
   }
   else
      CDialog::OnTimer(nIDEvent);
}
Is it OK ?
Avatar of janiv

ASKER

MadYugoslav, I'm sorry I wanna check it, but I have no clue how to use the timer mechanism.
Can U help me ?

Demo project will be gladly accepted.

Also, FYI , now I'm using ScrollWindow method for scrolling,
my problems are:

1. How to insert the first character from the right most column ?

2. How to know till when to scroll ?

3. How to return the window to the starting position ?
And what about original question ?
Avatar of janiv

ASKER

It is the same problem ...
Nothing has been changed but my explanation ...
Avatar of janiv

ASKER

How do U call DrawText ?
How do U set the timer ?
A little bit help is needed ...
10x,
Janiv Ratson
Avatar of janiv

ASKER

Ho Such function: SetOutputFont(pDC, Height);
Avatar of janiv

ASKER

Yes I did, it is not what I'm looking for ...
Avatar of DanRollins
hi janiv,
Are you still seeking help with this Question?

-- Dan
Avatar of janiv

ASKER

Yes, I still looking for help.
10x,
J
Having read the full question and follow-up comments, I think you may have mis-stated the question.  When youi said:

>> I want to scroll from left to right, message by message

I think you really mean that you want the messages to scroll from right to left.

I can easily write that routine in one of two ways.  I think that the way that you described it would be awkward.  That is, if the first message started scrolling in from the right, one letter at-a-time, it would be tedious.  The user would need to wait quite a while in order to see the entire text.  You further explain that you want that first message to scroll all of the way off, until it has disappeared completely before starting the next (tedious) letter-by-letter scrolling -- again the user would need to twiddle his thumbs waiting for the meaning of the next message to be clear.

A more expected way to do it would be to place the first string entirely into view immediately.  Then delay for one or two seconds. The start scrolling it.  After the entire message is visible, it continues to scroll.  But rather than waiting until it is entirely off-screen, you could start scrolling in the next message onece the first message was, for instance, half-way across.

Your 'flight simulator' example reinforces my point.  A pilot would *not* want to wait a long time in order to understand the message.  THe piolot needs to see the full meaning of the message as soon as possible.  Here is an example message:

"Your heading is 143 by 234 at 600 Nautical miles per hour.  At this heading and rate you will collide into a mountain in 10 seconds."

By the time the full message is visible, the pilot is dead.

Is this specification clear?  Do you want to see program code that implements this the way that I have described?

-- Dan
hi janiv,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: MadYugoslav, BeyondWu (points to be split)

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer