how to let CEdit SetFocus in a simple SDI program
-
hi, is there anybody who know let a CEdit control(child of CView) setfocus in a simple SDI program when program startup. I define CEdit control in my CView(.h file) like "CEdit m_edtContent", then in my CView's cpp file's create function, call like m_endContent.Create(....). But when the program startup, every time, i must click the CEdit first, then it will be focused, so can anybody tell me i don't need to click it, but let the program to setfocus my CEdit control. thanks.
-
hi, is there anybody who know let a CEdit control(child of CView) setfocus in a simple SDI program when program startup. I define CEdit control in my CView(.h file) like "CEdit m_edtContent", then in my CView's cpp file's create function, call like m_endContent.Create(....). But when the program startup, every time, i must click the CEdit first, then it will be focused, so can anybody tell me i don't need to click it, but let the program to setfocus my CEdit control. thanks.
use SetFocus(...) Good Luck. Uday kiran
-
hi, is there anybody who know let a CEdit control(child of CView) setfocus in a simple SDI program when program startup. I define CEdit control in my CView(.h file) like "CEdit m_edtContent", then in my CView's cpp file's create function, call like m_endContent.Create(....). But when the program startup, every time, i must click the CEdit first, then it will be focused, so can anybody tell me i don't need to click it, but let the program to setfocus my CEdit control. thanks.
hwndEdit=CreateWindow ("EDIT","Anshuman",WS_CHILD|WS_VISIBL|WS_BORDER,10,10,80,20,hWnd,(HMENU)IDC_EDIT1,hInst,NULL); SetFocus (hwndEdit); // Call at last to set the focus.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
hwndEdit=CreateWindow ("EDIT","Anshuman",WS_CHILD|WS_VISIBL|WS_BORDER,10,10,80,20,hWnd,(HMENU)IDC_EDIT1,hInst,NULL); SetFocus (hwndEdit); // Call at last to set the focus.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
use SetFocus(...) Good Luck. Uday kiran
-
tried this method several times at many different places, such as when created, when updated, or in InitInstance, can't success. don't know what's the problem
Call it immediatly before exiting your
OnInit
function. If that doesn't work look through your code for any other instances ofSetFocus
, maybe you are setting it but it is later being stolen. -
tried this method several times at many different places, such as when created, when updated, or in InitInstance, can't success. don't know what's the problem
On way is using CEdit::Setfocus in overridden OnActivateView()
Prasad Notifier using ATL
-
On way is using CEdit::Setfocus in overridden OnActivateView()
Prasad Notifier using ATL
-
On way is using CEdit::Setfocus in overridden OnActivateView()
Prasad Notifier using ATL
-
I don't know what's the reason, but i called m_edtContent.SetFocus in my overridden OnActivateView(), are you OK in your side, thanks for your help.
its failing ? Is it giving some ASSERT or just not doing what its intended to do? Have you suppressed its base class call ? You need to do that. It would just look like this,
void CSDIView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
m_edtContent.SetFocus();//later you can customize this to set foucs as your need
}Prasad Notifier using ATL
-
I don't know what's the reason, but i called m_edtContent.SetFocus in my overridden OnActivateView(), are you OK in your side, thanks for your help.
yes, really thanks for your help, it succeeds when i call like "CView::OnActivateView(bActivate, pActivateView, pDeactiveView); m_edtContent.SetFocus();" but not if i call like" m_edtContent.SetFocus(); CView::OnActivateView(bActivate, pActivateView, pDeactiveView); ". it's really very good, but after i quit the program, it will say "The exception Breakpoint, A breakpoint has been reached."
-
yes, really thanks for your help, it succeeds when i call like "CView::OnActivateView(bActivate, pActivateView, pDeactiveView); m_edtContent.SetFocus();" but not if i call like" m_edtContent.SetFocus(); CView::OnActivateView(bActivate, pActivateView, pDeactiveView); ". it's really very good, but after i quit the program, it will say "The exception Breakpoint, A breakpoint has been reached."
ikohl wrote:
CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
tries to set foucs on view itself. In your case its not needed.
Prasad Notifier using ATL
-
ikohl wrote:
CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
tries to set foucs on view itself. In your case its not needed.
Prasad Notifier using ATL
-
yes, it's ok in sdi program, except for can't focus previous program when this program quits. but for mdi program, there's an error box will jump out when quit this program. really thanks for your help, you're a kind man.
Actually, problem was you can't use SetFocus unless that window ,parent window is visible. OnActivateView is one place where you can achieve this. You can use its parameters for certain checks. Other place I feel is overriding WM_SHOWWINDOW, but it will get called once. You can look for such messages and use SetFocus there.
Prasad Notifier using ATL
-
Actually, problem was you can't use SetFocus unless that window ,parent window is visible. OnActivateView is one place where you can achieve this. You can use its parameters for certain checks. Other place I feel is overriding WM_SHOWWINDOW, but it will get called once. You can look for such messages and use SetFocus there.
Prasad Notifier using ATL