Solved

How to set the text blinking?

Posted on 1998-10-15
3
279 Views
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.
0
Comment
Question by:softyan
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 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

0
 

Author Comment

by:softyan
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!
0
 
LVL 8

Expert Comment

by:Answers2000
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 ;

- in WM_INITDIALOG
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
0

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

Suggested Solutions

Title # Comments Views Activity
Inorder binary search tree 5 179
valid enum? 6 75
Using popen() and gunzip() to open file in HTTPServer 6 75
What is sub-make ? 2 88
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files 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.

733 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