300分!!求助对话框拖动问题!

qqxia 2004-12-08 04:53:27
怎么才能实现鼠标按住对话框的边框,拖动对话框大小,在鼠标按下拖动的时候不改变对话框大小,但是显示对话框未来的大小的虚线框,在鼠标松开的时候才改变对话框大小!!

我的帖子:
http://community.csdn.net/Expert/topic/3623/3623634.xml?temp=.8683893
http://community.csdn.net/Expert/topic/3627/3627110.xml?temp=2.361697E-02
...全文
186 点赞 收藏 18
写回复
18 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
handwolf 2004-12-10
解决方法:
因为找不到onsizing,所以只能在onsize里面跳出,
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);//get out of system sizing

再模拟鼠标左键按下
SetCursorPos(m_rctWindow.left,m_rctWindow.top);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);//down the left mouse
SetCursorPos(oldPoint.x,oldPoint.y);//位置要是原来光标的位置

然后在onsizing后的第一次OnLButtonDown里面得到点在框架的位置(8个位置)!

接下来的就是在onmousemove和onlbuttonup里面处理了!
绘画的方法是dandycheung(珠穆朗玛) 所说的方法!

希望大家多交流,怎么得到点在框架的位置(8个位置)?????????
///////////////
.h文件
///////////////
对话框头文件中加入
int m_flagSize;//标志位,控制是否在改变大小!1的时候在改变大小
CRect m_rctWindow;//窗口矩形
CRect m_rctDraw;//虚线矩形
int m_moveDirect; //拖动的位置,1~8代表上右下左,右上,右下,左下,左上

afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
///////////////////////////////////////////////////////////////////////////////
///////////////
.cpp文件
///////////////
void CResizingDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

if(m_flagSize == 1){
m_flagSize = -1;
//erase the pre rectangle start
{
HDC hdc = ::GetDC(NULL);
CDC* pDC = CDC::FromHandle(hdc);
CRectTracker rectTracker;
m_rctDraw.NormalizeRect();
rectTracker.DrawTrackerRect(&m_rctDraw, NULL, pDC, NULL);
::ReleaseDC(NULL,hdc);
}
//erase the pre rectangle end

//sizing the window
m_rctWindow.NormalizeRect();
::SetWindowPos(this->GetSafeHwnd(),HWND_TOP,m_rctWindow.left,m_rctWindow.top,m_rctWindow.Width(),m_rctWindow.Height(),SWP_SHOWWINDOW);

ReleaseCapture();
}
CDialog::OnLButtonUp(nFlags, point);
}

void CResizingDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy) ;
// TODO: Add your message handler code here

if(m_flagSize != 0){
m_flagSize =0;
}else if(m_flagSize == 0){
GetClientRect(&m_rctWindow);
ClientToScreen(&m_rctWindow);
CPoint oldPoint;
GetCursorPos(&oldPoint); //get the pos of cursor

mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);//get out of system sizing
SetCursorPos(m_rctWindow.left,m_rctWindow.top);//for left mouse button down in the client area
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);//down the left mouse
SetCursorPos(oldPoint.x,oldPoint.y);//
m_flagSize = 1;
}
}

void CResizingDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

if(m_flagSize == 1){//sizing the window
CPoint oldPoint = point;
this->ClientToScreen(&oldPoint);

//erase the pre rectangle start
{
HDC hdc = ::GetDC(NULL);
CDC* pDC = CDC::FromHandle(hdc);
CRectTracker rectTracker;
m_rctDraw.NormalizeRect();
rectTracker.DrawTrackerRect(&m_rctDraw, NULL, pDC, NULL);
::ReleaseDC(NULL,hdc);
}
//erase the pre rectangle end

//changed the data of rectangle start
GetWindowRect(&m_rctWindow);
switch(m_moveDirect) {
case 1://top
m_rctWindow.top = oldPoint.y;
break;
case 2://right
m_rctWindow.right = oldPoint.x;
break;
case 3://bottom
m_rctWindow.bottom = oldPoint.y;
break;
case 4://left
m_rctWindow.left = oldPoint.x;
break;
case 5://topright
m_rctWindow.top = oldPoint.y;
m_rctWindow.right = oldPoint.x;
break;
case 6://bottomright
m_rctWindow.bottom= oldPoint.y;
m_rctWindow.right = oldPoint.x;
break;
case 7://bottomleft
m_rctWindow.left = oldPoint.x;
m_rctWindow.bottom = oldPoint.y;
break;
case 8://topleft
m_rctWindow.left = oldPoint.x;
m_rctWindow.top = oldPoint.y;
break;
default:
break;
}
m_rctDraw = m_rctWindow;
//changed the data of rectangle end


//Draw the rectangle start
{
HDC hdc = ::GetDC(NULL);
CDC* pDC = CDC::FromHandle(hdc);
CRectTracker rectTracker;
m_rctDraw.NormalizeRect();
rectTracker.DrawTrackerRect(&m_rctDraw, NULL, pDC, NULL);
::ReleaseDC(NULL,hdc);
}
//Draw the rectangle end

}else{

}


CDialog::OnMouseMove(nFlags, point);
}

void CResizingDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
GetWindowRect(&m_rctWindow);
CPoint oldPoint;
GetCursorPos(&oldPoint); //get the pos of cursor

if(m_flagSize == 1)
{
//check the pos of cursor start
//15---can be changed
if(fabs(oldPoint.y - m_rctWindow.top)<15){
if(fabs(oldPoint.x - m_rctWindow.right)<15){//topright
m_moveDirect = 5;
m_rctDraw.left = m_rctWindow.left;
m_rctDraw.right = m_rctWindow.left;
m_rctDraw.top = m_rctWindow.bottom;
m_rctDraw.bottom= m_rctWindow.bottom;
}else if(fabs(oldPoint.x - m_rctWindow.left)<15){//topleft
m_moveDirect = 8;
m_rctDraw.left = m_rctWindow.right;
m_rctDraw.right = m_rctWindow.right;
m_rctDraw.top = m_rctWindow.bottom;
m_rctDraw.bottom= m_rctWindow.bottom;
}else{//上
m_moveDirect = 1;
m_rctDraw.left = m_rctWindow.left;
m_rctDraw.right = m_rctWindow.right;
m_rctDraw.top = m_rctWindow.bottom;
m_rctDraw.bottom= m_rctWindow.bottom;
}
}else if(fabs(oldPoint.y - m_rctWindow.bottom)<15){
if(fabs(oldPoint.x - m_rctWindow.right)<15){//bottomright
m_moveDirect = 6;
m_rctDraw.left = m_rctWindow.left;
m_rctDraw.right = m_rctWindow.left;
m_rctDraw.top = m_rctWindow.top;
m_rctDraw.bottom= m_rctWindow.top;
}else if(fabs(oldPoint.x - m_rctWindow.left)<15){//bottomleft
m_moveDirect = 7;
m_rctDraw.left = m_rctWindow.right;
m_rctDraw.right = m_rctWindow.right;
m_rctDraw.top = m_rctWindow.top;
m_rctDraw.bottom= m_rctWindow.top;
}else{//下
m_moveDirect = 3;
m_rctDraw.left = m_rctWindow.left;
m_rctDraw.right = m_rctWindow.right;
m_rctDraw.top = m_rctWindow.top;
m_rctDraw.bottom= m_rctWindow.top;
}
}else if(fabs(oldPoint.x - m_rctWindow.right)<15){//right
m_moveDirect = 2;
m_rctDraw.left = m_rctWindow.left;
m_rctDraw.right = m_rctWindow.left;
m_rctDraw.top = m_rctWindow.top;
m_rctDraw.bottom= m_rctWindow.bottom;
}else if(fabs(oldPoint.x - m_rctWindow.left)<15){//left
m_moveDirect = 4;
m_rctDraw.left = m_rctWindow.right;
m_rctDraw.right = m_rctWindow.right;
m_rctDraw.top = m_rctWindow.top;
m_rctDraw.bottom= m_rctWindow.bottom;
}else{
m_flagSize = 0;
}
//check the pos of cursor end

if (m_flagSize == 1) {
SetCapture();
}
}
CDialog::OnLButtonDown(nFlags, point);
}

回复
handwolf 2004-12-10
to SmallGreenGrass():

已经给你发了!
回复
dandycheung 2004-12-09
答案见此帖 http://community.csdn.net/Expert/topic/3623/3623634.xml?temp=.8533289
原来楼主海发了好几个帖呢!我接分来了。;) 窃喜中...
回复
SmallGreenGrass 2004-12-09
给我一个:wwb130@eyou.com
回复
handwolf 2004-12-09
我也解决了,想要的留下email!
回复
handwolf 2004-12-09
楼主是在什么地方SetCapture()的?
回复
qqxia 2004-12-09
现在还有一点点问题,呵呵,等我完全解决了,总结一下贴出来!
回复
oyljerry 2004-12-09
用的什么方法?
回复
xdsh00 2004-12-09
要分啊....嘿嘿
回复
qqxia 2004-12-09
to all:
问题搞定了,多谢dandycheung(珠穆朗玛),一会散分!
回复
qqxia 2004-12-08
主要是显示对话框未来的大小的虚线框,aoosang(智慧的鱼) 的例子好像什么都没有做,呵呵
回复
koko1998 2004-12-08
CS_HREDRAW|CS_VREDRAW
应该跟以上两个属性有关
回复
laogong 2004-12-08
up学习
回复
koko1998 2004-12-08
关注中
回复
aoosang 2004-12-08
重载WM_SIZING消息不行??
回复
aoosang 2004-12-08
呵呵,我给你说的方法不行?我已经给你信箱里发了个demo
回复
qqxia 2004-12-08
DentistryDoctor(雅克医生<改行做程序员了>) 给的例子不行!不是我所要求的!
回复
DentistryDoctor 2004-12-08
http://www.codeguru.com/Cpp/W-D/dislog/resizabledialogs/article.php/c1917/
回复
相关推荐
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2004-12-08 04:53
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……