#include "stdafx.h" #include "SigmaView.h" #include "SectionDoc.h" #include "ItemCopyAsImage.h" #include "HSimpleTracker.h" static CItemCopyAsImage * getItemItemCopyAsImage(CSigmaView * pView) { CItem * pItem = pView->GetItem(); if (pItem == NULL) return NULL; CItemCopyAsImage * ciItem = dynamic_cast(pItem); return ciItem; } extern "C" __declspec(dllexport) int CopyAsImage_SetRange(CSigmaView * pView, int left, int right, int top, int bottom, HDC hdc) { if (pView == NULL) return -1; CItemCopyAsImage * pItem = getItemItemCopyAsImage(pView); if (pItem == NULL) return -1; CDC * pDC = CDC::FromHandle(hdc); if (pDC == NULL) return -1; CRect rect; rect.left = left; rect.right = right; rect.top = top; rect.bottom = bottom; if (pItem->SetRange(rect) == -1) return -1; CHSimpleTracker * tracker = pItem->GetTracker(); if (tracker) { tracker->Draw(pDC); } return 1; } extern "C" __declspec(dllexport) void CopyAsImage_EraseTrackerForRange(CSigmaView * pView, HDC hdc) { if (pView == NULL) return ; CItemCopyAsImage * pItem = getItemItemCopyAsImage(pView); if (pItem == NULL) return ; CDC * pDC = CDC::FromHandle(hdc); if (pDC == NULL) return ; CHSimpleTracker * tracker = pItem->GetTracker(); if (tracker == NULL) return; tracker->Draw(pDC); } //区域截屏是否成功 成功返回1 失败返回-1 extern "C" __declspec(dllexport) int CopyAsImage_IsSuccess(CSigmaView * pView, HDC hdc) { if (pView == NULL) return -1; if (pView->m_pDoc == NULL) return -1; if (pView->m_pDoc->IsCapturedScreen()) return 1; return -1; } //0--左下箭头 1--垂直箭头 2--右下箭头 3--水平箭头 //4--旋转箭头 5--水平剪切箭头 6--垂直剪切箭头 7--平移箭头 //-1 出错 extern "C" __declspec(dllexport) int CopyAsImage_GetTrackerHandleCursorType(CSigmaView * pView, int mouseX, int mouseY) { if (pView == NULL) return -1; CItemCopyAsImage * pItem = getItemItemCopyAsImage(pView); if (pItem == NULL) return -1; HTRACKER_HANDLE_KIND handleKind = pItem->GetTracker()->HitTest(mouseX, mouseY); if (handleKind == HTRACKER_HANDLE_KIND_INVALID) return -1; if (handleKind == HTRACKER_HANDLE_KIND_CENTER) return 7; switch (handleKind) { case HTRACKER_HANDLE_KIND_TOP_LEFT: case HTRACKER_HANDLE_KIND_BOTTOM_RIGHT: return 0; case HTRACKER_HANDLE_KIND_TOP_RIGHT: case HTRACKER_HANDLE_KIND_BOTTOM_LEFT: return 2; case HTRACKER_HANDLE_KIND_TOP: case HTRACKER_HANDLE_KIND_BOTTOM: return 1; case HTRACKER_HANDLE_KIND_RIGTH: case HTRACKER_HANDLE_KIND_LEFT: return 3; } return -1; } extern "C" __declspec(dllexport) int CopyAsImage_CopyWindow(CSigmaView * pView, int left, int right, int top, int bottom) { if (pView == NULL) return -1; CRect rect; rect.left = left; rect.right = right; rect.top = top; rect.bottom = bottom; CItemCopyAsImage * pItem = getItemItemCopyAsImage(pView); if (pItem == NULL) { pItem = new CItemCopyAsImage(pView->m_pDoc); pItem->CopyWindowToClipboard(rect); delete pItem; pItem = nullptr; } else { pItem->CopyWindowToClipboard(rect); } return 1; } extern "C" __declspec(dllexport) int CopyAsImage_CopyAll(CSigmaView * pView, int left, int right, int top, int bottom) { if (pView == NULL) return -1; CItemCopyAsImage * pItem = getItemItemCopyAsImage(pView); if (pItem == NULL) { pItem = new CItemCopyAsImage(pView->m_pDoc); pItem->CopyAllToClipboard(); delete pItem; pItem = nullptr; } else { pItem->CopyAllToClipboard(); } return 1; }