Solved

How Blinking Text IN MFC on CDC

Posted on 2006-07-04
13
1,174 Views
Last Modified: 2008-01-09
I am using the CDC Class from the MFC class library and the
 associated Textout() function to display text on the screen.
 Is there any way of making the text blink?

0
Comment
Question by:yogesh28577
  • 6
  • 4
13 Comments
 
LVL 8

Expert Comment

by:kaliyugkaarjun
ID: 17036477
0
 
LVL 5

Expert Comment

by:bastibartel
ID: 17037914

Add a message handler for the WM_TIMER message (class wizard)
Launch the timer in OnInitDialog

#define ID_MY_BLINKER (WM_USER+1)

BOOL CMyClass::OnInitiDialog()
{
   /* ...*/
   SetTimer(ID_MY_BLINKER, 1000, NULL);  // blink every 1000 ms
}

void CMyClass::OnTimer(UINT nIDEvent)
{
             if (nIDEvent == ID_MY_BLINKER)
             {
                  static bool IsOn = true;
                  IsOn ^= true;              // toggle true/false;

                  DCD *dc = GetDC();

                  if (IsOn´)
                      dc->TextOut("hello", ...
                   else
                      dc->TextOut("world", ...
                 
                    ReleaseDC(dc);
               }
               else
                   CDialog::OnTimer(nIDEvent)
}

Excuse any syntax errors - cannot compile on this machine
Cheers Sebastian
0
 
LVL 1

Author Comment

by:yogesh28577
ID: 17041742
i got solution on my problem
first define two timer
#define IDT_WINDOW_TIMER_1 100
#define IDT_WINDOW_TIMER_2 101

in paint events add following lines
void CChildView::OnPaint()
{
CPaintDC dc(this);

SetTimer(IDT_WINDOW_TIMER_1, 50, NULL);      
}
add following code to ontimer

void CChildView::OnTimer(UINT nIDEvent)
 {
CClientDC dc(this);

 switch(nIDEvent)
 {

 case  IDT_WINDOW_TIMER_1:

      
      str="Yogesh Shrikhande ";
      
            dc.TextOut ( 200, 100, str) ;
            
KillTimer(IDT_WINDOW_TIMER_1);
       SetTimer(IDT_WINDOW_TIMER_2, 50, NULL);      



break;
case      IDT_WINDOW_TIMER_2:

int l;
l=str.GetLength();       
s.Format("%d",l) ;
str.Empty();
for (int i=0;i<=l*2;i++)
str=str+" ";
dc.TextOut ( 200, 100,str) ;
KillTimer(IDT_WINDOW_TIMER_2);
SetTimer(IDT_WINDOW_TIMER_1, 100, NULL);

 }
CWnd::OnTimer(nIDEvent);
 }

in this text are blinking on disp device
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 5

Expert Comment

by:bastibartel
ID: 17041782
That's my code .. only a bit longer ;-)
You should call ReleaseDC() after using the dc.
Maybe it's better to set the timer in CWnd::OnCreate() - as it is, it will restart on every WM_PAINT notification

Cheers,
Sebastian
0
 
LVL 5

Expert Comment

by:bastibartel
ID: 17047115
Hi yogesh28577

Do you have any more questions on the code ?
and did you think of the ReleaseDC() ?

If you have no more comments you should finalize the question.

Cheers,
Sebastian
0
 
LVL 1

Author Comment

by:yogesh28577
ID: 17049292
hi bastibartel
plz tell me how to use ReleaseDc()
in my program

i have also another method with out using timer but after some time it gives error


// ChildView.cpp : implementation of the CChildView class
//

#include "stdafx.h"
#include "Rotating.h"
#include "ChildView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CString str;

/////////////////////////////////////////////////////////////////////////////
// CChildView

CChildView::CChildView()
{
}

CChildView::~CChildView()
{
}


BEGIN_MESSAGE_MAP(CChildView,CWnd )
      //{{AFX_MSG_MAP(CChildView)
      ON_WM_PAINT()      
      ON_WM_CREATE()
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CChildView message handlers



void CChildView::OnPaint()
{
CPaintDC dc(this);

disp();

}

void CChildView::disp()
 {

CClientDC dc(this);

str="Yogesh Shrikhande";
dc.TextOut ( 200, 100, str) ;
time1(.1);

disp1();

}
void CChildView::disp1()
{
CString s;
CClientDC dc(this);
int l;
l=str.GetLength();       
s.Format("%d",l) ;
str.Empty();
for (int i=0;i<=l*2;i++)
str=str+" ";
dc.TextOut ( 200, 100,str) ;
time1(.1);
disp();

 }
int CChildView::time1(int t)
{


  long initial,final;
  long ltime;

  initial=time(&ltime);
  final=initial+t;

  while (time(&ltime) < final);
  return 1;

}



0
 
LVL 5

Accepted Solution

by:
bastibartel earned 60 total points
ID: 17049351
Hi there,

Because you are now using CClientDC dc(this), there is no need for ReleaseDC() (my mistake!).
ReleaseDC() will be called when 'dc' is destroyed.

Otherwise it would be
DCD *dc = GetDC();
dc.SetText(...)
ReleaseDC(dc);   // free this DC so others can use it

But there are some other things:

1.
the call time1(.1) passes 0.1 to the time1 function, which converts to integer t=0.
So in time1(int t) the while-loop is never executed.

Instead use the Sleep function
Sleep(1000); waits 1000 milliseconds.

2.
In CChildView::OnPaint()

I guess disp() does the painting.
You should pass the dc to disp(), because it will need it to paint into. It's unneccessary to get yet another handle to the dc in disp().

Cheers,
Sebastian



 



 
0
 
LVL 5

Expert Comment

by:bastibartel
ID: 17062787
Hello yogesh28577 ,

Do have any more questions ?.

Cheers,
Sebastia
0
 
LVL 1

Author Comment

by:yogesh28577
ID: 17063792
plz give me yahoo messager id i want to chat with u
0
 
LVL 5

Expert Comment

by:bastibartel
ID: 17069495
Sorry I don't have an account there ...
Go ahead, ask me here at EE :-)

Cheers,
Sebastian
0
 
LVL 1

Author Comment

by:yogesh28577
ID: 17152996
ok
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mapBully challenge 6 134
Device same like our heart 12 85
C# DataGridView_RowsAdded event not firing 1 75
Beginner to Unreal Engine 4 5 80
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This is about my first experience with programming Arduino.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

778 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