SetCaretPos inside a control
I got a strange problem with SetCaretPos() in a combo box, I would like
to set the caret position inside the combobox as soon as my appl pops
up the login dlg box. Tried in different ways with no success. Any
help is greatly appreciated.
here is the code snap shot.
My appl controls are created at runtime
BOOL CLoginDialog::OnInitDialog( )
{
CDialog::OnInitDialog();
CenterWindow();
PSessionInfo pSessionInfo = CSessionInfo::GetObject();
ASSERT(pSessionInfo);
CString strCurrentUser = pSessionInfo->GetCurrentUserName();
CStringArray & arrUsers = pSessionInfo->GetUserList();
for (int i = 0; i < arrUsers.GetCount(); i++)
{
m_ctrlUserName.AddString(arrUsers[i]);
}
if (m_ctrlUserName.GetCount() > 0)
{
int iIndex = m_ctrlUserName.FindString(-1, strCurrentUser);
if (iIndex < -1) iIndex = 0;
m_ctrlUserName.SetCurSel(iIndex);
}
// create the progress dialog
m_progressDlg.Create(IDD_DIALOG_PROGRESS, this);
m_progressDlg.CenterWindow();
UpdateData(FALSE);
// set the parents
CWnd * pWnd = GetDlgItem(IDC_STATIC_CONTAINER);
if (pWnd)
{
UINT idChild[] = {IDC_COMBO_USERNAME,
IDC_STATIC_USER_NAME,
IDC_STATIC_PASSWORD,
IDC_EDIT_PASSWORD};
CWnd * pWndChild = NULL;
CRect rect;
for (int i=0; i< 4; i++)
{
pWndChild =
GetDlgItem(idChild[i]);
if (!pWndChild) continue;
pWndChild->GetWindowRect(rect);
pWndChild->SetParent(pWnd);
pWnd->ScreenToClient(rect);
pWndChild->MoveWindow(rect);
}
} m_bitmap.LoadBitmap(IDB_BITMAP_LOGIN);
return TRUE;
}