票是什么?时间还早,我还没有喝咖啡 块视图示例...呵呵....
太好了,谢谢你的确认,街区视图样本是我应该看的 那么现在我可以获得我的块的视图,那么关于如何通过MFC创建块图标数组的任何想法?
这是我一直在努力的工作,但我没有太多的运气
#pragma once
#include "afxwin.h"
class CGsPreviewCtrl : public CStatic
{
public:
AcGsManager *mpManager;
AcGsClassFactory *mpFactory;
AcGsDevice *mpDevice;
AcGsView *mpView;
AcGsModel *mpModel;
bool mbModelCreated;
AcGeVoidPointerArray mEntities;
public:
CGsPreviewCtrl(void);
virtual ~CGsPreviewCtrl(void);
protected:
afx_msg void OnPaint(void);
public:
bool Add(AcGiDrawable *item, AcGsModel* pModel);
void SetModel(AcGsModel* pModel);
void ClearAll(void);
void ErasePreview(void);
void Init(HMODULE hRes, bool bCreateModel);
AcGsView*view(void) const;
AcGsModel* model(void) const;
bool GetPreviewIcon(AcDbBlockTableRecord::PreviewIcon &icn);
DECLARE_MESSAGE_MAP()
};
inline AcGsView* CGsPreviewCtrl::view() const
{
return mpView;
}
inline AcGsModel* CGsPreviewCtrl::model() const
{
return mpModel;
}
和问题区域
bool CGsPreviewCtrl::GetPreviewIcon( AcDbBlockTableRecord::PreviewIcon &icn )
{
CDC *view = GetDC();
HDC hview = view->GetSafeHdc();
HDC hCompDC = CreateCompatibleDC(hview);
int nWidth = 32;
int nHeight = 32;
HBITMAP hBmp = CreateCompatibleBitmap(hview, nWidth, nHeight);
HBITMAP hOld = (HBITMAP)SelectObject(hCompDC, hBmp);
BitBlt(hCompDC, 0, 0, nWidth, nHeight, hview, 0, 0, SRCCOPY);
BITMAP bmp;
GetObject(hBmp, sizeof(BITMAP), (void*)&bmp);
BITMAPINFOHEADER bi;
ZeroMemory(&bi,sizeof(BITMAPINFOHEADER));
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = bmp.bmWidth;
bi.biHeight = bmp.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = 32;
bi.biCompression = BI_RGB;
DWORD dwBmpSize = ((bmp.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmp.bmHeight;
HANDLE hDIB = GlobalAlloc(GHND,dwBmpSize);
Adesk::UInt8 *bmpBuffer = (Adesk::UInt8*)GlobalLock(hDIB);
int res = GetDIBits(hview, hBmp, 0,(UINT)bmp.bmHeight, bmpBuffer,(BITMAPINFO *)&bi, DIB_RGB_COLORS);
icn.setLogicalLength(dwBmpSize);
memcpy(icn.asArrayPtr(),bmpBuffer,dwBmpSize);
GlobalUnlock(hDIB);
GlobalFree(hDIB);
DeleteObject(hBmp);
ReleaseDC(view);
DeleteDC(hCompDC);
return true;
}
这个公式正确吗?否则,在视觉上一切看起来都很好<DWORD dwBmpSize=((bmp.bmWidth*bi.bibibitCount+31)/32)*4*bmp。BMH<编辑:这个公式看起来也不错。如果您能提供更多详细信息,很难从您的描述和代码中看出哪些不起作用。
页:
1
[2]