views:

277

answers:

2

Does anyone know how to move my SDL.net video surface around the screen programtically?

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);

I can't find any properties in Surface or Video which do the job, and FromHandle is returning Null.

The window is initializing falling off the bottom of the screen. alt text

Any ideas?

Update:

I've seen this code but can't work out an equivilent C# implimentation. Can anyone help?

#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 );
}

Failing that, how much work is involved in including some c++ in my c# project?

Thanks.

+2  A: 

Judging by the C++ code you've found, you could P/Invoke the Win32 SetWindowPos function and pass the Video.WindowHandle handle (as well as your size and position parameters) since there doesn't appear to be a solution provided by .NET.

Adam Maras
+2  A: 

You'll need these declarations:

    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);

Usage:

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

where x and y are in screen coordinates. Use Control.PointToScreen() if necessary.

Hans Passant