void CImageApp::OnUpdateEditPaste(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here if(!IsClipboardFormatAvailable(CF_DIB)) pCmdUI->Enable(FALSE); }
void CImageApp::OnEditPaste() { // TODO: Add your command handler code here // ImageDoc의 DocTemplate을 얻음 POSITION pos = GetFirstDocTemplatePosition(); CDocTemplate *pTemplate = GetNextDocTemplate(pos);
// 새로운 도큐먼트 생성 CImageDoc *pNewDoc = (CImageDoc*)pTemplate->OpenDocumentFile(NULL); if (pNewDoc) { HANDLE hBitmap=NULL;
// 클립보드에서 데이터 가져오기 if (::OpenClipboard(AfxGetMainWnd()->GetSafeHwnd())) hBitmap = ::GetClipboardData(CF_DIB);
if (hBitmap){ // 클립보드에서 얻은 데이터로부터 CxImage 생성 pNewDoc->m_pImage = new CxImage(); pNewDoc->m_pImage->CreateFromHANDLE(hBitmap); // View 초기화 POSITION pos = pNewDoc->GetFirstViewPosition(); CImageView* pView = (CImageView*)pNewDoc->GetNextView(pos); }
// 클립보드 닫기 ::CloseClipboard();
pNewDoc->SetModifiedFlag(); } }
class CImageDoc : public CDocument
{
...
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CImageDoc)
public:
... virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
virtual void DeleteContents();
virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
//}}AFX_VIRTUAL
BEGIN_MESSAGE_MAP(CImageDoc, CDocument)
//{{AFX_MSG_MAP(CImageDoc) ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
...
CImageDoc::CImageDoc()
{
// TODO: add one-time construction code here m_pImage = NULL;
}
...
BOOL CImageDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: Add your specialized creation code here
// { m_pImage = new CxImage;
m_pImage->Load(lpszPathName, CxImage::FindType(lpszPathName));
// }
return TRUE;
}
void CImageDoc::DeleteContents()
{
// TODO: Add your specialized code here and/or call the base class
// { if(m_pImage)
delete m_pImage;
// }
CDocument::DeleteContents();
}
BOOL CImageDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
// TODO: Add your specialized code here and/or call the base class
// { return m_pImage->Save(lpszPathName, CxImage::FindType(lpszPathName));
// }
// return CDocument::OnSaveDocument(lpszPathName);
}
void CImageDoc::OnEditCopy() { // TODO: Add your command handler code here HANDLE hDIB = m_pImage->CopyToHandle();
if (::OpenClipboard(AfxGetMainWnd()->GetSafeHwnd())) { if(::EmptyClipboard()) { if (::SetClipboardData(CF_DIB, hDIB) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); } } } ::CloseClipboard(); }