a question of edit control
-
when I click in my editbox,I want all the contents to be selected,I used these code: void CCaculatorDlg::OnSetfocusEDITap1() { CEdit* ped=(CEdit*)GetDlgItem(IDC_EDIT_ap1); ped->SetSel(0, -1, FALSE); } but it doesnt work, when I click at the editbox, it just like havent added these code. what could I do?
-
when I click in my editbox,I want all the contents to be selected,I used these code: void CCaculatorDlg::OnSetfocusEDITap1() { CEdit* ped=(CEdit*)GetDlgItem(IDC_EDIT_ap1); ped->SetSel(0, -1, FALSE); } but it doesnt work, when I click at the editbox, it just like havent added these code. what could I do?
-
There's no EN_SETSEL. Tomasz Sowinski -- http://www.shooltz.com
- It's for protection
- Protection from what? Zee Germans? -
Use EN_SETSEL ----- // editHWnd is the handle to your edit control // from and to are the beginning and end of your select range SendMessage(editHWnd, EM_SETSEL, static_cast(from), static_cast(to)); ----- Kuphryn
There's no EN_SETSEL. Tomasz Sowinski -- http://www.shooltz.com
- It's for protection
- Protection from what? Zee Germans? -
And what do you think CEdit::SetSel does? Tomasz Sowinski -- http://www.shooltz.com
- It's for protection
- Protection from what? Zee Germans? -
And what do you think CEdit::SetSel does? Tomasz Sowinski -- http://www.shooltz.com
- It's for protection
- Protection from what? Zee Germans? -
There are more than one way to get it working. Using EM_SETSEL is another method. I recommend trying that method to see if get the design where you want it. Kuphryn
Just FYI, CEdit::SetSel is a thin wrapper which sends EM_SETSEL. So there's no difference, unless you want to achieve macho-API posture. :) Tomasz Sowinski -- http://www.shooltz.com
- It's for protection
- Protection from what? Zee Germans? -
when I click in my editbox,I want all the contents to be selected,I used these code: void CCaculatorDlg::OnSetfocusEDITap1() { CEdit* ped=(CEdit*)GetDlgItem(IDC_EDIT_ap1); ped->SetSel(0, -1, FALSE); } but it doesnt work, when I click at the editbox, it just like havent added these code. what could I do?
Two things: First (as I go into Pedantic mode...) Anonymous wrote:
CEdit* ped=(CEdit*)GetDlgItem(IDC_EDIT_ap1); ped->SetSel(0, -1, FALSE);
I would recommend that you do not get into the habit of casting the return value ofGetDlgItem(...)
to aCEdit*
(or other class type) like that. There are certain situations whereGetDlgItem(...)
will return a pointer to a realCEdit
(or other Control Class) object, but if you do not know what those situations are, it is best to avoid this entirely. Bind aCEdit
member variable to the control, and use it instead. True, in the case of MFC, doing that is usually safe, but in general C++ practices, it is a bad thing to do: you do not know if the pointer returned byGetDlgItem(...)
is, or ever was, a pointer to an actualCEdit
object. Second, try usingPostMessage(...)
to send yourself the EM_SETSEL message from inside theOnSetFocus
handler. BTW:CWnd::OnSetFocus(...)
is a standard function. What isOnSetfocusEDITap1
supposed to be? You may be handling theWM_SETFOCUS
message incorrectly. Peace! -=- James. "Some People Know How To Drive, Others Just Know How To Operate A Car." (Try Check Favorites Sometime!) -
Two things: First (as I go into Pedantic mode...) Anonymous wrote:
CEdit* ped=(CEdit*)GetDlgItem(IDC_EDIT_ap1); ped->SetSel(0, -1, FALSE);
I would recommend that you do not get into the habit of casting the return value ofGetDlgItem(...)
to aCEdit*
(or other class type) like that. There are certain situations whereGetDlgItem(...)
will return a pointer to a realCEdit
(or other Control Class) object, but if you do not know what those situations are, it is best to avoid this entirely. Bind aCEdit
member variable to the control, and use it instead. True, in the case of MFC, doing that is usually safe, but in general C++ practices, it is a bad thing to do: you do not know if the pointer returned byGetDlgItem(...)
is, or ever was, a pointer to an actualCEdit
object. Second, try usingPostMessage(...)
to send yourself the EM_SETSEL message from inside theOnSetFocus
handler. BTW:CWnd::OnSetFocus(...)
is a standard function. What isOnSetfocusEDITap1
supposed to be? You may be handling theWM_SETFOCUS
message incorrectly. Peace! -=- James. "Some People Know How To Drive, Others Just Know How To Operate A Car." (Try Check Favorites Sometime!)