📄 viewwnd.cpp
字号:
nPos2=pData->m_ptPaintOrg.y;
//获得鼠标所在的父窗口用户区,并将坐标拷贝到rt0中
GetParent()->GetClientRect(rt0);
//根据鼠标形状来确定鼠标抬起时候的操作
switch(m_iCursorType)
{
case CT_CROSS: //十字形状
if(bTrack) //如果按下过
{
if(L) //左拉
{
if(Rect.left==0)
{
if(Rect.top==0)
{
Rect.right=m_SelectZoom.right-m_SelectZoom.left;
Rect.bottom=m_SelectZoom.bottom-m_SelectZoom.top;
}
else
{
Rect.bottom=m_SelectZoom.bottom+(point.y-t)*(pData->m_nZoomFactor);
Rect.right=m_SelectZoom.right-m_SelectZoom.left;
}
}
else if(Rect.top==0)
{
Rect.right=m_SelectZoom.right+(point.x-s)*(pData->m_nZoomFactor);
Rect.bottom=m_SelectZoom.bottom-m_SelectZoom.top;
}
else if(Rect.right==shuzu3)
{
if(Rect.bottom==shuzu5)
{
Rect.right=shuzu3;
Rect.bottom=shuzu5;
}
else
{
Rect.bottom=m_SelectZoom.bottom+(point.y-t)*(pData->m_nZoomFactor);
Rect.right=shuzu3;
}
}
else if(Rect.bottom==shuzu5)
{
Rect.right=m_SelectZoom.right+(point.x-s)*(pData->m_nZoomFactor);
Rect.bottom=shuzu5;
}
else
{
Rect.right=m_SelectZoom.right+(point.x-s)*(pData->m_nZoomFactor);
Rect.bottom=m_SelectZoom.bottom+(point.y-t)*(pData->m_nZoomFactor);
}
}//判断L结束
else //如果不是左拉
{
if(H)//水平拉
{
if(Rect.bottom<0 )
{
Rect.bottom=0;
Rect.right=m_SelectZoom.right;
}
else if(Rect.bottom>shuzu5)
{
Rect.bottom=shuzu5;
Rect.right=m_SelectZoom.right;
}
else
{
Rect.bottom=point.y*(pData->m_nZoomFactor)+nPos2;
Rect.right=m_SelectZoom.right;
}
}//结束H
else if(V) //垂直落
{
if(Rect.right<0)
{
Rect.right=0;
Rect.bottom=m_SelectZoom.bottom;
}
else if(Rect.right>shuzu3)
{
Rect.right=shuzu3;
Rect.bottom=m_SelectZoom.bottom;
}
else
{
Rect.bottom=m_SelectZoom.bottom;
Rect.right=point.x*(pData->m_nZoomFactor)+nPos1;
}
}//结束V
else
{
if(Rect.right<0&&Rect.bottom>shuzu5)
{
Rect.right=0;
Rect.bottom=shuzu5;
}
else if(Rect.right>0&&Rect.right<shuzu3&&Rect.bottom>shuzu5)
{
Rect.right=(point.x)*(pData->m_nZoomFactor)+nPos1;
Rect.bottom=shuzu5;
}
else if(Rect.right>shuzu3&&Rect.bottom>shuzu5)
{
Rect.right=shuzu3;
Rect.bottom=shuzu5;
}
else if(Rect.right<0&&Rect.bottom<shuzu5&&Rect.bottom>0)
{
Rect.right=0;
Rect.bottom=(point.y)*(pData->m_nZoomFactor)+nPos2;
}
else if(Rect.right>shuzu3&&Rect.bottom<shuzu5&&Rect.bottom>0)
{
Rect.right=shuzu3;
Rect.bottom=(point.y)*(pData->m_nZoomFactor)+nPos2;
}
else if(Rect.right<0&&Rect.bottom<0)
{
Rect.right=0;
Rect.bottom=0;
}
else if(Rect.right>0&&Rect.right<shuzu3&&Rect.bottom<0)
{
Rect.right=(point.x)*(pData->m_nZoomFactor)+nPos1;
Rect.bottom=0;
}
else if(Rect.right>shuzu3&&Rect.bottom<0)
{
Rect.right=shuzu3;
Rect.bottom=0;
}
else
{
if(zx==point.x&&zy==point.y)
{
Rect.top=m_SelectZoom.top;
Rect.left=m_SelectZoom.left;
Rect.bottom=m_SelectZoom.bottom;
Rect.right=m_SelectZoom.right;
}
else
{
Rect.bottom=(point.y)*(pData->m_nZoomFactor)+nPos2;
Rect.right=(point.x)*(pData->m_nZoomFactor)+nPos1;
}
}
}
}
m_SelectZoom=Rect;
if(m_SelectZoom.top>m_SelectZoom.bottom)
{
nTemp = m_SelectZoom.bottom;
m_SelectZoom.bottom = m_SelectZoom.top;
Rect.bottom = Rect.top;
m_SelectZoom.top = nTemp;
Rect.top = nTemp;
}
if(m_SelectZoom.left>m_SelectZoom.right)
{
nTemp = m_SelectZoom.right;
m_SelectZoom.right = m_SelectZoom.left;
Rect.right= Rect.left;
m_SelectZoom.left = nTemp;
Rect.left = nTemp;
}
if(m_SelectZoom.top<0)
{
m_SelectZoom.top=0;
}
if(m_SelectZoom.left<0)
{
m_SelectZoom.left=0;
}
if(m_SelectZoom.right>shuzu3)
{
m_SelectZoom.right=shuzu3;
}
if(m_SelectZoom.bottom>shuzu5)
{
m_SelectZoom.bottom=shuzu5;
}
tempRect.top = m_SelectZoom.top*10;
tempRect.left = m_SelectZoom.left*10;
tempRect.right = m_SelectZoom.right*10;
tempRect.bottom = m_SelectZoom.bottom*10;
if(tempRect.top<0)
{
tempRect.top = 0;
}
if(tempRect.left<0)
{
tempRect.left = 0;
}
m_pPositionInfo->SetPosition(tempRect,0);
bTrack=FALSE;
H=FALSE;
V=FALSE;
L=FALSE;
//释放鼠标
SetCapture();
ReleaseCapture();
char str[36];
GetWindowsDirectory(InitDir2,sizeof(InitDir2));
lstrcat(InitDir2,"\\twain_32\\MTIScanner\\jiaose.ini");
sprintf(str, "%d", m_SelectZoom.left);
WritePrivateProfileString("select", "left", str, InitDir2);
sprintf(str, "%d", m_SelectZoom.right);
WritePrivateProfileString("select", "right", str, InitDir2);
sprintf(str, "%d", m_SelectZoom.top);
WritePrivateProfileString("select", "top", str, InitDir2);
sprintf(str, "%d",m_SelectZoom.bottom );
WritePrivateProfileString("select", "bottom", str, InitDir2);
pScanner->SetSelectZoom(tempRect);
InvalidateContainers();
OnTimer(1);
}
break;
//此时,鼠标为其它形状时,程序不处理
case CT_ZOOMIN:
break;
case CT_HAND:
//::SetCursor(theApp.LoadCursor(IDC_HAND));
bTrackHand=FALSE;
SetCapture();
ReleaseCapture();
break;
default:
break;
}
}
void CViewWnd::OnCancelMode()
{
CWnd::OnCancelMode();
}
//////////////////////////////////////////////////////////////////
//按下SHIFT键改变鼠标形状以进行缩放操作,响应键盘按下消息 // //
//////////////////////////////////////////////////////////////////
void CViewWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch(nChar)
{
case VK_SHIFT:
if (pViewWnd->m_iCursorType == CT_ZOOMIN)
{
m_iCursorType = CT_ZOOMOUT;
::SetCursor(theApp.LoadCursor(203));
}
default:
break;
}
CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}
//////////////////////////////////////////////////////////////////
//抬起SHIFT键改变鼠标形状以进行缩放操作,响应键盘按下消息 // //
//////////////////////////////////////////////////////////////////
void CViewWnd::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch(nChar)
{
case VK_SHIFT:
if(pViewWnd->m_iCursorType == CT_ZOOMOUT)
{
m_iCursorType = CT_ZOOMIN;
::SetCursor(m_curZoomIn);
}
default:
break;
}
CWnd::OnKeyUp(nChar, nRepCnt, nFlags);
}
////////////////////////////////////////////////////////////////////////////
////使标尺、视区数据无效,以响应ON_PAINT消息,被其它需要刷新显示区的程序调用// //
////////////////////////////////////////////////////////////////////////////
void CViewWnd::InvalidateContainers()
{
pHRulerWnd->InvalidateRect(NULL);
pVRulerWnd->InvalidateRect(NULL);
pViewWnd->InvalidateRect(NULL);
}
////////////////////////////////////////////////////////////////////////////
//画黑白流动选择扫描框 //
////////////////////////////////////////////////////////////////////////////
void CViewWnd::DrawBlackandWhiteLines(CClientDC* pDC,RECT SelectZoom,BOOL bWhite,BOOL bDash)
{
CPen WhitePen( PS_SOLID, 1, RGB(255,255,255));
CPen BlackPen( PS_SOLID, 1, RGB(0,0,0));;
CPen* oldPen;
short OldROP;
int i;
//画白笔
if(bWhite)
{
oldPen=pDC->SelectObject( &WhitePen );
OldROP=pDC->SetROP2( R2_COPYPEN );
}
//画黑笔
else
{
pDC->SelectObject( &BlackPen );
OldROP=pDC->SetROP2( R2_COPYPEN );
}
//画黑白线框以产生流动效果
if(bDash)
{
for(i=1;i<=(SelectZoom.right-SelectZoom.left)/10;i++)
{
pDC->MoveTo(SelectZoom.left-10+10*i,SelectZoom.top);
pDC->LineTo(SelectZoom.left-10+5+10*i,SelectZoom.top);
}
//画从右上角到右下角的垂直线
for(i=1;i<=((SelectZoom.bottom-SelectZoom.top)/10);i++)
{
pDC->MoveTo((SelectZoom.right),10*i+SelectZoom.top-10);
pDC->LineTo((SelectZoom.right),5+10*i+SelectZoom.top-10);
}
//画从右下角到左下角的水平线
for(i=(SelectZoom.right-SelectZoom.left)/10;i>0;i--)
{
pDC->MoveTo(SelectZoom.left+10*i,SelectZoom.bottom);
pDC->LineTo(SelectZoom.left-5+10*i,SelectZoom.bottom);
}
//画从左下角到左上角的垂直线
for(i=((SelectZoom.bottom-SelectZoom.top)/10);i>0;i--)
{
pDC->MoveTo(SelectZoom.left,10*i+SelectZoom.top);
pDC->LineTo(SelectZoom.left,10*i+SelectZoom.top-5);
}
}
else
{
for(i=1;i<=(SelectZoom.right-SelectZoom.left)/10;i++)
{
pDC->MoveTo(10*i+5+SelectZoom.left-10,SelectZoom.top);
pDC->LineTo(10*i+10+SelectZoom.left-10,SelectZoom.top);
}
for(i=1;i<=(SelectZoom.bottom-SelectZoom.top)/10;i++)
{
pDC->MoveTo(SelectZoom.right,10*i+5+SelectZoom.top-10);
pDC->LineTo(SelectZoom.right,10+10*i+SelectZoom.top-10);
}
for(i=(SelectZoom.right-SelectZoom.left)/10;i>0;i--)
{
pDC->MoveTo(10*i+SelectZoom.left-5,SelectZoom.bottom);
pDC->LineTo(10*i+SelectZoom.left-10,SelectZoom.bottom);
}
for(i=(SelectZoom.bottom-SelectZoom.top)/10;i>0;i--)
{
pDC->MoveTo(SelectZoom.left,10*i+SelectZoom.top-5);
pDC->LineTo(SelectZoom.left,10*i+SelectZoom.top-10);
}
}//End of if(bDash)
pDC->SetROP2(OldROP);
pDC->SelectObject( oldPen );
}
////////////////////////////////////////////////////////////////////////////
//响应系统时钟,调用上面流动扫描框函数 //
////////////////////////////////////////////////////////////////////////////
void CViewWnd::OnTimer(UINT nIDEvent)
{
CClientDC DC(this);
CPen WhitePen( PS_SOLID, 1, RGB(255,255,255));
CPen BlackPen( PS_SOLID, 1, RGB( 0, 0, 0));
CBrush Brush2;
CPoint point;
static bDraw=TRUE;
if(nIDEvent==1)
{
if(bDraw) //从黑线开始画
{
DrawBlackandWhiteLines(&DC,m_SelectZoom,TRUE,TRUE);
DrawBlackandWhiteLines(&DC,m_SelectZoom,FALSE,FALSE);
bDraw=FALSE;
}
else
{
//从黑线开始画虚线框
DrawBlackandWhiteLines(&DC,m_SelectZoom,TRUE,FALSE);
DrawBlackandWhiteLines(&DC,m_SelectZoom,FALSE,TRUE);
bDraw=TRUE;
}
}
}
////////////////////////////////////////////////////////////////////////////
//画矩形框,被CPosition调用,用来实现通过信息框输入扫描框的时候,画扫描框. //
////////////////////////////////////////////////////////////////////////////
void CViewWnd::DrawRect(RECT re)
{
int left,top,right,bottom;
CFile myFile;
left=re.left/10;
top=re.top/10;
right=re.right/10;
bottom=re.bottom/10;
if((left<0)||(top<0)||(right>shuzu3)||(bottom>shuzu5))
{
if(left<0)
{
left=0;
}
if(top<0)
{
top=0;
}
if(right>shuzu3)
{
right=shuzu3;
}
if(bottom>shuzu5)
{
bottom=shuzu5;
}
}
m_SelectZoom.left=left;
m_SelectZoom.top=top;
m_SelectZoom.right=right;
m_SelectZoom.bottom=bottom;
InvalidateContainers();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -