|
-
September 5th, 2003, 06:02 AM
#1
CComboBoxEx doesn't insert item
Hi! Maybe a stupid error, but my code only inserts garbage:
Code:
m_cmbAddress.Create(WS_CHILD|WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWN | CBS_HASSTRINGS ,
rect, &m_wndComboTool, ID_ADDRESS);
m_ImageListCombo.Create (16,16,TRUE,1,1);
m_ImageListCombo.Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
m_cmbAddress.SetImageList (&m_ImageListCombo);
m_cmbAddress.ShowWindow(SW_SHOW);
COMBOBOXEXITEM cbi;
CString str = "prueba";
cbi.mask = CBEIF_TEXT;
cbi.iItem = 0;
cbi.pszText = (LPTSTR)(LPCTSTR)str;
cbi.cchTextMax = str.GetLength();
m_cmbAddress.InsertItem (&cbi);
m_cmbAddress is a CComboBoxEx.
I am Miss Maiden... Miss Iron Maiden :-D
-
September 5th, 2003, 06:07 AM
#2
Why are you using CBS_HASSTRINGS? Is your combo box owner-drawn?
-
September 5th, 2003, 06:33 AM
#3
No, now it isn't owner-drawn. Thank you!. Now I can insert my string. But now I have two problems:
1.
Code:
m_wndComboTool.m_ImageListCombo.Create( GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR24, 50, 50);
void CMainFrame::WriteCombo (CString sData)
{
m_wndComboTool.m_cmbAddress.DeleteString (0);
SHFILEINFO shinfo;
SHGetFileInfo(sData, NULL,
&shinfo, sizeof(shinfo), SHGFI_ICON | SHGFI_SMALLICON);
int nIcon = m_wndComboTool.m_ImageListCombo.Add (shinfo.hIcon);
m_wndComboTool.m_cmbAddress.SetImageList (&m_wndComboTool.m_ImageListCombo);
COMBOBOXEXITEM cbi;
cbi.mask = CBEIF_TEXT|CBEIF_IMAGE;
cbi.iItem = 0;
cbi.iImage = nIcon;
cbi.pszText = (LPTSTR)(LPCTSTR)sData;
cbi.cchTextMax = sData.GetLength();
m_wndComboTool.m_cmbAddress.InsertItem (&cbi);
m_wndComboTool.m_cmbAddress.SetCurSel (0);
}
sData is a folder or disk drive, etc... But my combo doesn't show the icon. And shinfo is ok.
2.
Code:
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
// check if the message is a keypress
if ((pMsg->message >= WM_KEYFIRST) && (pMsg->message <= WM_KEYLAST))
{
CWnd* pWnd = GetFocus();
if (pWnd != NULL)
{
if (pWnd->GetOwner() == &m_wndComboTool.m_cmbAddress &&
pMsg->wParam == VK_RETURN)
{
CString str;
pWnd->GetWindowText(str);
CString* sItem = new CString (str);
//Actulizamos la lista con el contenido de la carpeta seleccionada
m_pExplorerView->GetDocument()->UpdateAllViews (m_pExplorerView, (DWORD)sItem);
//Pero además, en la vista de árbol tenemos que seleccionar el nodo
m_pExplorerView->UpdateSelect (str);
}
}
}
return CFrameWnd::PreTranslateMessage(pMsg);
}
This code worked when I had CCombo, but now with my CComboBoxEx, the next if:
pWnd->GetOwner() == &m_wndComboTool.m_cmbAddress
doesn't work.
Forget my first post:
m_cmbAddress is a CComboBoxEx in my class CComboToolBar.
And m_wndComboTool is a CComboToolbar. So:
Code:
m_wndComboTool.m_cmbAddress.Create(WS_CHILD|WS_VISIBLE | CBS_AUTOHSCROLL |
CBS_DROPDOWN ,
rect, &m_wndComboTool, ID_ADDRESS)
I am Miss Maiden... Miss Iron Maiden :-D
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|