几何尺寸与公差论坛

 找回密码
 注册
查看: 4213|回复: 1

How to get preview bitmaps?

[复制链接]
发表于 2007-9-4 22:28:00 | 显示全部楼层 |阅读模式
How to get preview bitmaps
GetPreviewBitmap.zip
[size=-2]Updated: 6/15/2004
Size: 0.505

This sample code shows how to use SldWorks::GetPreviewBitmap in a C++ COM Addin.
 楼主| 发表于 2007-9-4 22:34:00 | 显示全部楼层

回复: 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;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-22 23:51 , Processed in 0.036707 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表