#include "stdafx.h"
#include "MagnetDialog.h"
char * g_ChildClassNam = "MagneticDlg";
CMagnetDialog *dlg = NULL;
LRESULT CALLBACK WndMagnetProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
{
switch( nMsg )
{
case WM_PAINT:
{
PAINTSTRUCT ps = { 0 };
HDC dc = BeginPaint( hWnd, &ps );
char *pBuf = "磁性窗口";
::TextOut( dc, 100, 50, pBuf, strlen(pBuf) );
::EndPaint( hWnd, &ps);
}
break;
case WM_LBUTTONDOWN:
::SendMessage( hWnd, WM_SYSCOMMAND, SC_MOVE | HTCAPTION ,NULL);
break;
case WM_WINDOWPOSCHANGING:
dlg->ChildCheckMagnetism( lParam );
break;
case WM_CLOSE:
case WM_DESTROY:
break;
}
return DefWindowProc( hWnd, nMsg, wParam, lParam );
}
CMagnetDialog::CMagnetDialog( HINSTANCE hInst, HWND pwnd )
:m_hInst(hInst), m_pWnd(pwnd)
{
dlg = this;
m_nWith = 300;
m_nHeight = 150;
m_isAdsorption = false;
::GetWindowRect( m_pWnd, &m_RcParent );
GetMainRc( &m_RcParent );
InitDlg( g_ChildClassNam );
m_hWnd = ::CreateWindow( g_ChildClassNam, "磁性窗口",
WS_TILEDWINDOW|WS_VISIBLE|WS_SYSMENU|WS_MINIMIZEBOX|WS_CAPTION|DS_CENTER,
400, 450, m_nWith, m_nHeight,
NULL, NULL, m_hInst, NULL );
}
CMagnetDialog::~CMagnetDialog()
{
}
BOOL CMagnetDialog::InitDlg( char * lpClassName )
{
WNDCLASSEX wce = { 0 };
wce.cbSize = sizeof( wce );
wce.style = CS_HREDRAW|CS_VREDRAW;
wce.cbClsExtra = 0;
wce.cbWndExtra = 0;
wce.hInstance = m_hInst;
wce.lpfnWndProc = WndMagnetProc;
wce.hIcon = 0;
wce.hIconSm = NULL;
wce.hCursor = LoadCursor(NULL,IDC_ARROW);
wce.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wce.lpszMenuName = NULL;
wce.lpszClassName = lpClassName;
ATOM nAtom = RegisterClassEx( &wce );
if( 0 == nAtom )
{
return FALSE;
}
return TRUE;
}
// ON_WM_MOVING()
// CMagnetDialog 消息处理程序
void CMagnetDialog::GetMainRc( RECT * rc )
{
::CopyRect( &m_RcParent, rc );
//------------------------------------------顶端磁力范围
m_TopRc.left = m_RcParent.left-OFFSETMOVE;
m_TopRc.top = m_RcParent.bottom-OFFSETMOVE;
m_TopRc.right = m_RcParent.right+OFFSETMOVE;
m_TopRc.bottom = m_RcParent.bottom+OFFSETMOVE;
//------------------------------------------左侧磁力范围 m_LeftRc
if( m_isAdsorption )
{
::SetWindowPos( m_hWnd, 0, rc->left, rc->bottom, 0, 0, SWP_NOSIZE );
}
m_LeftRc.left = m_RcParent.left-OFFSETMOVE;
m_LeftRc.top = m_RcParent.bottom-OFFSETMOVE;
m_LeftRc.right = m_RcParent.left+OFFSETMOVE;
m_LeftRc.bottom = m_RcParent.bottom+m_nHeight+OFFSETMOVE;
}
void CMagnetDialog::ChildCheckMagnetism( LPARAM lParam )
{
PWINDOWPOS pPos = (WINDOWPOS *)lParam;
POINT pt;
pt.x = pPos->x;
pt.y = pPos->y;
if( ( pPos->x | pPos->y | pPos->cx | pPos->cy ) == 0 )
return;
m_isAdsorption = false;
if( ::PtInRect( &m_TopRc, pt ) )
{
m_isAdsorption = true;
pPos->y = m_RcParent.bottom;
pPos->cy = pPos->y + pPos->cy - m_RcParent.bottom;
}
if( ::PtInRect( &m_LeftRc, pt ) )
{
m_isAdsorption = true;
pPos->x = m_RcParent.left;
pPos->cx = pPos->x + pPos->cx - m_RcParent.left;
}
return;
}
Win32写的磁性窗体
4星 · 超过85%的资源 需积分: 9 86 浏览量
2012-09-14
16:52:55
上传
评论
收藏 17KB RAR 举报
chel
- 粉丝: 7
- 资源: 28
最新资源
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- windows注册表编辑工具
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- 校园通行码预约管理系统20240522075502
- 车类型数据集6250张VOC+YOLO格式.zip
- The PyTorch implementation of STGCN.STGCN-main.zip
- 092300108.cpp
- 车类型数据集6000张VOC+YOLO格式.zip
- for daily read
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈