Problem with SetFocus
-
Hey, I've an application with 2 dialogs. The first dialog holds a couple of controls, the second dialog a listbox with handles to the controls (on the first dialog). Now I want to set the focus to the control on the first dialog by selecting an item in the listbox. My problem is that the focus jumps back to my listbox after I set it to the control. Code after selecting an item in listbox (all pointers are valid!)
CWnd* pWnd = GetHandleToDialogControl(iIndex); //Get CWnd* information from selected item pWnd->SetFocus() //Set focus to my control on first dialog
I can see that the control get the focus, but it jumps back to listbox immediately... -
Hey, I've an application with 2 dialogs. The first dialog holds a couple of controls, the second dialog a listbox with handles to the controls (on the first dialog). Now I want to set the focus to the control on the first dialog by selecting an item in the listbox. My problem is that the focus jumps back to my listbox after I set it to the control. Code after selecting an item in listbox (all pointers are valid!)
CWnd* pWnd = GetHandleToDialogControl(iIndex); //Get CWnd* information from selected item pWnd->SetFocus() //Set focus to my control on first dialog
I can see that the control get the focus, but it jumps back to listbox immediately...You might try using
PostMessage
to send a user-defined message from the second dialog to the first in your listbox notification handler. This should let the focus handling in the list box complete, and then your user-defined message would reach the first dialog, which could then set the focus as desired.
Software Zen:
delete this;
-
Hey, I've an application with 2 dialogs. The first dialog holds a couple of controls, the second dialog a listbox with handles to the controls (on the first dialog). Now I want to set the focus to the control on the first dialog by selecting an item in the listbox. My problem is that the focus jumps back to my listbox after I set it to the control. Code after selecting an item in listbox (all pointers are valid!)
CWnd* pWnd = GetHandleToDialogControl(iIndex); //Get CWnd* information from selected item pWnd->SetFocus() //Set focus to my control on first dialog
I can see that the control get the focus, but it jumps back to listbox immediately...Where is this code located? In OnInitDialog()? If so, make sure you return FALSE from the OnInitDialog() function. If not, the system will give the first control in the dialog the focus (which may not be the control you have given focus).
-- Nominated For Three Glemmys
-
Hey, I've an application with 2 dialogs. The first dialog holds a couple of controls, the second dialog a listbox with handles to the controls (on the first dialog). Now I want to set the focus to the control on the first dialog by selecting an item in the listbox. My problem is that the focus jumps back to my listbox after I set it to the control. Code after selecting an item in listbox (all pointers are valid!)
CWnd* pWnd = GetHandleToDialogControl(iIndex); //Get CWnd* information from selected item pWnd->SetFocus() //Set focus to my control on first dialog
I can see that the control get the focus, but it jumps back to listbox immediately...Having two dialogs communicate in this fashion indicates a very bad design. They should be using
PostMessage()
to communicate with each other.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb