📄 snapdlg.cpp
字号:
// SnapDlg.cpp: implementation of the CSnapDlg class.
//
/*
Copyright 2001 Anish Mistry. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY ANISH MISTRY ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of Anish Mistry or AM Productions.
* Variation of the FreeBSD License. http://www.freebsd.org/copyright/freebsd-license.html
*/
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SnapDlg.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSnapDlg::CSnapDlg()
{
m_szMoveOffset.cx = 0;
m_szMoveOffset.cy = 0;
// snap pixels
m_nSnapPixels = 5;
// get the desktop rectangle for snappyness
GetWindowRect(GetDesktopWindow(),&m_rDesktopRect);
}
CSnapDlg::~CSnapDlg()
{
}
LRESULT CSnapDlg::DlgProc(HWND hDlg,UINT nMessage,WPARAM wParam,LPARAM lParam)
{// begin DlgProc
switch (nMessage)
{
case WM_MOVING:
OnMoving(wParam,lParam);
break;
case WM_NCLBUTTONDOWN:
OnNcLButtonDown(wParam,lParam);
break;
}
return CMyDialog::DlgProc(hDlg,nMessage,wParam,lParam);
}// end DlgProc
void CSnapDlg::OnMoving(WPARAM &wParam,LPARAM &lParam)
{// begin OnMoving
RECT *pRect = (RECT *)lParam;
// calculate window size
SIZE szSize = {pRect->right-pRect->left,pRect->bottom-pRect->top};
POINT pt = {NULL};
GetCursorPos(&pt);
pRect->left = pt.x-m_szMoveOffset.cx;
pRect->top = pt.y-m_szMoveOffset.cy;
pRect->right = pRect->left+szSize.cx;
pRect->bottom = pRect->top+szSize.cy;
// snap window to screen edges
if(pRect->top < m_nSnapPixels && pRect->top > -m_nSnapPixels)
{// begin snap to top
pRect->top = 0;
pRect->bottom = szSize.cy;
}// end snap to top
if(pRect->left < m_nSnapPixels && pRect->left > -m_nSnapPixels)
{// begin snap to left
pRect->left = 0;
pRect->right = szSize.cx;
}// end snap to left
if(pRect->right < m_rDesktopRect.right+m_nSnapPixels && pRect->right > m_rDesktopRect.right-m_nSnapPixels)
{// begin snap to right
pRect->right = m_rDesktopRect.right;
pRect->left = m_rDesktopRect.right-szSize.cx;
}// end snap to right
if(pRect->bottom < m_rDesktopRect.bottom+m_nSnapPixels && pRect->bottom > m_rDesktopRect.bottom-m_nSnapPixels)
{// begin snap to bottom
pRect->bottom = m_rDesktopRect.bottom;
pRect->top = m_rDesktopRect.bottom-szSize.cy;
}// end snap to bottom
}// end OnMoving
void CSnapDlg::OnNcLButtonDown(WPARAM wParam,LPARAM lParam)
{// begin OnNcLButtonDown
if(wParam == HTCAPTION)
{// begin save mouse coord
// calculate drag offset
POINT pt = {LOWORD(lParam),HIWORD(lParam)};
RECT rRect = {NULL};
GetWindowRect(m_hDlg,&rRect);
m_szMoveOffset.cx = pt.x-rRect.left;
m_szMoveOffset.cy = pt.y-rRect.top;
}// end save mouse coord
}// end OnNcLButtonDown
void CSnapDlg::OnDisplayChange(void)
{// begin OnDisplayChange
// get the new desktop rectangle
GetWindowRect(GetDesktopWindow(),&m_rDesktopRect);
}// end OnDisplayChange
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -