Moving Focus To A Control
-
Hello, I have a dialog box that I reuse to enter and modify information in my program. What I would like to accomplish is to have the focus placed on a certain control when the dialog is being used to enter information and another different control when it is being used to modify information. How would I go about doing this? I've been searching through the MSDN but haven't had any luck figuring out how to move the focus at all. Right now it's just defaulting to the first tab stop on the dialog. I really appreciate any help. Thanks!! Joseph LeBlanc unixd0od@hotmail.com
-
Hello, I have a dialog box that I reuse to enter and modify information in my program. What I would like to accomplish is to have the focus placed on a certain control when the dialog is being used to enter information and another different control when it is being used to modify information. How would I go about doing this? I've been searching through the MSDN but haven't had any luck figuring out how to move the focus at all. Right now it's just defaulting to the first tab stop on the dialog. I really appreciate any help. Thanks!! Joseph LeBlanc unixd0od@hotmail.com
Hello, the codegurus around the world. In order to change the input focus on Dilaog, we can use CWnd::SetFocus() or CDialog::GoToDlgCtrl(CWnd*) member functions. However, if you validate some data in some control, and change the input foucs, you have to write your own code. Issue is when the application will change the input foucs to the conrol? When the user push enter key, or some control loses its own focus... Have a nice day!
-Masaaki Onishi-
-
Hello, the codegurus around the world. In order to change the input focus on Dilaog, we can use CWnd::SetFocus() or CDialog::GoToDlgCtrl(CWnd*) member functions. However, if you validate some data in some control, and change the input foucs, you have to write your own code. Issue is when the application will change the input foucs to the conrol? When the user push enter key, or some control loses its own focus... Have a nice day!
-Masaaki Onishi-
Hi Onishi. If i using SDI and CFormView in my program, so how can i set the focus for controls ? *** Please write code *** My month article: Game programming by DirectX by Lan Mader. Please visit in: www.geocities.com/hadi_rezaie/index.html Hadi Rezaie
-
Hi Onishi. If i using SDI and CFormView in my program, so how can i set the focus for controls ? *** Please write code *** My month article: Game programming by DirectX by Lan Mader. Please visit in: www.geocities.com/hadi_rezaie/index.html Hadi Rezaie
Hello, the codegurus around the world.;) If you add "Please" to your message, someone else may help you more.:rolleyes: "Write your own code" means that we sometimes work more than we expect. SetFocus() doesn't work correctly if we figure out the order of the input foucs. Your question is this example. X| One control should be on CMyFormView. I try to set the input foucs to the edit box called IDC_ZIP after I close Sort dialog if I open Sort Dialog by clicking the menu item.
void CSortDialog::OnCancel()
{
// Get CMainFrame CWnd to use GetActiveView();
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
ASSERT(pFrame);
// Get CWnd of CMyFormView;
CMyFormView* pView = (CMyFormView*)(pFrame->GetActiveView());
ASSERT(pView);
// Try to set the input foucs the edit control called IDC_ZIP;
pView->GetDlgItem(IDC_ZIP)->SetFocus();
// But the above code did't work, so I use BOOL m_bSetFocusToZipCode;
// Since the first tab order control gets the input focus;
pView->m_bSetFocusToZipCode = TRUE;CDialog::OnCancel();
}
void CMyFormView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
// bActivate = TRUE means that CMyFormView gets the foucs;
if (bActivate && m_bSetFocusToZipCode) {
//This works to change the input foucs to IDC_ZIP here;
GetDlgItem(IDC_ZIP)->SetFocus();
m_bSetFocusToZipCode = FALSE;
}CDaoRecordView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
Hum, in fact, this code seems not to be practical since we have to add all BOOL flag to change the input foucs to all controls on FormView. X| But, now we understand that SetFocus() doen's work if we misunderstand how the input foucs is executed in the process of Window message. In this case, the tab order of the control on FormView seems to overwrite the code of void CSortDialog::OnCancel() to set the input focus. Have a nice day!
-Masaaki Onishi-
-
Hello, the codegurus around the world.;) If you add "Please" to your message, someone else may help you more.:rolleyes: "Write your own code" means that we sometimes work more than we expect. SetFocus() doesn't work correctly if we figure out the order of the input foucs. Your question is this example. X| One control should be on CMyFormView. I try to set the input foucs to the edit box called IDC_ZIP after I close Sort dialog if I open Sort Dialog by clicking the menu item.
void CSortDialog::OnCancel()
{
// Get CMainFrame CWnd to use GetActiveView();
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
ASSERT(pFrame);
// Get CWnd of CMyFormView;
CMyFormView* pView = (CMyFormView*)(pFrame->GetActiveView());
ASSERT(pView);
// Try to set the input foucs the edit control called IDC_ZIP;
pView->GetDlgItem(IDC_ZIP)->SetFocus();
// But the above code did't work, so I use BOOL m_bSetFocusToZipCode;
// Since the first tab order control gets the input focus;
pView->m_bSetFocusToZipCode = TRUE;CDialog::OnCancel();
}
void CMyFormView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
// bActivate = TRUE means that CMyFormView gets the foucs;
if (bActivate && m_bSetFocusToZipCode) {
//This works to change the input foucs to IDC_ZIP here;
GetDlgItem(IDC_ZIP)->SetFocus();
m_bSetFocusToZipCode = FALSE;
}CDaoRecordView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
Hum, in fact, this code seems not to be practical since we have to add all BOOL flag to change the input foucs to all controls on FormView. X| But, now we understand that SetFocus() doen's work if we misunderstand how the input foucs is executed in the process of Window message. In this case, the tab order of the control on FormView seems to overwrite the code of void CSortDialog::OnCancel() to set the input focus. Have a nice day!
-Masaaki Onishi-
I didn't want to be unpolite with you, especially and with others. any how i appologize :) My month article: Game programming by DirectX by Lan Mader. Please visit in: www.geocities.com/hadi_rezaie/index.html Hadi Rezaie
-
I didn't want to be unpolite with you, especially and with others. any how i appologize :) My month article: Game programming by DirectX by Lan Mader. Please visit in: www.geocities.com/hadi_rezaie/index.html Hadi Rezaie
Hello, the codegurus around the world.;) Well, I missed your word - "Please write the code". You're lucky since I have my time to have some experiment and I have my own code for the formview project. However, if I don't have this project, I have to spend my time - maybe a couple of hours to create the same enviroment project. :(( Since I am done this test about 20 minutes, it wasn't tough for me. (However, the first approach did't work, I'm so :eek: ) (Or someone may have the better answer.) My point is that if we have the same project which someone asks us, we can answer the question or make some test easily. Otherwise, we have to spend a least couple of hours since we have some responsibilty to our answers.:(( (Or, the other super-programmers can answer these easily.? X| ) So, I often told the people at the codegurus or codeproject, show your code or narrow your question more. :cool: Have a nice day!
-Masaaki Onishi-