Improve company productivity with a Business Account.Sign Up


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
  • 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

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
There's never been a better time to become a computer scientist. Employment growth in the field is expected to reach 22% overall by 2020, and if you want to get in on the action, it’s a good idea to think about at least minoring in computer science …
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

580 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