Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 正在使用SetWindowPos移动窗口';正常方式';怎么办?_Windows_Winapi - Fatal编程技术网

Windows 正在使用SetWindowPos移动窗口';正常方式';怎么办?

Windows 正在使用SetWindowPos移动窗口';正常方式';怎么办?,windows,winapi,Windows,Winapi,我想知道,如果要将带有Win32 API的(ms windows-)窗口向右移动20 px,向下移动40 px,是否需要执行以下操作: 函数调用将是如何执行的: SetWindowPos( /* hWnd */ hChildDlg2, /* hWndInsertAfter */ (HWND) -1, /* X */ 20, /* Y */ 40, /* cx

我想知道,如果要将带有Win32 API的(ms windows-)窗口向右移动20 px,向下移动40 px,是否需要执行以下操作: 函数调用将是如何执行的:

SetWindowPos(
  /* hWnd             */  hChildDlg2, 
  /* hWndInsertAfter  */ (HWND) -1,
  /* X                */ 20,
  /* Y                */ 40,
  /* cx               */ -1,
  /* cy               */ -1,
  /* uFlags           */  SWP_NOSIZE |  // Ignore cx, cy
                          SWP_NOZORDER  // and hWndInsertAfter
);
我问这个问题是因为在我看来,可能存在一个函数,它只接受一个
HWND
和一个
x
y
作为参数


它需要hwnd、x、y、width、height,因为没有
SWP\u NOSIZE
标志,实际上使用它来移动窗口更为复杂,因为您还需要获取大小。

是的,这就是它的工作原理。您应该更喜欢使用,因为它可以让您控制如何移动/调整窗口大小

我通常这样使用它(我写的一个小框架的一部分):


还有一个函数可以做几乎相同的事情。使用
SetWindowPos()
功能,.

是的,这是正常的方式,窗口将获得
WM\u WINDOWPOSCHANGING
消息(参数已更改),也有较旧的,但灵活性较低,实际上会强制您设置大小


要正确保存和恢复窗口大小,应分别使用
GetWindowPlacement
SetWindowPlacement

看起来像
SetWindowPos
强制您设置Z-Order@mikew不,使用SWP_NOZORDER
// Window member function
void Window::Move(int x, int y)
{
    if(hwnd != 0)
    {
        ::SetWindowPos(hwnd, 0, x, y, 0, 0, 
            SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
    }
}