Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to set the text blinking?

Posted on 1998-10-15
Medium Priority
Last Modified: 2010-05-18
I want to set the text on my dialog blinking?
How to do it, please help!
I'm not using MFC, but WIN32 SDK.
Question by:softyan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

Answers2000 earned 200 total points
ID: 1253550
Unfortunately there isn't a "flashing" attribute for dialog text under Windows.  This means you have to flash it yourself.

Also unfortunately the FlashWindow API (if you heard of it) is no help.  It simply flashes the window caption.  Assuming you mean a control on the dialog - e.g. a static.  This is no help either.

Okay - here are the steps:
1. Add a static UINT to your dialog which is the Timer Id

static UINT uTimerId = 0 ;

2. Use the SetTimer API call to create a Timer.  Do this  in WM_INITDIALOG.

uTimerId = SetTimer( hDlg, 1, 1000 /* Time in Millisecs */, NULL ) ;

3. Before closing your dialog kill the timer, (e.g. before calling EndDialog in response to the OK button)

if ( uTimerId != 0 )
  KillTimer( hDlg, uTimerId ) ;

4. Process the WM_TIMER message sent to your dialog and causing flashing here.

case WM_TIMER:
  /* Flashing code */

5. What is flashing code - I'll assume you just want to make the a control appear/reappear.  If yes - try this

HWND hWndItem = GetDlgItem( hDlg, ID_CONTROL ) ; /* ID_CONTROL = the id of the control - e.g. a static - to link
if ( IsWindowVisible(hWndItem) )
   ShowWindow(  hWndItem, SW_HIDE ) ;
} else
   ShowWindow( hWndItem, SW_SHOW ) ;

If you don't like #5 change the code to cause whatever kind of flashing you want


Author Comment

ID: 1253551
Can i ask u a question?
Your suggestion is great, but how if i want to change the colour of the static text?
I will increase the point to 70 if u can give me a guide!

Expert Comment

ID: 1253552
You can't increase the pts - as you've already accepted it!

To change the color process the WM_CTLCOLORSTATIC message

To make it flash:
- use my code above

- add variables to dlg proc :-
 static COLORREF m_crText[2] ;
 static COLORREF m_crBack[2] ;
 static HBRUSH m_brush[2] ;
 int m_nWhichColor = 0 ;

m_crText[0] = RGB(255,0,0) ; // red text
m_crText[1] = RGB(0,0,255) ; // blue text
m_crBack[0] = RGB(255,255,255) ; // white background
m_crBack[1] = RGB(0,255,0) ; // green background
m_brush[0] = ::CreateSolidBrush( m_crBack[0] ) ;
m_brush[1] = ::CreateSolidBrush( m_crBack[1] ) ;
m_nWhichColor = 0 ;

- when dialog exits
::DeleteObject( m_brush[0] ) ;
::DeleteObject( m_brush[1] ) ;

- modify step #5 of my original answer

m_nWhichColor ^= 1 ; // flip between 1 and 0
HWND hWndItem = GetDlgItem( hDlg, ID_CONTROL ) ; /* ID_CONTROL = the id of the control - e.g. a static - to link
::InvalidateRect( hWndItem, NULL, FALSE ) ;
::UpdateWindow( hWndItem ) ;

- for WM_CTLCOLORSTATIC, do something like:

HWND hWndItem = GetDlgItem( hDlg, ID_CONTROL ) ;

if ( hWndItem == ((HWND)lParam) )
  pDC->SetTextColor( m_crText[m_nWhichColor] ) ;
  pDC->SetBkColor( m_crBack[m_nWhichColor] ) ;
  return m_brush[m_nWhichColor] ;
// otherwise call DefWndProc

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

722 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