博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
XNA程序开发常用到的一些代码汇总
阅读量:7057 次
发布时间:2019-06-28

本文共 3426 字,大约阅读时间需要 11 分钟。

 

This 
is the code form the menu system that starts the XNA game.
    
var process = Process.Start(info);
    
var currentProcess = Process.GetCurrentProcess();
    
while (!process.HasExited)
    {
        Thread.Sleep(
50);
        
if (GetForegroundWindow() == currentProcess.MainWindowHandle)
        {
            Activate(process.MainWindowHandle);
        }
    }
This 
is the code that sets the XNA game 
as the foreground window.
        
///
 
<summary>
        
///
 Sets the window to be foreground
        
///
 
</summary>
        [DllImport(
"
User32
")]
        
private 
static 
extern 
int SetForegroundWindow(IntPtr hwnd);
 
        
///
 
<summary>
        
///
 Activate or minimize a window
        
///
 
</summary>
        [DllImportAttribute(
"
User32.DLL
")]
        
private 
static 
extern 
bool ShowWindow(IntPtr hWnd, 
int nCmdShow);
        
private 
const 
int SW_SHOW = 
5;
        
private 
const 
int SW_MINIMIZE = 
6;
        
private 
const 
int SW_RESTORE = 
9;
 
        
///
 
<summary>
        
///
 The GetForegroundWindow function returns a handle to the foreground window.
        
///
 
</summary>
        [DllImport(
"
user32.dll
")]
        
private 
static 
extern IntPtr GetForegroundWindow();
 
        
private 
static 
void Activate(IntPtr windowHandle)
        {
            ShowWindow(windowHandle, SW_RESTORE);
            SetForegroundWindow(windowHandle);
        }
 
 
//
设置幕大小,其中ChatForm为聊天WinForm窗体。
ChatForm form = 
new ChatForm();
                
int screenWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
//
 System.Windows.Forms.SystemInformation.WorkingArea.Width;
                
int screenHeight = System.Windows.Forms.SystemInformation.WorkingArea.Height;
                form.Size = 
new System.Drawing.Size((
int)(screenWidth * 
0.2f * 
1000) / 
1000, (
int)(screenHeight));
                form.FormLocation = 
new System.Drawing.Point((
int)(screenWidth * 
0.8f * 
1000) / 
1000
0);
                form.Show();
          
                IntPtr ip = Window.Handle;
                System.Windows.Forms.Form gameForm = System.Windows.Forms.Control.FromHandle(ip) 
as System.Windows.Forms.Form;
                
if (gameForm != 
null)
                {
                    gameForm.Location = 
new System.Drawing.Point(
0
0);
                    gameForm.Size = 
new System.Drawing.Size((
int)(screenWidth * 
0.8f * 
1000) / 
1000, (
int)(screenHeight));
                }
===========================================================================================
int screenWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            
int screenHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
            graphics.PreferredBackBufferWidth = (
int)(screenWidth * 
0.8f);
            graphics.PreferredBackBufferHeight = screenHeight;
this.Window.AllowUserResizing = 
true;
this.Window.ClientSizeChanged += 
new EventHandler<EventArgs>(Window_ClientSizeChanged);
//
获取除任务栏之外的显示屏高度
 System.Windows.Forms.SystemInformation.WorkingArea.Height;
///
/
string currentScreenSize_OutTaskBar=SystemInformation.WorkingArea.Width.ToString() + 
"
,
" +SystemInformation.WorkingArea.Height.ToString();
MessageBox.Show(
"
当前的屏幕除任务栏外的工作域大小为:
"+currentScreenSize_OutTaskBar);
///
/
///
/
string currentScreenSize=System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width.ToString() + 
"
,
" + System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height.ToString();
MessageBox.Show(
"
当前的屏幕包括任务栏的工作域大小为:
"+currentScreenSize);
///
/
///
/
Size OutTaskBarSize = 
new Size(SystemInformation.WorkingArea.Width, SystemInformation.WorkingArea.Height);
Size ScreenSize = 
new Size(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
Size TaskBarSize;
TaskBarSize = 
new Size(
                (ScreenSize.Width - (ScreenSize.Width - OutTaskBarSize.Width)),
                (ScreenSize.Height - OutTaskBarSize.Height)
                );
MessageBox.Show(
"
任务栏大小:
" + TaskBarSize.Width + 
"
,
" + TaskBarSize.Height);
///
/

 

转载地址:http://ncgol.baihongyu.com/

你可能感兴趣的文章
Xamarin引用第三方包错误解决方法
查看>>
Html2Text
查看>>
简单的设计不简单
查看>>
prm文件总结
查看>>
C#+gdi 绘制汉字 鼠标点击笔画 实现动态类似flash填充该怎么做?多谢大家...
查看>>
SQL行转列
查看>>
android真机调试方法
查看>>
SQL Server 2008中原生的分层数据类型:hierarchyid(转)
查看>>
C++ 重载、覆盖和隐藏
查看>>
Silverlight浮动窗体 floatablewindow 非模态对话框
查看>>
C#解析json文件的方法
查看>>
WPF如何不显示最大化,最小化的按钮
查看>>
交叉表组件
查看>>
探索式测试实践之路(国际大师James Bach题词推荐之探索式测试唯一本土著作)
查看>>
每日英语:Generation Exhausted
查看>>
初识EseNt
查看>>
POJ 1787 Charlie's Change (完全背包,记录路径)
查看>>
Java中IO操作的基本规律
查看>>
第四章 数据抽象 ----《C++编程思想》
查看>>
iBatis简单入门教程
查看>>