[ATL] Compter les valeurs d'une listBox
Bonjour, j'essaye de faire un controle ATL basé sur une listbox, pour une page Web, mais j'ai des soucis pour compter les valeurs.
Voici mon constructeur :
Code:
1 2 3 4 5
| DnDZone()
: m_ctlListBox(_T("ListBox"), this, 1)
{
m_bWindowOnly = TRUE;
} |
Voici comment j'ajoute une ligne à ma ListBox :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| STDMETHODIMP DnDZone::addString(BSTR bstrItem)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if (!::IsWindow(m_hWnd)) {
return Error (OLESTR ("Invalid or NULL window handler for the ListBox control"),
IID_IDnDZone, E_FAIL);
}
long count = 0;
HRESULT hRes = S_OK;
hRes = get_length (&count);
if (FAILED (hRes)) {
return hRes;
}
// If the count number is one of the indcies, then add a blank line and then add the text
// string.
USES_CONVERSION;
if (::SendMessage (m_ctlListBox.m_hWnd, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(W2CT (bstrItem)))
== LB_ERR) {
return Error (OLESTR ("Failed to add text string in ListBox control"),
IID_IDnDZone, E_FAIL);
}
return S_OK;
} |
et voici comment je compte les valeurs :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| STDMETHODIMP DnDZone::get_length(LONG* pVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// Do some initial checks.
if (!::IsWindow(m_hWnd)) {
return Error (OLESTR ("Invalid or NULL window handler for the ListBox control"),
IID_IDnDZone, E_FAIL);
}
if (pVal == NULL) {
return Error (OLESTR ("NULL pointer passed in to return the value"),
IID_IDnDZone, E_POINTER);
}
*pVal = (int)::SendMessage(m_ctlListBox.m_hWnd, CB_GETCOUNT, 0, 0L);
if (*pVal == LB_ERR) {
return Error (OLESTR ("Error getting number of items from ListBox control"),
IID_IDnDZone, E_FAIL);
}
return S_OK;
} |
Le problème est que je reçois toujours 0 au GETCOUNT. Est ce que je dois mettre quelque chose à jour pour avoir la bonne valeur ? Est ce qu'il y a une méthode que je devrais implementer et qu'il me manque (genre OnDrawItem) ?
Merci d'avance.