?? wdxmutmisc.cs
字號:
//--------------------------------------------------------------------------------------
// File: WDXMUTMisc.cs
//
// Shortcut and helper functions for using Managed DirectX for Whidbey 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 RefWarningDialog Form
internal class SwitchRefDialog : System.Windows.Forms.Form
{
internal const string KeyLocation = @"Software\Microsoft\DirectX 9.0 SDK\ManagedSamples";
internal const string KeyValueName = "SkipWarning";
public SwitchRefDialog(string title)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
// Use the 'question' icon
this.pictureBox1.Image = System.Drawing.SystemIcons.Question.ToBitmap();
// Include text
this.lblInfo.Text = "Switching to the Direct3D reference rasterizer, a software device that implements the entire Direct3D feature set, but runs very slowly.\r\nDo you wish to continue?";
// UPdate title
this.Text = title;
}
#region Windows Form Designer generated code
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label lblInfo;
private System.Windows.Forms.CheckBox chkShowAgain;
private System.Windows.Forms.Button btnYes;
private System.Windows.Forms.Button btnNo;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.lblInfo = new System.Windows.Forms.Label();
this.chkShowAgain = new System.Windows.Forms.CheckBox();
this.btnYes = new System.Windows.Forms.Button();
this.btnNo = new System.Windows.Forms.Button();
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(16, 16);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(32, 32);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// lblInfo
//
this.lblInfo.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.lblInfo.Location = new System.Drawing.Point(64, 16);
this.lblInfo.Name = "lblInfo";
this.lblInfo.Size = new System.Drawing.Size(328, 48);
this.lblInfo.TabIndex = 99;
//
// chkShowAgain
//
this.chkShowAgain.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.chkShowAgain.Location = new System.Drawing.Point(8, 104);
this.chkShowAgain.Name = "chkShowAgain";
this.chkShowAgain.Size = new System.Drawing.Size(224, 16);
this.chkShowAgain.TabIndex = 2;
this.chkShowAgain.Text = "&Don\'t show again";
//
// btnYes
//
this.btnYes.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnYes.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnYes.Location = new System.Drawing.Point(117, 72);
this.btnYes.Name = "btnYes";
this.btnYes.Size = new System.Drawing.Size(80, 24);
this.btnYes.TabIndex = 0;
this.btnYes.Text = "&Yes";
this.btnYes.Click += new EventHandler(OnYes);
//
// btnNo
//
this.btnNo.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnNo.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnNo.Location = new System.Drawing.Point(205, 72);
this.btnNo.Name = "btnNo";
this.btnNo.Size = new System.Drawing.Size(80, 24);
this.btnNo.TabIndex = 1;
this.btnNo.Text = "&No";
this.btnNo.Click += new EventHandler(OnNo);
//
// SwitchRefDialog
//
this.AcceptButton = this.btnYes;
this.CancelButton = this.btnNo;
this.ClientSize = new System.Drawing.Size(402, 134);
this.Controls.Add(this.btnNo);
this.Controls.Add(this.btnYes);
this.Controls.Add(this.chkShowAgain);
this.Controls.Add(this.lblInfo);
this.Controls.Add(this.pictureBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "SwitchRefDialog";
this.Text = "SampleName";
this.ResumeLayout(false);
}
/// <summary>
/// Fired when the 'Yes' button is clicked
/// </summary>
private void OnYes(object sender, EventArgs e)
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
/// <summary>
/// Fired when the 'No' button is clicked
/// </summary>
private void OnNo(object sender, EventArgs e)
{
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.Close();
}
#endregion
/// <summary>
/// Dialog is being dismissed, either continue the application, or shutdown.
/// Save setting if required.
/// </summary>
protected override void OnClosed(EventArgs e)
{
// Is the box checked?
if (chkShowAgain.Checked)
{
using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(KeyLocation))
{
key.SetValue(KeyValueName, (int)1);
}
}
}
}
#endregion
#region Native Methods
/// <summary>
/// Will hold native methods which are interop'd
/// </summary>
public class NativeMethods
{
#region Win32 User Messages / Structures
/// <summary>Window messages</summary>
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,
}
/// <summary>Mouse buttons</summary>
public enum MouseButtons
{
Left = 0x0001,
Right = 0x0002,
Middle = 0x0010,
Side1 = 0x0020,
Side2 = 0x0040,
}
/// <summary>Windows Message</summary>
[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;
}
/// <summary>MinMax Info structure</summary>
[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;
}
/// <summary>Monitor Info structure</summary>
[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
}
#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("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 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 int GetCaretBlinkTime();
[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, uint flags);
#endregion
#region Class Methods
private NativeMethods() { } // No creation
/// <summary>Returns the low word</summary>
public static short LoWord(uint l)
{
return (short)(l & 0xffff);
}
/// <summary>Returns the high word</summary>
public static short HiWord(uint l)
{
return (short)(l >> 16);
}
/// <summary>Makes two shorts into a long</summary>
public static uint MakeUInt32(short l, short r)
{
return (uint)((l & 0xffff) | ((r & 0xffff) << 16));
}
/// <summary>Is this key down right now</summary>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -