在使用如下语句调用SetWindowPos,该语句的本来目的是要将当前窗口设为最前面,且处于屏幕中心位置,但该语句执行后窗口就跑到了屏幕之外,不知道什么地方去了。
Call SetWindowPos(Me.hwnd, HWND_TOPMOST, (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2, 0, 0, SWP_NOSIZE)
请问问题出在什么什么地方,如何解决?谢谢!

解决方案 »

  1.   

    BOOL SetWindowPos(
      HWND hWnd,             // handle to window
      HWND hWndInsertAfter,  // placement-order handle
      int X,                 // horizontal position
      int Y,                 // vertical position
      int cx,                // width
      int cy,                // height
      UINT uFlags            // window-positioning options
    );
    ----------------
    SetWindowPos(Me.hwnd, HWND_TOPMOST, (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2, 0, 0, SWP_NOSIZE)
    ----------------注意:原型中的X和Y坐标的单位是象素,而你的Width和Height的单位也要是象素;
          原型中的cx和cy是窗体的宽和高,你的0,why?(Me.Width,Me.Height才对)
      

  2.   

    //你的Width和Height的单位也要是象素
    楼上正解
    SetWindowPos(Me.hwnd, HWND_TOPMOST,(Screen.Width - Me.Width) / 2 / Screen.TwipsPerPixelX, (Screen.Height - Me.Height) / 2 / Screen.TwipsPerPixelY, 0, 0, SWP_NOSIZE)另,窗体的宽和高,你的0,why?(Me.Width,Me.Height才对)
    加了SWP_NOSIZE就不理会前面对宽高的设置了~