[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

control focus events

Posted on 2005-04-27
7
Medium Priority
?
274 Views
Last Modified: 2013-11-20
Hi experts,

I need to know what event gets triggered when a dialog control gets focus.

For example, my property page has several static labels, checkboxes, combo boxes, text entry fields.  As the user tabs to each one I need to announce what they should do.

Can you help me?

Thanks
marisa
0
Comment
Question by:marisademeglio
  • 3
  • 2
  • 2
7 Comments
 
LVL 9

Assisted Solution

by:rcarlan
rcarlan earned 1000 total points
ID: 13875655
WM_SETFOCUS is sent to the control getting the focus, WM_KILLFOCUS to the control losing the focus, nothing to the parent dialog.

Radu
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13875679
You can try to trap WM_KEYDOWN with VK_TAB in PreTranslateMessage method of your CDialog derived class and then ask where's teh focus and act accordingly.
0
 
LVL 9

Expert Comment

by:rcarlan
ID: 13875961
Focus can be gain/lost through mouse actions as well as through accelerator keys (i.e. keyboard shortcuts), in addition to Tab and Shift+Tab. Handling VK_TAB alone will only get you so far.

Radu
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:marisademeglio
ID: 13878854
Tab/shift-tab might work for me, since i will be playing an audio prompt as part of a self-voicing interface.  which would get annoying if it were triggered by any action.  but I understand Radu's point.

anyway, how would I ask "where's the focus?"
0
 
LVL 9

Expert Comment

by:rcarlan
ID: 13880137
HWND GetFocus();
CWnd* CWnd::GetFocus();  // static
0
 

Author Comment

by:marisademeglio
ID: 13934360
How do I catch keyboard events in a dialog?  WM_KEYUP and KEYDOWN aren't responsive..

nonubik, you mentioned PreTranslateMessage... How do I use it?

thanks
marisa
0
 
LVL 16

Accepted Solution

by:
nonubik earned 1000 total points
ID: 13934397
PreTranslateMessage is a CWnd virtual method. You just need to overwrite it (can use MFC wizard).

BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
  if(pMsg->message == WM_KEYDOWN)
  {
     pMsg->hwnd; //here is the window that received keydown.
  }

  return CDialog::PreTranslateMessage(pMsg);
}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

873 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