How to track position of the Caret

28 01 2012

Sometimes back one of my friends asked me, how could he able to find whether the caret is blinking in an active window? or just for an example if you have a dialog application which contains different controls like button, editbox, listbox etc and you are keep on moving the cursor focus over these control using “Tab” key, once the edit box gets focus, cursor starts to blink. How to detect such events?

The direct method to track caret position like windows events are to use Microsoft Active Accessibility. However the simpler approach to track caret position is to use GUITHREADINFO structure. This structure contains hwndCaret and rcCaret members that gives the handle to the window that owns the caret and client coordinate of the caret.

GetGUIThreadInfo function is used to get GUITHREADINFO structure info.

GetWindowThreadProcessId function retrieves the identifier of the thread that created the specified thread.


void OnTimer(UINT_PTR nIDEvent)
	// Retrieves the identifier of the thread that created the specified window
	DWORD dwThreadID = GetWindowThreadProcessId(GetForegroundWindow()->m_hWnd, NULL);

	guiThreadInfo.cbSize = sizeof(GUITHREADINFO);

	//Retrieves information about the active window or a specified GUI thread.
	if (GetGUIThreadInfo(dwThreadID, &guiThreadInfo))
		if (GUI_CARETBLINKING == guiThreadInfo.flags)
			AfxMessageBox(_T("Caret Blinking"));

		if (guiThreadInfo.hwndCaret)
			//caret position
			POINT pt = { guiThreadInfo.rcCaret.left, };
			//it should be an edit control
			AfxMessageBox(_T("edit control"));

Microsoft Active Accessibility provides a mechanism that allows to generate events to detect object creation, destruction, focus change, location change,… so on.

Principles of good GUI design

8 01 2009


Graphical User Interfaces (GUIs) are the user interface part of an application. Most of the cases it act as the front end of our applications.  So it must be effective and purposeful.

It is better to consider the following things during a GUI development. 

  1. The captions of the controls should be readable.
  2. Avoid cluttered controls.
  3. It should be fully visible in all resolutions.
  4. Should follow same theme throughout the application.
  5. Avoid recursive message boxes.
  6. Notify the user about the error, warning and information in a smooth and fine way.
  7. Provide traceable path with the text message boxes.
  8. Use model and modeless dialogs effectively.
  9. Set proper tab order to controls.
  10.  Provide keyboard accelerators to access menu items and controls within the main window.

If you apply these principles in GUI design, your users could use it easily and quickly.