English 中文(简体)
moving SDL video surface
原标题:

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.

最佳回答

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.

问题回答

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.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签