EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

#Previous question #Index of VC++/WIN32/MFC Questions #Next question

Text Caret

Caret is a blinking cursor in a window. It displays the current position of the cursor where the input is getting added from user. A textbox or text area control automatically displayes caret. It is the builtin property of the windon. However a custom window application which displayes logs, terminal or console output etc can use caret. Win32 APIs are available to create, distroy, show, hide, set position etc.

CreateCare

CreateCaret() creates a cursor with a size of nWidth x nHeight. It creates a solid cursor if hBitmap is NULL else the bitmap is used for drawing the cursor.

BOOL WINAPI CreateCaret(HWND hWnd, HBITMAP hBitmap, int nWidth, int nHeight);

DestroyCaret

Frees the memory of cursor object and releases the handle

BOOL WINAPI DestroyCaret(void);

GetCaretBlinkTime

Returns the current blink interval time of the cursor in milliseconds. The less the number the more the blink rate.

UINT WINAPI GetCaretBlinkTime(void);

GetCaretPos

Returns the current position of the cursor.

BOOL WINAPI GetCaretPos(LPPOINT lpPoint);

HideCaret

Hides the cursor of the window.

BOOL WINAPI HideCaret(HWND hWnd);

SetCaretBlinkTime

Set the blink time of the caret in miliseconds. The less the time the more the blinking rate.

BOOL WINAPI SetCaretBlinkTime(UINT uMSeconds);

SetCaretPos

SetCaretPos set the caret position in the window

BOOL WINAPI SetCaretPos(int X, int Y);

ShowCaret

ShowCaret shows the blinking caret

BOOL WINAPI ShowCaret(HWND hWnd);

Caret Demo application

Demo aplication showing Create, Destroy, Show, Hide of Caret/Cursor. With UP arrow key, caret blink time is reduced and blink rate increases. With DOWN arrow key, caret blink time is increated and blink rate reduced.
unsigned int nBlinkRate;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  CHAR szTitle[100];
  switch (message) 
  {
    case WM_KEYDOWN:
            if(wParam == VK_UP)
      {
10                nBlinkRate-=10;
11          SetCaretBlinkTime(nBlinkRate);
12          sprintf(szTitle,"Cursor blink rate %d", nBlinkRate);
13          SetWindowText(hWnd,szTitle);
14        }
15              else if(wParam == VK_DOWN)
16        {
17          nBlinkRate+=10;
18          SetCaretBlinkTime(nBlinkRate);
19          sprintf(szTitle,"Cursor blink rate %d", nBlinkRate);
20          SetWindowText(hWnd,szTitle);
21        }
22        break;
23          
24      case WM_DESTROY:
25        PostQuitMessage(0);
26        break;
27      case WM_SETFOCUS:
28          CreateCaret(hWnd, NULL, 12,2);
29        SetCaretPos(0,16);
30        ShowCaret(hWnd);
31        nBlinkRate = GetCaretBlinkTime();
32        sprintf(szTitle,"Cursor blink rate %d", nBlinkRate);
33          SetWindowText(hWnd,szTitle);
34        break;
35      case WM_KILLFOCUS:
36 
37        HideCaret(hWnd);
38        DestroyCaret();
39        break;
40      default:
41        return DefWindowProc(hWnd, message, wParam, lParam);
42     }
43     return 0;
44  }

Output

CreateCaret demo

You have viewed 1 page out of 109. Your VC++ learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

#Programming Windows, Fifth Edition (Developer Reference)
#Programming Applications for Microsoft Windows (Microsoft Programming Series)
#Programming Windows with MFC, Second Edition
#Visual C++ Programming
#Programming Microsoft Visual C++, Fifth Edition

* #1 webmaster Sun 27 Apr/2014 04:48:54(GMT)  Like 0 Unlike 0

Dear Users,

We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.

Regards,
Webmaster

Your message goes here:

Name:Guest
Email:anonymous@unknown.com
My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
 
Note:
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.