Codeing for fun help - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Codeing for fun help

this Codeing for fun example from microsoft doesnt work i need to refrence the classes and methods from the dxmutmisc.cs file from a standalone vb.net or do i need c# to do this here is some of the code becuase its long:

I need to reference the microsoft.samples.directx.UtilityToolkit class from this file any help on how to do this in vb.net?

//--------------------------------------------------------------------------------------
// File: DXMUTMisc.cs
//
// Shortcut and helper functions for using DX Code
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
using System;
using System.IO;
using System.Collections;
using System.Runtime.InteropServices;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace Microsoft.Samples.DirectX.UtilityToolkit
{
#region Native Methods
///
/// Will hold native methods which are interop'd
///
public class NativeMethods
{
#region Win32 User Messages / Structures
/// Show window flags styles
public enum ShowWindowFlags: uint
{
Hide = 0,
ShowNormal = 1,
Normal = 1,
ShowMinimized = 2,
ShowMaximized = 3,
ShowNoActivate = 4,
Show = 5,
Minimize = 6,
ShowMinNoActivate = 7,
ShowNotActivated = 8,
Restore = 9,
ShowDefault = 10,
ForceMinimize = 11,

}
/// Window styles
[Flags]
public enum WindowStyles: uint
{
Overlapped = 0x00000000,
Popup = 0x80000000,
Child = 0x40000000,
Minimize = 0x20000000,
Visible = 0x10000000,
Disabled = 0x08000000,
ClipSiblings = 0x04000000,
ClipChildren = 0x02000000,
Maximize = 0x01000000,
Caption = 0x00C00000, /* WindowStyles.Border | WindowStyles.DialogFrame */
Border = 0x00800000,
DialogFrame = 0x00400000,
VerticalScroll = 0x00200000,
HorizontalScroll = 0x00100000,
SystemMenu = 0x00080000,
ThickFrame = 0x00040000,
Group = 0x00020000,
TabStop = 0x00010000,
MinimizeBox = 0x00020000,
MaximizeBox = 0x00010000,
}

/// Peek message flags
public enum PeekMessageFlags : uint
{
NoRemove = 0,
Remove = 1,
NoYield = 2,
}

/// Window messages
public enum WindowMessage : uint
{
// Misc messages
Destroy = 0x0002,
Close = 0x0010,
Quit = 0x0012,
Paint = 0x000F,
SetCursor = 0x0020,
ActivateApplication = 0x001C,
EnterMenuLoop = 0x0211,
ExitMenuLoop = 0x0212,
NonClientHitTest = 0x0084,
PowerBroadcast = 0x0218,
SystemCommand = 0x0112,
GetMinMax = 0x0024,

// Keyboard messages
KeyDown = 0x0100,
KeyUp = 0x0101,
Character = 0x0102,
SystemKeyDown = 0x0104,
SystemKeyUp = 0x0105,
SystemCharacter = 0x0106,

// Mouse messages
MouseMove = 0x0200,
LeftButtonDown = 0x0201,
LeftButtonUp = 0x0202,
LeftButtonDoubleClick = 0x0203,
RightButtonDown = 0x0204,
RightButtonUp = 0x0205,
RightButtonDoubleClick = 0x0206,
MiddleButtonDown = 0x0207,
MiddleButtonUp = 0x0208,
MiddleButtonDoubleClick = 0x0209,
MouseWheel = 0x020a,
XButtonDown = 0x020B,
XButtonUp = 0x020c,
XButtonDoubleClick = 0x020d,
MouseFirst = LeftButtonDown, // Skip mouse move, it happens a lot and there is another message for that
MouseLast = XButtonDoubleClick,

// Sizing
EnterSizeMove = 0x0231,
ExitSizeMove = 0x0232,
Size = 0x0005,

}

/// Mouse buttons
public enum MouseButtons
{
Left = 0x0001,
Right = 0x0002,
Middle = 0x0010,
Side1 = 0x0020,
Side2 = 0x0040,
}

/// Windows Message
[StructLayout(LayoutKind.Sequential)]
public struct Message
{
public IntPtr hWnd;
public WindowMessage msg;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public System.Drawing.Point p;
}

/// MinMax Info structure
[StructLayout(LayoutKind.Sequential)]
public struct MinMaxInformation
{
public System.Drawing.Point reserved;
public System.Drawing.Point MaxSize;
public System.Drawing.Point MaxPosition;
public System.Drawing.Point MinTrackSize;
public System.Drawing.Point MaxTrackSize;
}

/// Monitor Info structure
[StructLayout(LayoutKind.Sequential)]
public struct MonitorInformation
{
public uint Size; // Size of this structure
public System.Drawing.Rectangle MonitorRectangle;
public System.Drawing.Rectangle WorkRectangle;
public uint Flags; // Possible flags
}

/// Window class structure
[StructLayout(LayoutKind.Sequential)]
public struct WindowClass
{
public int Styles;
[MarshalAs(UnmanagedType.FunctionPtr)] public WndProcDelegate WindowsProc;
private int ExtraClassData;
private int ExtraWindowData;
public IntPtr InstanceHandle;
public IntPtr IconHandle;
public IntPtr CursorHandle;
public IntPtr backgroundBrush;
[MarshalAs(UnmanagedType.LPTStr)] public string MenuName;
[MarshalAs(UnmanagedType.LPTStr)] public string ClassName;
}
#endregion

#region Delegates
public delegate IntPtr WndProcDelegate(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam);
#endregion

#region Windows API calls
[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[System.Runtime.InteropServices.DllImport("winmm.dll")]
public static extern IntPtr timeBeginPeriod(uint period);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, PeekMessageFlags flags);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool TranslateMessage(ref Message msg);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool DispatchMessage(ref Message msg);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr DefWindowProc(IntPtr hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern void PostQuitMessage(int exitCode);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
#if(_WIN64)
private static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int index, [MarshalAs(UnmanagedType.FunctionPtr)] WndProcDelegate windowCallback);
#else
private static extern IntPtr SetWindowLong(IntPtr hWnd, int index, [MarshalAs(UnmanagedType.FunctionPtr)] WndProcDelegate windowCallback);
#endif

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", EntryPoint="SetWindowLong", CharSet=CharSet.Auto)]
private static extern IntPtr SetWindowLongStyle(IntPtr hWnd, int index, WindowStyles style);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", EntryPoint="GetWindowLong", CharSet=CharSet.Auto)]
private static extern WindowStyles GetWindowLongStyle(IntPtr hWnd, int index);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("kernel32")]
public static extern bool QueryPerformanceFrequency(ref long PerformanceFrequency);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("kernel32")]
public static extern bool QueryPerformanceCounter(ref long PerformanceCount);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool GetClientRect(IntPtr hWnd, out System.Drawing.Rectangle rect);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool GetWindowRect(IntPtr hWnd, out System.Drawing.Rectangle rect);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndAfter, int x, int y, int w, int h, uint flags);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool ScreenToClient(IntPtr hWnd, ref System.Drawing.Point rect);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SetFocus(IntPtr hWnd);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr GetParent(IntPtr hWnd);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool GetMonitorInfo(IntPtr hWnd, ref MonitorInformation info);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr MonitorFromWindow(IntPtr hWnd, uint flags);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern short GetAsyncKeyState(uint key);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SetCapture(IntPtr handle);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool ReleaseCapture();

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool ShowWindow(IntPtr hWnd, ShowWindowFlags flags);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool SetMenu(IntPtr hWnd, IntPtr menuHandle);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool DestroyWindow(IntPtr hWnd);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool IsIconic(IntPtr hWnd);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool AdjustWindowRect(ref System.Drawing.Rectangle rect, WindowStyles style,
[MarshalAs(UnmanagedType.Bool)]bool menu);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr windowHandle, WindowMessage msg, IntPtr w, IntPtr l);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr RegisterClass(ref WindowClass wndClass);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool UnregisterClass([MarshalAs(UnmanagedType.LPTStr)] string className, IntPtr instanceHandle);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", EntryPoint="CreateWindowEx", CharSet=CharSet.Auto)]
public static extern IntPtr CreateWindow(int exStyle, [MarshalAs(UnmanagedType.LPTStr)] string className, [MarshalAs(UnmanagedType.LPTStr)] string windowName,
WindowStyles style, int x, int y, int width, int height, IntPtr parent, IntPtr menuHandle, IntPtr instanceHandle, IntPtr zero);

[System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern int GetCaretBlinkTime();
#endregion

#region Class Methods
private NativeMethods() {} // No creation
/// Hooks window messages to go through this new callback
public static void HookWindowsMessages(IntPtr window, WndProcDelegate callback)
{
#if(_WIN64)
SetWindowLongPtr(window, -4, callback);
#else
SetWindowLong(window, -4, callback);
#endif
}
/// Set new window style
public static void SetStyle(IntPtr window, WindowStyles newStyle)
{
SetWindowLongStyle(window, -16, newStyle);
}
/// Get new window style
public static WindowStyles GetStyle(IntPtr window)
{
return GetWindowLongStyle(window, -16);
}

/// Returns the low word
public static short LoWord(uint l)
{
return (short)(l & 0xffff);
}
/// Returns the high word
public static short HiWord(uint l)
{
return (short)(l >> 16);
}

/// Makes two shorts into a long
public static uint MakeUInt32(short l, short r)
{
return (uint)((l & 0xffff) | ((r & 0xffff) << 16));
}

/// <summary>Is this key down right now
public static bool IsKeyDown(System.Windows.Forms.Keys key)
{
return (GetAsyncKeyState((int)System.Windows.Forms.Keys.ShiftKey) & 0x8000) != 0;
}
#endregion
}

#endregion

#region Timer
public class FrameworkTimer
{
#region Instance Data
private static bool isUsingQPF;
private static bool isTimerStopped;
private static long ticksPerSecond;
private static long stopTime;
private static long lastElapsedTime;
private static long baseTime;
#endregion

#region Creation
private FrameworkTimer() { } // No creation
///
/// Static creation routine
///
static FrameworkTimer()
{
isTimerStopped = true;
ticksPerSecond = 0;
stopTime = 0;
lastElapsedTime = 0;
baseTime = 0;
// Use QueryPerformanceFrequency to get frequency of the timer
isUsingQPF = NativeMethods.QueryPerformanceFrequency(ref ticksPerSecond);
}
#endregion

///
/// Resets the timer
///
public static void Reset()
{
if (!isUsingQPF)
return; // Nothing to do

// Get either the current time or the stop time
long time = 0;
if (stopTime != 0)
time = stopTime;
else
NativeMethods.QueryPerformanceCounter(ref time);

baseTime = time;
lastElapsedTime = time;
stopTime = 0;
isTimerStopped = false;
}

///
/// Starts the timer
///
public static void Start()
{
if (!isUsingQPF)
return; // Nothing to do

// Get either the current time or the stop time
long time = 0;
if (stopTime != 0)
time = stopTime;
else
NativeMethods.QueryPerformanceCounter(ref time);

if (isTimerStopped)
baseTime += (time - stopTime);
stopTime = 0;
lastElapsedTime = time;
isTimerStopped = false;
}

///
/// Stop (or pause) the timer
///
public static void Stop()
{
if (!isUsingQPF)
return; // Nothing to do

if (!isTimerStopped)
{
// Get either the current time or the stop time
long time = 0;
if (stopTime != 0)
time = stopTime;
else
NativeMethods.QueryPerformanceCounter(ref time);

stopTime = time;
lastElapsedTime = time;
isTimerStopped = true;
}
}

///
/// Advance the timer a tenth of a second
///
public static void Advance()
{
if (!isUsingQPF)
return; // Nothing to do

stopTime += ticksPerSecond / 10;
}

///
/// Get the absolute system time
///
public static double GetAbsoluteTime()
{
if (!isUsingQPF)
return -1.0; // Nothing to do

// Get either the current time or the stop time
long time = 0;
if (stopTime != 0)
time = stopTime;
else
NativeMethods.QueryPerformanceCounter(ref time);

double absolueTime = time / (double)ticksPerSecond;
return absolueTime;
}

///
/// Get the current time
///
public static double GetTime()
{
if (!isUsingQPF)
return -1.0; // Nothing to do

// Get either the current time or the stop time
long time = 0;
if (stopTime != 0)
time = stopTime;
else
NativeMethods.QueryPerformanceCounter(ref time);

double appTime = (double)(time - baseTime) / (double)ticksPerSecond;
return appTime;
}

///
/// get the time that elapsed between GetElapsedTime() calls
///
public static double GetElapsedTime()
{
if (!isUsingQPF)
return -1.0; // Nothing to do

// Get either the current time or the stop time
long time = 0;
if (stopTime != 0)
time = stopTime;
else
NativeMethods.QueryPerformanceCounter(ref time);

double elapsedTime = (double)(time - lastElapsedTime) / (double)ticksPerSecond;
lastElapsedTime = time;
return elapsedTime;
}

///
/// Returns true if timer stopped
///
public static bool IsStopped
{
get { return isTimerStopped; }
}
}
#endregion

Comments

Sign In or Register to comment.