5

有谁知道如何以编程方式在屏幕上移动我的SDL.net视频表面?

Surface videoContext = Video.SetVideoMode(1024, 768, 32, false, false, false, true, true);

var a = System.Windows.Forms.Control.FromHandle(Video.WindowHandle);
var b = System.Windows.Forms.NativeWindow.FromHandle(Video.WindowHandle);

我找不到任何属性SurfaceVideo哪些属性可以完成这项工作,并且FromHandle正在返回 Null。

窗口正在初始化,从屏幕底部掉落。 替代文字

有任何想法吗?

更新:

我已经看过这段代码,但无法计算出等效的 C# 实现。任何人都可以帮忙吗?

#ifdef WIN32
#include <SDL_syswm.h>
SDL_SysWMinfo i;
SDL_VERSION( &i.version );
if ( SDL_GetWMInfo ( &i) ) {
  HWND hwnd = i.window;
  SetWindowPos( hwnd, HWND_TOP, x, y, width, height, flags );
}

如果做不到这一点,在我的 c# 项目中包含一些 c++ 需要做多少工作?

谢谢。

4

2 回答 2

4

您将需要这些声明:

    private static IntPtr HWND_TOP = IntPtr.Zero;
    private static int SWP_FLAGS = 0x004 | 0x0010;
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern bool SetWindowPos(IntPtr hWnd, IntPtr after, int x, int y, int width, int height, int flags);

用法:

    SetWindowPos(Video.WindowHandle, HWND_TOP, x, y, width, height, SWP_FLAGS);

其中 x 和 y 在屏幕坐标中。如有必要,请使用 Control.PointToScreen()。

于 2010-04-20T15:15:10.620 回答
3

从您找到的 C++ 代码来看,您可以 P/Invoke Win32SetWindowPos函数并传递Video.WindowHandle句柄(以及您的大小和位置参数),因为 .NET 似乎没有提供解决方案。

于 2010-04-16T09:13:49.013 回答