Solved

Scrolling text in CDialogBar

Posted on 2001-07-03
21
274 Views
Last Modified: 2013-11-20
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.


0
Comment
Question by:janiv
  • 9
  • 6
  • 3
  • +3
21 Comments
 
LVL 2

Accepted Solution

by:
MadYugoslav earned 118 total points
Comment Utility
Is message text ?
Where do you want to display message (in some control) ?
0
 

Author Comment

by:janiv
Comment Utility
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).

0
 
LVL 2

Expert Comment

by:MadYugoslav
Comment Utility
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.
0
 

Author Comment

by:janiv
Comment Utility
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 ?
0
 
LVL 9

Assisted Solution

by:BeyondWu
BeyondWu earned 117 total points
Comment Utility
0
 
LVL 2

Expert Comment

by:MadYugoslav
Comment Utility
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);
}
0
 

Author Comment

by:janiv
Comment Utility
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.
0
 
LVL 2

Expert Comment

by:MadYugoslav
Comment Utility
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);
}
0
 
LVL 2

Expert Comment

by:MadYugoslav
Comment Utility
Is it OK ?
0
 

Author Comment

by:janiv
Comment Utility
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 ?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 2

Expert Comment

by:MadYugoslav
Comment Utility
And what about original question ?
0
 

Author Comment

by:janiv
Comment Utility
It is the same problem ...
Nothing has been changed but my explanation ...
0
 

Author Comment

by:janiv
Comment Utility
How do U call DrawText ?
How do U set the timer ?
A little bit help is needed ...
10x,
Janiv Ratson
0
 

Author Comment

by:janiv
Comment Utility
Ho Such function: SetOutputFont(pDC, Height);
0
 
LVL 12

Expert Comment

by:migel
Comment Utility
0
 

Author Comment

by:janiv
Comment Utility
Yes I did, it is not what I'm looking for ...
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
hi janiv,
Are you still seeking help with this Question?

-- Dan
0
 

Author Comment

by:janiv
Comment Utility
Yes, I still looking for help.
10x,
J
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
hi janiv,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
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
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now