CComboBox* CPlayerListCtrl::ShowInPlaceComboBox(int nItem, int nCol, CAtlList<CString>& lstItems, int nSel, bool bShowDropDown) { CRect rect; if (!PrepareInPlaceControl(nItem, nCol, rect)) { return nullptr; } DWORD dwStyle = /*WS_BORDER|*/WS_CHILD | WS_VISIBLE | WS_VSCROLL /*|WS_HSCROLL*/ | CBS_DROPDOWNLIST | CBS_DISABLENOSCROLL/*|CBS_NOINTEGRALHEIGHT*/; CComboBox* pComboBox = DEBUG_NEW CInPlaceComboBox(nItem, nCol, lstItems, nSel); pComboBox->Create(dwStyle, rect, this, IDC_COMBO1); CorrectComboListWidth(*pComboBox); int width = GetColumnWidth(nCol); if (pComboBox->GetDroppedWidth() < width) { pComboBox->SetDroppedWidth(width); } if (bShowDropDown) { pComboBox->ShowDropDown(); } m_fInPlaceDirty = false; return pComboBox; }
void UpdateHorzExtent(CComboBox &rctlComboBox, int iIconWidth) { int iItemCount = rctlComboBox.GetCount(); if (iItemCount > 0) { CDC *pDC = rctlComboBox.GetDC(); if (pDC != NULL) { // *** To get *ACCURATE* results from 'GetOutputTextExtent' one *MUST* // *** explicitly set the font! CFont *pOldFont = pDC->SelectObject(rctlComboBox.GetFont()); CString strItem; int iMaxWidth = 0; for (int i = 0; i < iItemCount; i++) { rctlComboBox.GetLBText(i, strItem); int iItemWidth = pDC->GetOutputTextExtent(strItem, strItem.GetLength()).cx; if (iItemWidth > iMaxWidth) iMaxWidth = iItemWidth; } pDC->SelectObject(pOldFont); rctlComboBox.ReleaseDC(pDC); // Depending on the string (lot of "M" or lot of "i") sometime the // width is just a few pixels too small! iMaxWidth += 4; if (iIconWidth) iMaxWidth += 2 + iIconWidth + 2; rctlComboBox.SetHorizontalExtent(iMaxWidth); if (rctlComboBox.GetDroppedWidth() < iMaxWidth) rctlComboBox.SetDroppedWidth(iMaxWidth); } } else rctlComboBox.SetHorizontalExtent(0); }
/************************************ * 设备初始化 *************************************/ bool CCommon::InitialDevice(CComboBox &m_cbDevice, LONG * width, LONG * height) { LONG w = 0, h = 0; bool m_bCameraOpen = false; int cam_count = GetCameraCount();//仅仅获取摄像头数目 m_cbDevice.SetDroppedWidth(cam_count); //获取所有摄像头的名称 for(int i=0; i < cam_count; i++) { char camera_name[1024]; int retval = GetCameraName(i, camera_name, sizeof(camera_name)); if(retval >0) { CString str,str_camera_name; str_camera_name = CCommon::Char2CString(camera_name); //防止摄像头名称太长,超出显示区域 int spaceNum = str_camera_name.Find(" "); CString strTemp = str_camera_name.Mid(0,spaceNum); str.Format("[%d] %s",i,strTemp); m_cbDevice.InsertString(i,str.GetBuffer(0)); } } if(cam_count > 0) { CString camera = CCommon::GetReg("Camera"); int m_iCameraIndex = atoi(CCommon::CString2Char(camera));//注册表获取摄像头id if(m_iCameraIndex < 0 || m_iCameraIndex > cam_count - 1) m_iCameraIndex = 0; m_cbDevice.SetCurSel(m_iCameraIndex);//设置默认选中第一个摄像头,现在从配置文件读取 //打开第一个摄像头 if(OpenCameraCB(m_iCameraIndex, false, &w,&h)) //不弹出属性选择窗口,用代码制定图像宽和高 { m_bCameraOpen = TRUE; } if(m_bCameraOpen == false) { for(int k = 0; k < cam_count; k++) { //打开第一个摄像头 if(OpenCameraCB(k, false, &w, &h)) //不弹出属性选择窗口,用代码制定图像宽和高 { m_bCameraOpen = TRUE; break; } } if(m_bCameraOpen == false && cam_count> 0) { //AfxMessageBox("摄像头初始化失败", MB_OK, MB_ICONINFORMATION); //OnOK(); *width = w; *width = h; return false; } } } *width = w; *height = h; return true; }