移动SDL视频表面

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。

窗口正在初始化并从屏幕底部掉落。 alt text

有什么想法吗?

更新:

我看到了这段代码,但无法找出等效的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++代码需要多少工作量呢?谢谢。

自己的笔记:回家后看这里,寻找线索... http://fixunix.com/xwindows/91816-coords-window-under-sdl.html,http://www.gamedev.net/community/forums/topic.asp?topic_id=328286 - gingerbreadboy
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()。


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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接