yogesh28577
asked on
How Blinking Text IN MFC on CDC
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?
associated Textout() function to display text on the screen.
Is there any way of making the text blink?
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
ASKER
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
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_
}
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
SetTimer(IDT_WINDOW_TIMER_
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
SetTimer(IDT_WINDOW_TIMER_
}
CWnd::OnTimer(nIDEvent);
}
in this text are blinking on disp device
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
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
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
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
ASKER
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(CChildVi ew,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(<ime);
final=initial+t;
while (time(<ime) < final);
return 1;
}
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(CChildVi
//{{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(<ime);
final=initial+t;
while (time(<ime) < final);
return 1;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hello yogesh28577 ,
Do have any more questions ?.
Cheers,
Sebastia
Do have any more questions ?.
Cheers,
Sebastia
ASKER
plz give me yahoo messager id i want to chat with u
Sorry I don't have an account there ...
Go ahead, ask me here at EE :-)
Cheers,
Sebastian
Go ahead, ask me here at EE :-)
Cheers,
Sebastian
ASKER
ok
https://www.experts-exchange.com/questions/21834593/String-Manipulation.html