vs2008 MFC COMBOBOX 按钮不显示问题?
绿林好汉 2011-10-13 09:50:25 我要在list上显示combobox,先在对话框上放了一个combobox控件,再在对话框里添加了一个list点击事件,代码如下:
但点list时combobox的按钮不显示,只显示一个combobox的编辑框,必须zaicombobox的按钮的地方点击一下按钮才会显示出来,怎么样让按钮在点击list示就显示出来呢
void CGenIncCmpCfgFile::OnNMClickListIncField(NMHDR *pNMHDR, LRESULT *pResult)
{
// 1.获取当前显示的变量的名称
int iSelItemIndex = 0; // 记录选中的第一条记录的索引
POSITION pPosition = m_lstIncSheetCols.GetFirstSelectedItemPosition();
iSelItemIndex= m_lstIncSheetCols.GetNextSelectedItem( pPosition );
// 2.获取选中项的配置信息
// string strCmdName("");
// strCmdName = (LPCTSTR)m_lstIncSheetCols.GetItemText( iSelItemIndex, 0 );
// // 判断是否点击了空的记录
// if ( strCmdName.empty() )
// {
//GetDlgItem( IDC_BUTTON_VIEW_ALL_CMD_REF_VAL )->EnableWindow( FALSE );
// return ;
// }
//GetDlgItem( IDC_BUTTON_VIEW_ALL_CMD_REF_VAL )->EnableWindow( TRUE );
HWND hWnd1 = ::GetDlgItem (m_hWnd,IDC_LIST_INC_FIELD);
LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE) pNMHDR;
m_iRowNum = temp->iItem; // get the row number
m_iColNum = temp->iSubItem; // get the column number
if(m_iColNum == -1 || m_iRowNum == -1)
{
return ;
}
m_iRowNumOld = m_iRowNum;
m_iColNumOld = m_iColNum;
//Retrieve the text of the selected subItem
//from the list
CString str = GetItemText(hWnd1,m_iRowNum , 2);
RECT rect;
RECT rect1;
RECT rect2;
// this macro is used to retrieve the Rectanle of the selected SubItem
ListView_GetSubItemRect(hWnd1,temp->iItem, 2,LVIR_BOUNDS,&rect);
::GetWindowRect(temp->hdr.hwndFrom,&rect1); // Get the Rectange of the listControl
::GetWindowRect(m_hWnd,&rect2); // Get the Rectange of the Dialog
int x=rect1.left-rect2.left;
int y=rect1.top-rect2.top;
if( -1 != m_iRowNum )
{
::SetWindowPos(::GetDlgItem(m_hWnd,IDC_CB_GENINCCMP), 0,rect.left+x,rect.top+82, rect.right-rect.left, rect.bottom-rect.top -1,NULL);
}
::ShowWindow(::GetDlgItem(m_hWnd,IDC_CB_GENINCCMP),SW_SHOW);
//把list内容赋给combobox
::SetWindowText(::GetDlgItem(m_hWnd,IDC_CB_GENINCCMP),str);
::SetFocus(::GetDlgItem(m_hWnd,IDC_CB_GENINCCMP));//set focus to combobox
*pResult = 0;
return ;
}