查看单个帖子
旧 2007-09-04, 10:34 PM   #2
huangyhg
超级版主
 
huangyhg的头像
 
注册日期: 04-03
帖子: 18592
精华: 36
现金: 249466 标准币
资产: 1080358888 标准币
huangyhg 向着好的方向发展
默认 回复: How to get preview bitmaps?

BOOL CMyDialog::ShowConfigPreview()
{
CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_CONFIG_NAMES);
if ( !pCombo )
return FALSE;

int nIndex = pCombo->GetCurSel();
if ( nIndex == LB_ERR )
return FALSE;

CString strConfigName;
int nLen;
nLen = pCombo->GetLBTextLen( nIndex );
pCombo->GetLBText( nIndex, strConfigName.GetBuffer(nLen) );
strConfigName.ReleaseBuffer();

if ( strConfigName.IsEmpty() )
return FALSE;

CString strFilePath;
GetDlgItemText(IDC_FILE_PATH , strFilePath);
if ( strFilePath.IsEmpty() )
return FALSE;

BSTR bstrFilePath = strFilePath.AllocSysString();
BSTR bstrConfigName = strConfigName.AllocSysString();

IDispatch* pDisp = NULL;

HRESULT hres = m_iSldWorks->GetPreviewBitmap ( bstrFilePath , bstrConfigName , &pDisp );
if ( hres != S_OK || NULL == pDisp )
{
AfxMessageBox(_T("no preview for selected config"));
return FALSE;
}

IPictureDisp* pPictureDispatch = NULL;

hres = pDisp->QueryInterface(IID_IPictureDisp,(void**)&pPictureDispatch);
if ( NULL == pPictureDispatch )
{
return FALSE;
}

LPPICTURE pPict = NULL;
CPictureHolder holder;
holder.SetPictureDispatch(pPictureDispatch);
pPict = holder.m_pPict;

CPicture* pic = new CPicture();
pic->SetPicture(pPict);
m_wndPict.SetPicture(pic);

m_wndPict.Invalidate();

return TRUE;
}
__________________
借用达朗贝尔的名言:前进吧,你会得到信心!
[url="http://www.dimcax.com"]几何尺寸与公差标准[/url]
huangyhg离线中   回复时引用此帖