为什么RtlMoveMemory老是失败?

lwsxln 2010-05-12 08:36:07
class Kernel32
{
public struct POINTAPI
{
public int x;
public int y;
}
public struct MINMAXINFO
{
public POINTAPI ptReserved;
public POINTAPI ptMaxSize;
public POINTAPI ptMaxPosition;
public POINTAPI ptMinTrackSize;
public POINTAPI ptMaxTrackSize;
}

[DllImport("Kernel32.dll")]
public static extern bool RtlMoveMemory(int pDest, MINMAXINFO pSrc, byte ByteLen);
[DllImport("Kernel32.dll")]
public static extern bool RtlMoveMemory(MINMAXINFO pDest, int pSrc, byte ByteLen);






private int WndProc(int Wnd, int Msg, int WParam, int LParam)
{
const int WM_MOVING=534;

Kernel32.MINMAXINFO minMaxInfo=new Kernel32.MINMAXINFO();
switch(Msg)
{
case 675://鼠标移出
mouseIsInWindow=false;
break;
case WM_MOVING://正在移动
Debug.WriteLine(Kernel32.RtlMoveMemory(minMaxInfo,LParam, 40));
if(minMaxInfo.ptReserved.x<1)
{
minMaxInfo.ptReserved.x=0;
minMaxInfo.ptMaxSize.x=this.Width;
}
else if(minMaxInfo.ptReserved.y<1)
{
minMaxInfo.ptReserved.y=0;
minMaxInfo.ptMaxSize.y=this.Height;
}
else if (minMaxInfo.ptMaxSize.x > Screen.GetWorkingArea(this).Width)
{
Debug.WriteLine(minMaxInfo.ptReserved.x);
minMaxInfo.ptReserved.x = Screen.GetWorkingArea(this).Width - this.Width;
minMaxInfo.ptMaxSize.x = Screen.GetWorkingArea(this).Width;
}
else if (minMaxInfo.ptMaxSize.y > Screen.GetWorkingArea(this).Height)
{
minMaxInfo.ptReserved.y = Screen.GetWorkingArea(this).Height - this.Height;
minMaxInfo.ptMaxSize.y = Screen.GetWorkingArea(this).Height;
}
break;
Debug.WriteLine(Kernel32.RtlMoveMemory(LParam, minMaxInfo, 40));
}

return User32.CallWindowProc(oldWindowLong, Wnd, Msg, WParam, LParam);







我想拦截wm_moving消息,来限制窗口移动,为什么RtlMoveMemory老是显示false?
...全文
321 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lwsxln 2010-05-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zdbb 的回复:]
这2句反过来看看:
break;
Debug.WriteLine(Kernel32.RtlMoveMemory(LParam, minMaxInfo, 40));
改成:
Debug.WriteLine(Kernel32.RtlMoveMemory(LParam, minMaxInfo, 40));
break;
[/Quote]


成功了,应该是下面这样,不过还是感谢你给的灵感
[DllImport("Kernel32.dll")]
public static extern bool RtlMoveMemory(int pDest,ref MINMAXINFO pSrc, byte ByteLen);
[DllImport("Kernel32.dll")]
public static extern bool RtlMoveMemory(ref MINMAXINFO pDest, int pSrc, byte ByteLen);
只在此山中 2010-05-12
  • 打赏
  • 举报
回复
这2句反过来看看:
break;
Debug.WriteLine(Kernel32.RtlMoveMemory(LParam, minMaxInfo, 40));
改成:
Debug.WriteLine(Kernel32.RtlMoveMemory(LParam, minMaxInfo, 40));
break;
lwsxln 2010-05-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zdbb 的回复:]
要加ref:
[DllImport("Kernel32.dll")]
public static extern bool RtlMoveMemory(ref int pDest, MINMAXINFO pSrc, byte ByteLen);
[DllImport("Kernel32.dll")]
public static extern bool RtlMoveMemory……
[/Quote]

返回为true了。

但是为什么还是不能限制窗口的移动?
只在此山中 2010-05-12
  • 打赏
  • 举报
回复
要加ref:
[DllImport("Kernel32.dll")]
public static extern bool RtlMoveMemory(ref int pDest, MINMAXINFO pSrc, byte ByteLen);
[DllImport("Kernel32.dll")]
public static extern bool RtlMoveMemory(ref MINMAXINFO pDest, int pSrc, byte ByteLen);

110,526

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧