this.SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 0); 总是报 this.Handle 类型错误,但是这是窗口的句柄呀

解决方案 »

  1.   

    你的SetWindowPos是怎么定义的?
    贴出来看看。
      

  2.   

    this.SetWindowPos(this, -1, 0, 0, 0, 0, 0);
      

  3.   

    你在声明SetWindowPos API的时候,是不是句柄参数使用的是Int32类型?
    如果是的话,强制转化一下就可以了。
    this.SetWindowPos((Int32)this.Handle, -1, 0, 0, 0, 0, 0);不过最好还是用IntPtr来声明,这样一看就知道是句柄。
      

  4.   

    javascript也可以移动窗体:<html>
    <head>
    <title>window.resizeTo()函数</title><script laguage="javascript">
    <!--
    function movewin(form)
    {
    var winx=form.X.value;
    var winy=form.Y.value;
    window.moveTo(winx,winy);
    }
    //-->
    </script></head>
    <body bgcolor="#FFFFFF" text="#000000">
    <form name=form1>
    <table border=0 align=center width="575">
    <tr> 
    <td colspan=3 align=center bgcolor=red><font color=blue size=3>请输入窗口目标位置的 
    x、y坐标,再点击下列按钮,看看窗口的效果</font></td>
    </tr>
    <tr> 
    <td> 
    <input type=text name="X" style="background-color:blue;color:red">
    </td>
    <td> 
    <input type=text name="Y" style="background-color:blue;color:red">
    </td>
    <td> 
    <input type=button value="move window" onclick=movewin(this.form) style="background-color:blue;color:red">
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>
      

  5.   

    下个C#api精灵,找到SetWindowPos后引用
    接分
      

  6.   

    转换一下this.SetWindowPos((int)this.Handle, -1, 0, 0, 0, 0, 0);
      

  7.   

    网上搜索到的 :  hwnd和hdc当然不同了.连这都没搞清楚.
    hwnd是windows句柄.
    hdc是专用于绘制的句柄.两者怎么是一样呢?最简单的是连值都不同.------------------------------
    与这个有关吗?
      

  8.   

    最后是这么搞定的:  IntPtr ParenthWnd = new IntPtr(0); 
      IntPtr EdithWnd = new IntPtr(0); 
      
      //查到窗体,得到整个窗体 
      //ParenthWnd = FindWindow(null,"xxxxxxx"); 
      
      //判断这个窗体是否有效 
      if (!ParenthWnd.Equals(IntPtr.Zero)) 
         SetWindowPos(ParenthWnd , -1, 100,700,800, 900,6);
      

  9.   


    转换一下this.SetWindowPos((int)this.Handle, -1, 0, 0, 0, 0, 0);--------------------------------
    不行的
      

  10.   

    如果直接转换不行的话,那应该是this.Handle本来就不是一个有效的句柄值。
    MSDN上也明确地说了存在两者之间的转换:IntPtr 到 Int32 的转换  [C#]请参见
    IntPtr 结构 | IntPtr 成员 | System 命名空间 | ToInt32 | IntPtr 成员(Visual J# 语法) | C++ 托管扩展编程 
    要求
    平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版 - Windows CE .NET
    语言
    C#C++JScriptVisual Basic全部显示
    将指定的 IntPtr 的值转换为 32 位有符号整数。[Visual Basic]
    returnValue = IntPtr.op_Explicit(value)[C#]
    public static explicit operator int(
       IntPtr value
    );[C++]
    public: static int op_Explicit();[JScript]
    returnValue = Int32(value);[Visual Basic] 在 Visual Basic 中,您可以使用由类型定义的转换运算符,但您不能自行定义。[JScript] 在 JScript 中,您可以使用由类型定义的转换运算符,但您不能自行定义。参数 [Visual Basic, JScript] 
    value 
    一个 IntPtr。 
    参数 [C#] 
    value 
    一个 IntPtr。 
    返回值
    value 的内容。
      

  11.   

    如果直接转换不行的话,那应该是this.Handle本来就不是一个有效的句柄值。
    --------------------  hwnd和hdc当然不同了.连这都没搞清楚.
    hwnd是windows句柄.
    hdc是专用于绘制的句柄.两者怎么是一样呢?最简单的是连值都不同.
    ------------------------
      这样的回答正确吗? 我在网上看到的
      

  12.   

    hwnd和hdc当然不同了.连这都没搞清楚.
    hwnd是windows句柄.
    hdc是专用于绘制的句柄.两者怎么是一样呢?最简单的是连值都不同.--------------------从逻辑含义来说的确是不一样的,不过所包含的值都是32位整数,
    所以对于句柄参数来说,你可以传递任意的32位整数,函数都会把它当成句柄来处理,
    只不过对于无效的32位整数,函数不会成功而已。